repo_name
string
dataset
string
owner
string
lang
string
func_name
string
code
string
docstring
string
url
string
sha
string
ion
github_2023
sst
typescript
Redis.port
public get port() { return this.cluster.port.apply((v) => v!); }
/** * The port to connect to the Redis cluster. */
https://github.com/sst/ion/blob/d5c4855b2618198f5e9af315c5e67d4163df165a/platform/src/components/aws/redis.ts#L283-L285
d5c4855b2618198f5e9af315c5e67d4163df165a
ion
github_2023
sst
typescript
Redis.getSSTLink
public getSSTLink() { return { properties: { host: this.host, port: this.port, username: this.username, password: this.password, }, }; }
/** @internal */
https://github.com/sst/ion/blob/d5c4855b2618198f5e9af315c5e67d4163df165a/platform/src/components/aws/redis.ts#L294-L303
d5c4855b2618198f5e9af315c5e67d4163df165a
ion
github_2023
sst
typescript
Redis.get
public static get(name: string, clusterID: Input<string>) { const cluster = elasticache.ReplicationGroup.get( `${name}Cluster`, clusterID, ); return new Redis(name, { ref: true, cluster } as unknown as RedisArgs); }
/** * Reference an existing Redis cluster with the given cluster name. This is useful when you * create a Redis cluster in one stage and want to share it in another. It avoids having to * create a new Redis cluster in the other stage. * * :::tip * You can use the `static get` method to share Redis clusters across stages. * ::: * * @param name The name of the component. * @param clusterID The id of the existing Redis cluster. * * @example * Imagine you create a cluster in the `dev` stage. And in your personal stage `frank`, * instead of creating a new cluster, you want to share the same cluster from `dev`. * * ```ts title="sst.config.ts" * const redis = $app.stage === "frank" * ? sst.aws.Redis.get("MyRedis", "app-dev-myredis") * : new sst.aws.Redis("MyRedis"); * ``` * * Here `app-dev-myredis` is the ID of the cluster created in the `dev` stage. * You can find this by outputting the cluster ID in the `dev` stage. * * ```ts title="sst.config.ts" * return { * cluster: redis.clusterID * }; * ``` */
https://github.com/sst/ion/blob/d5c4855b2618198f5e9af315c5e67d4163df165a/platform/src/components/aws/redis.ts#L336-L342
d5c4855b2618198f5e9af315c5e67d4163df165a
ion
github_2023
sst
typescript
Remix.url
public get url() { return all([this.cdn?.domainUrl, this.cdn?.url, this.devUrl]).apply( ([domainUrl, url, dev]) => domainUrl ?? url ?? dev!, ); }
/** * The URL of the Remix app. * * If the `domain` is set, this is the URL with the custom domain. * Otherwise, it's the autogenerated CloudFront URL. */
https://github.com/sst/ion/blob/d5c4855b2618198f5e9af315c5e67d4163df165a/platform/src/components/aws/remix.ts#L695-L699
d5c4855b2618198f5e9af315c5e67d4163df165a
ion
github_2023
sst
typescript
Remix.nodes
public get nodes() { return { /** * The AWS Lambda server function that renders the site. */ server: this.server, /** * The Amazon S3 Bucket that stores the assets. */ assets: this.assets, /** * The Amazon CloudFront CDN that serves the app. */ cdn: this.cdn, }; }
/** * The underlying [resources](/docs/components/#nodes) this component creates. */
https://github.com/sst/ion/blob/d5c4855b2618198f5e9af315c5e67d4163df165a/platform/src/components/aws/remix.ts#L704-L719
d5c4855b2618198f5e9af315c5e67d4163df165a
ion
github_2023
sst
typescript
Remix.getSSTLink
public getSSTLink() { return { properties: { url: this.url, }, }; }
/** @internal */
https://github.com/sst/ion/blob/d5c4855b2618198f5e9af315c5e67d4163df165a/platform/src/components/aws/remix.ts#L722-L728
d5c4855b2618198f5e9af315c5e67d4163df165a
ion
github_2023
sst
typescript
Router.url
public get url() { return all([this.cdn.domainUrl, this.cdn.url]).apply( ([domainUrl, url]) => domainUrl ?? url, ); }
/** * The URL of the Router. * * If the `domain` is set, this is the URL with the custom domain. * Otherwise, it's the autogenerated CloudFront URL. */
https://github.com/sst/ion/blob/d5c4855b2618198f5e9af315c5e67d4163df165a/platform/src/components/aws/router.ts#L885-L889
d5c4855b2618198f5e9af315c5e67d4163df165a
ion
github_2023
sst
typescript
Router.nodes
public get nodes() { return { /** * The Amazon CloudFront CDN resource. */ cdn: this.cdn, }; }
/** * The underlying [resources](/docs/components/#nodes) this component creates. */
https://github.com/sst/ion/blob/d5c4855b2618198f5e9af315c5e67d4163df165a/platform/src/components/aws/router.ts#L894-L901
d5c4855b2618198f5e9af315c5e67d4163df165a
ion
github_2023
sst
typescript
Router.getSSTLink
public getSSTLink() { return { properties: { url: this.url, }, }; }
/** @internal */
https://github.com/sst/ion/blob/d5c4855b2618198f5e9af315c5e67d4163df165a/platform/src/components/aws/router.ts#L904-L910
d5c4855b2618198f5e9af315c5e67d4163df165a
ion
github_2023
sst
typescript
Service.url
public get url() { const errorMessage = "Cannot access the URL because no public ports are exposed."; if ($dev) { if (!this.devUrl) throw new VisibleError(errorMessage); return this.devUrl; } if (!this._url) throw new VisibleError(errorMessage); return this._url; }
/** * The URL of the service. * * If `public.domain` is set, this is the URL with the custom domain. * Otherwise, it's the autogenerated load balancer URL. */
https://github.com/sst/ion/blob/d5c4855b2618198f5e9af315c5e67d4163df165a/platform/src/components/aws/service-v1.ts#L783-L793
d5c4855b2618198f5e9af315c5e67d4163df165a
ion
github_2023
sst
typescript
Service.nodes
public get nodes() { const self = this; return { /** * The Amazon ECS Service. */ get service() { if ($dev) throw new VisibleError("Cannot access `nodes.service` in dev mode."); return self.service!; }, /** * The Amazon ECS Task Role. */ get taskRole() { return self.taskRole; }, /** * The Amazon ECS Task Definition. */ get taskDefinition() { if ($dev) throw new VisibleError( "Cannot access `nodes.taskDefinition` in dev mode.", ); return self.taskDefinition!; }, /** * The Amazon Elastic Load Balancer. */ get loadBalancer() { if ($dev) throw new VisibleError( "Cannot access `nodes.loadBalancer` in dev mode.", ); if (!self.loadBalancer) throw new VisibleError( "Cannot access `nodes.loadBalancer` when no public ports are exposed.", ); return self.loadBalancer; }, }; }
/** * The underlying [resources](/docs/components/#nodes) this component creates. */
https://github.com/sst/ion/blob/d5c4855b2618198f5e9af315c5e67d4163df165a/platform/src/components/aws/service-v1.ts#L798-L840
d5c4855b2618198f5e9af315c5e67d4163df165a
ion
github_2023
sst
typescript
Service.getSSTLink
public getSSTLink() { return { properties: { url: $dev ? this.devUrl : this._url }, }; }
/** @internal */
https://github.com/sst/ion/blob/d5c4855b2618198f5e9af315c5e67d4163df165a/platform/src/components/aws/service-v1.ts#L843-L847
d5c4855b2618198f5e9af315c5e67d4163df165a
ion
github_2023
sst
typescript
Service.url
public get url() { const errorMessage = "Cannot access the URL because no public ports are exposed."; if (this.dev) { if (!this.devUrl) throw new VisibleError(errorMessage); return this.devUrl; } if (!this._url) throw new VisibleError(errorMessage); return this._url; }
/** * The URL of the service. * * If `public.domain` is set, this is the URL with the custom domain. * Otherwise, it's the autogenerated load balancer URL. */
https://github.com/sst/ion/blob/d5c4855b2618198f5e9af315c5e67d4163df165a/platform/src/components/aws/service.ts#L940-L950
d5c4855b2618198f5e9af315c5e67d4163df165a
ion
github_2023
sst
typescript
Service.service
public get service() { return this.dev ? interpolate`dev.${this.cloudmapNamespace}` : interpolate`${this.cloudmapService!.name}.${this.cloudmapNamespace}`; }
/** * The name of the Cloud Map service. */
https://github.com/sst/ion/blob/d5c4855b2618198f5e9af315c5e67d4163df165a/platform/src/components/aws/service.ts#L955-L959
d5c4855b2618198f5e9af315c5e67d4163df165a
ion
github_2023
sst
typescript
Service.nodes
public get nodes() { const self = this; return { /** * The Amazon ECS Service. */ get service() { if (self.dev) throw new VisibleError("Cannot access `nodes.service` in dev mode."); return self.service!; }, /** * The Amazon ECS Execution Role. */ executionRole: this.executionRole, /** * The Amazon ECS Task Role. */ taskRole: this.taskRole, /** * The Amazon ECS Task Definition. */ get taskDefinition() { if (self.dev) throw new VisibleError( "Cannot access `nodes.taskDefinition` in dev mode.", ); return self.taskDefinition!; }, /** * The Amazon Elastic Load Balancer. */ get loadBalancer() { if (self.dev) throw new VisibleError( "Cannot access `nodes.loadBalancer` in dev mode.", ); if (!self.loadBalancer) throw new VisibleError( "Cannot access `nodes.loadBalancer` when no public ports are exposed.", ); return self.loadBalancer; }, }; }
/** * The underlying [resources](/docs/components/#nodes) this component creates. */
https://github.com/sst/ion/blob/d5c4855b2618198f5e9af315c5e67d4163df165a/platform/src/components/aws/service.ts#L964-L1008
d5c4855b2618198f5e9af315c5e67d4163df165a
ion
github_2023
sst
typescript
Service.getSSTLink
public getSSTLink() { return { properties: { url: this.dev ? this.devUrl : this._url, service: this.service, }, }; }
/** @internal */
https://github.com/sst/ion/blob/d5c4855b2618198f5e9af315c5e67d4163df165a/platform/src/components/aws/service.ts#L1011-L1018
d5c4855b2618198f5e9af315c5e67d4163df165a
ion
github_2023
sst
typescript
SnsTopicLambdaSubscriber.nodes
public get nodes() { return { /** * The Lambda function that'll be notified. */ function: this.fn.apply((fn) => fn.getFunction()), /** * The Lambda permission. */ permission: this.permission, /** * The SNS Topic subscription. */ subscription: this.subscription, }; }
/** * The underlying [resources](/docs/components/#nodes) this component creates. */
https://github.com/sst/ion/blob/d5c4855b2618198f5e9af315c5e67d4163df165a/platform/src/components/aws/sns-topic-lambda-subscriber.ts#L103-L118
d5c4855b2618198f5e9af315c5e67d4163df165a
ion
github_2023
sst
typescript
SnsTopicQueueSubscriber.nodes
public get nodes() { return { /** * The SQS Queue policy. */ policy: this.policy, /** * The SNS Topic subscription. */ subscription: this.subscription, }; }
/** * The underlying [resources](/docs/components/#nodes) this component creates. */
https://github.com/sst/ion/blob/d5c4855b2618198f5e9af315c5e67d4163df165a/platform/src/components/aws/sns-topic-queue-subscriber.ts#L100-L111
d5c4855b2618198f5e9af315c5e67d4163df165a
ion
github_2023
sst
typescript
SnsTopic.arn
public get arn() { return this.topic.arn; }
/** * The ARN of the SNS Topic. */
https://github.com/sst/ion/blob/d5c4855b2618198f5e9af315c5e67d4163df165a/platform/src/components/aws/sns-topic.ts#L195-L197
d5c4855b2618198f5e9af315c5e67d4163df165a
ion
github_2023
sst
typescript
SnsTopic.name
public get name() { return this.topic.name; }
/** * The name of the SNS Topic. */
https://github.com/sst/ion/blob/d5c4855b2618198f5e9af315c5e67d4163df165a/platform/src/components/aws/sns-topic.ts#L202-L204
d5c4855b2618198f5e9af315c5e67d4163df165a
ion
github_2023
sst
typescript
SnsTopic.nodes
public get nodes() { return { /** * The Amazon SNS Topic. */ topic: this.topic, }; }
/** * The underlying [resources](/docs/components/#nodes) this component creates. */
https://github.com/sst/ion/blob/d5c4855b2618198f5e9af315c5e67d4163df165a/platform/src/components/aws/sns-topic.ts#L209-L216
d5c4855b2618198f5e9af315c5e67d4163df165a
ion
github_2023
sst
typescript
SnsTopic.subscribe
public subscribe( subscriber: Input<string | FunctionArgs | FunctionArn>, args: SnsTopicSubscriberArgs = {}, ) { return SnsTopic._subscribeFunction( this.constructorName, this.arn, subscriber, args, { provider: this.constructorOpts.provider }, ); }
/** * Subscribe to this SNS Topic. * * @param subscriber The function that'll be notified. * @param args Configure the subscription. * * @example * * ```js title="sst.config.ts" * topic.subscribe("src/subscriber.handler"); * ``` * * Add a filter to the subscription. * * ```js title="sst.config.ts" * topic.subscribe("src/subscriber.handler", { * filter: { * price_usd: [{numeric: [">=", 100]}] * } * }); * ``` * * Customize the subscriber function. * * ```js title="sst.config.ts" * topic.subscribe({ * handler: "src/subscriber.handler", * timeout: "60 seconds" * }); * ``` * * Or pass in the ARN of an existing Lambda function. * * ```js title="sst.config.ts" * topic.subscribe("arn:aws:lambda:us-east-1:123456789012:function:my-function"); * ``` */
https://github.com/sst/ion/blob/d5c4855b2618198f5e9af315c5e67d4163df165a/platform/src/components/aws/sns-topic.ts#L255-L266
d5c4855b2618198f5e9af315c5e67d4163df165a
ion
github_2023
sst
typescript
SnsTopic.subscribe
public static subscribe( topicArn: Input<string>, subscriber: Input<string | FunctionArgs | FunctionArn>, args?: SnsTopicSubscriberArgs, ) { return output(topicArn).apply((topicArn) => this._subscribeFunction( logicalName(parseTopicArn(topicArn).topicName), topicArn, subscriber, args, ), ); }
/** * Subscribe to an SNS Topic that was not created in your app. * * @param topicArn The ARN of the SNS Topic to subscribe to. * @param subscriber The function that'll be notified. * @param args Configure the subscription. * * @example * * For example, let's say you have an existing SNS Topic with the following ARN. * * ```js title="sst.config.ts" * const topicArn = "arn:aws:sns:us-east-1:123456789012:MyTopic"; * ``` * * You can subscribe to it by passing in the ARN. * * ```js title="sst.config.ts" * sst.aws.SnsTopic.subscribe(topicArn, "src/subscriber.handler"); * ``` * * Add a filter to the subscription. * * ```js title="sst.config.ts" * sst.aws.SnsTopic.subscribe(topicArn, "src/subscriber.handler", { * filter: { * price_usd: [{numeric: [">=", 100]}] * } * }); * ``` * * Customize the subscriber function. * * ```js title="sst.config.ts" * sst.aws.SnsTopic.subscribe(topicArn, { * handler: "src/subscriber.handler", * timeout: "60 seconds" * }); * ``` */
https://github.com/sst/ion/blob/d5c4855b2618198f5e9af315c5e67d4163df165a/platform/src/components/aws/sns-topic.ts#L308-L321
d5c4855b2618198f5e9af315c5e67d4163df165a
ion
github_2023
sst
typescript
SnsTopic.subscribeQueue
public subscribeQueue( queueArn: Input<string>, args: SnsTopicSubscriberArgs = {}, ) { return SnsTopic._subscribeQueue( this.constructorName, this.arn, queueArn, args, ); }
/** * Subscribe to this SNS Topic with an SQS Queue. * * @param queueArn The ARN of the queue that'll be notified. * @param args Configure the subscription. * * @example * * For example, let's say you have a queue. * * ```js title="sst.config.ts" * const queue = sst.aws.Queue("MyQueue"); * ``` * * You can subscribe to this topic with it. * * ```js title="sst.config.ts" * topic.subscribeQueue(queue.arn); * ``` * * Add a filter to the subscription. * * ```js title="sst.config.ts" * topic.subscribeQueue(queue.arn, { * filter: { * price_usd: [{numeric: [">=", 100]}] * } * }); * ``` */
https://github.com/sst/ion/blob/d5c4855b2618198f5e9af315c5e67d4163df165a/platform/src/components/aws/sns-topic.ts#L384-L394
d5c4855b2618198f5e9af315c5e67d4163df165a
ion
github_2023
sst
typescript
SnsTopic.subscribeQueue
public static subscribeQueue( topicArn: Input<string>, queueArn: Input<string>, args?: SnsTopicSubscriberArgs, ) { return output(topicArn).apply((topicArn) => this._subscribeQueue( logicalName(parseTopicArn(topicArn).topicName), topicArn, queueArn, args, ), ); }
/** * Subscribe to an existing SNS Topic with a previously created SQS Queue. * * @param topicArn The ARN of the SNS Topic to subscribe to. * @param queueArn The ARN of the queue that'll be notified. * @param args Configure the subscription. * * @example * * For example, let's say you have an existing SNS Topic and SQS Queue with the following ARNs. * * ```js title="sst.config.ts" * const topicArn = "arn:aws:sns:us-east-1:123456789012:MyTopic"; * const queueArn = "arn:aws:sqs:us-east-1:123456789012:MyQueue"; * ``` * * You can subscribe to the topic with the queue. * * ```js title="sst.config.ts" * sst.aws.SnsTopic.subscribeQueue(topicArn, queueArn); * ``` * * Add a filter to the subscription. * * ```js title="sst.config.ts" * sst.aws.SnsTopic.subscribeQueue(topicArn, queueArn, { * filter: { * price_usd: [{numeric: [">=", 100]}] * } * }); * ``` */
https://github.com/sst/ion/blob/d5c4855b2618198f5e9af315c5e67d4163df165a/platform/src/components/aws/sns-topic.ts#L428-L441
d5c4855b2618198f5e9af315c5e67d4163df165a
ion
github_2023
sst
typescript
SnsTopic.getSSTLink
public getSSTLink() { return { properties: { arn: this.arn, }, include: [ permission({ actions: ["sns:*"], resources: [this.arn], }), ], }; }
/** @internal */
https://github.com/sst/ion/blob/d5c4855b2618198f5e9af315c5e67d4163df165a/platform/src/components/aws/sns-topic.ts#L470-L482
d5c4855b2618198f5e9af315c5e67d4163df165a
ion
github_2023
sst
typescript
SolidStart.url
public get url() { return all([this.cdn?.domainUrl, this.cdn?.url, this.devUrl]).apply( ([domainUrl, url, dev]) => domainUrl ?? url ?? dev!, ); }
/** * The URL of the SolidStart app. * * If the `domain` is set, this is the URL with the custom domain. * Otherwise, it's the autogenerated CloudFront URL. */
https://github.com/sst/ion/blob/d5c4855b2618198f5e9af315c5e67d4163df165a/platform/src/components/aws/solid-start.ts#L520-L524
d5c4855b2618198f5e9af315c5e67d4163df165a
ion
github_2023
sst
typescript
SolidStart.nodes
public get nodes() { return { /** * The AWS Lambda server function that renders the site. */ server: this.server, /** * The Amazon S3 Bucket that stores the assets. */ assets: this.assets, /** * The Amazon CloudFront CDN that serves the site. */ cdn: this.cdn, }; }
/** * The underlying [resources](/docs/components/#nodes) this component creates. */
https://github.com/sst/ion/blob/d5c4855b2618198f5e9af315c5e67d4163df165a/platform/src/components/aws/solid-start.ts#L529-L544
d5c4855b2618198f5e9af315c5e67d4163df165a
ion
github_2023
sst
typescript
SolidStart.getSSTLink
public getSSTLink() { return { properties: { url: this.url, }, }; }
/** @internal */
https://github.com/sst/ion/blob/d5c4855b2618198f5e9af315c5e67d4163df165a/platform/src/components/aws/solid-start.ts#L547-L553
d5c4855b2618198f5e9af315c5e67d4163df165a
ion
github_2023
sst
typescript
StaticSite.url
public get url() { return all([this.cdn?.domainUrl, this.cdn?.url, this.devUrl]).apply( ([domainUrl, url, dev]) => domainUrl ?? url ?? dev!, ); }
/** * The URL of the website. * * If the `domain` is set, this is the URL with the custom domain. * Otherwise, it's the autogenerated CloudFront URL. */
https://github.com/sst/ion/blob/d5c4855b2618198f5e9af315c5e67d4163df165a/platform/src/components/aws/static-site.ts#L968-L972
d5c4855b2618198f5e9af315c5e67d4163df165a
ion
github_2023
sst
typescript
StaticSite.nodes
public get nodes() { return { /** * The Amazon S3 Bucket that stores the assets. */ assets: this.assets, /** * The Amazon CloudFront CDN that serves the site. */ cdn: this.cdn, }; }
/** * The underlying [resources](/docs/components/#nodes) this component creates. */
https://github.com/sst/ion/blob/d5c4855b2618198f5e9af315c5e67d4163df165a/platform/src/components/aws/static-site.ts#L977-L988
d5c4855b2618198f5e9af315c5e67d4163df165a
ion
github_2023
sst
typescript
StaticSite.getSSTLink
public getSSTLink() { return { properties: { url: this.url, }, }; }
/** @internal */
https://github.com/sst/ion/blob/d5c4855b2618198f5e9af315c5e67d4163df165a/platform/src/components/aws/static-site.ts#L991-L997
d5c4855b2618198f5e9af315c5e67d4163df165a
ion
github_2023
sst
typescript
SvelteKit.url
public get url() { return all([this.cdn?.domainUrl, this.cdn?.url, this.devUrl]).apply( ([domainUrl, url, dev]) => domainUrl ?? url ?? dev!, ); }
/** * The URL of the SvelteKit app. * * If the `domain` is set, this is the URL with the custom domain. * Otherwise, it's the autogenerated CloudFront URL. */
https://github.com/sst/ion/blob/d5c4855b2618198f5e9af315c5e67d4163df165a/platform/src/components/aws/svelte-kit.ts#L584-L588
d5c4855b2618198f5e9af315c5e67d4163df165a
ion
github_2023
sst
typescript
SvelteKit.nodes
public get nodes() { return { /** * The AWS Lambda server function that renders the app. */ server: this.server, /** * The Amazon S3 Bucket that stores the assets. */ assets: this.assets, /** * The Amazon CloudFront CDN that serves the app. */ cdn: this.cdn, }; }
/** * The underlying [resources](/docs/components/#nodes) this component creates. */
https://github.com/sst/ion/blob/d5c4855b2618198f5e9af315c5e67d4163df165a/platform/src/components/aws/svelte-kit.ts#L593-L608
d5c4855b2618198f5e9af315c5e67d4163df165a
ion
github_2023
sst
typescript
SvelteKit.getSSTLink
public getSSTLink() { return { properties: { url: this.url, }, }; }
/** @internal */
https://github.com/sst/ion/blob/d5c4855b2618198f5e9af315c5e67d4163df165a/platform/src/components/aws/svelte-kit.ts#L611-L617
d5c4855b2618198f5e9af315c5e67d4163df165a
ion
github_2023
sst
typescript
TanstackStart.url
public get url() { return all([this.cdn?.domainUrl, this.cdn?.url, this.devUrl]).apply( ([domainUrl, url, dev]) => domainUrl ?? url ?? dev!, ); }
/** * The URL of the TanstackStart app. * * If the `domain` is set, this is the URL with the custom domain. * Otherwise, it's the autogenerated CloudFront URL. */
https://github.com/sst/ion/blob/d5c4855b2618198f5e9af315c5e67d4163df165a/platform/src/components/aws/tanstack-start.ts#L520-L524
d5c4855b2618198f5e9af315c5e67d4163df165a
ion
github_2023
sst
typescript
TanstackStart.nodes
public get nodes() { return { /** * The AWS Lambda server function that renders the site. */ server: this.server, /** * The Amazon S3 Bucket that stores the assets. */ assets: this.assets, /** * The Amazon CloudFront CDN that serves the site. */ cdn: this.cdn, }; }
/** * The underlying [resources](/docs/components/#nodes) this component creates. */
https://github.com/sst/ion/blob/d5c4855b2618198f5e9af315c5e67d4163df165a/platform/src/components/aws/tanstack-start.ts#L529-L544
d5c4855b2618198f5e9af315c5e67d4163df165a
ion
github_2023
sst
typescript
TanstackStart.getSSTLink
public getSSTLink() { return { properties: { url: this.url, }, }; }
/** @internal */
https://github.com/sst/ion/blob/d5c4855b2618198f5e9af315c5e67d4163df165a/platform/src/components/aws/tanstack-start.ts#L547-L553
d5c4855b2618198f5e9af315c5e67d4163df165a
ion
github_2023
sst
typescript
Vector.get
public static get(name: string, clusterID: Input<string>) { const postgres = Postgres.get(`${name}Database`, clusterID); return new Vector(name, { ref: true, postgres, } as unknown as VectorArgs); }
/** * Reference an existing Vector database with the given name. This is useful when you * create a Vector database in one stage and want to share it in another. It avoids having to * create a new Vector database in the other stage. * * :::tip * You can use the `static get` method to share Vector databases across stages. * ::: * * @param name The name of the component. * @param clusterID The RDS cluster id of the existing Vector database. * * @example * Imagine you create a vector database in the `dev` stage. And in your personal stage `frank`, * instead of creating a new database, you want to share the same database from `dev`. * * ```ts title="sst.config.ts" * const vector = $app.stage === "frank" * ? sst.aws.Vector.get("MyVectorDB", "app-dev-myvectordb") * : new sst.aws.Vector("MyVectorDB", { * dimension: 1536 * }); * ``` * * Here `app-dev-myvectordb` is the ID of the underlying Postgres cluster created in the `dev` stage. * You can find this by outputting the cluster ID in the `dev` stage. * * ```ts title="sst.config.ts" * return { * cluster: vector.clusterID * }; * ``` * * :::note * The Vector component creates a Postgres cluster and lambda functions for interfacing with the VectorDB. * The `static get` method only shares the underlying Postgres cluster. Each stage will have its own * lambda functions. * ::: */
https://github.com/sst/ion/blob/d5c4855b2618198f5e9af315c5e67d4163df165a/platform/src/components/aws/vector.ts#L254-L260
d5c4855b2618198f5e9af315c5e67d4163df165a
ion
github_2023
sst
typescript
Vector.clusterID
public get clusterID() { return this.postgres.nodes.cluster.id; }
/** * The ID of the RDS Postgres Cluster. */
https://github.com/sst/ion/blob/d5c4855b2618198f5e9af315c5e67d4163df165a/platform/src/components/aws/vector.ts#L265-L267
d5c4855b2618198f5e9af315c5e67d4163df165a
ion
github_2023
sst
typescript
Vector.nodes
public get nodes() { return { /** * The Postgres database. */ postgres: this.postgres, }; }
/** * The underlying [resources](/docs/components/#nodes) this component creates. */
https://github.com/sst/ion/blob/d5c4855b2618198f5e9af315c5e67d4163df165a/platform/src/components/aws/vector.ts#L272-L279
d5c4855b2618198f5e9af315c5e67d4163df165a
ion
github_2023
sst
typescript
Vector.getSSTLink
public getSSTLink() { return { properties: { /** @internal */ queryFunction: this.queryHandler.name, /** @internal */ putFunction: this.putHandler.name, /** @internal */ removeFunction: this.removeHandler.name, }, include: [ permission({ actions: ["lambda:InvokeFunction"], resources: [ this.queryHandler.nodes.function.arn, this.putHandler.nodes.function.arn, this.removeHandler.nodes.function.arn, ], }), ], }; }
/** @internal */
https://github.com/sst/ion/blob/d5c4855b2618198f5e9af315c5e67d4163df165a/platform/src/components/aws/vector.ts#L282-L303
d5c4855b2618198f5e9af315c5e67d4163df165a
ion
github_2023
sst
typescript
Vpc.id
public get id() { return this.vpc.id; }
/** * The VPC ID. */
https://github.com/sst/ion/blob/d5c4855b2618198f5e9af315c5e67d4163df165a/platform/src/components/aws/vpc-v1.ts#L383-L385
d5c4855b2618198f5e9af315c5e67d4163df165a
ion
github_2023
sst
typescript
Vpc.publicSubnets
public get publicSubnets() { return this._publicSubnets.apply((subnets) => subnets.map((subnet) => subnet.id), ); }
/** * A list of public subnet IDs in the VPC. */
https://github.com/sst/ion/blob/d5c4855b2618198f5e9af315c5e67d4163df165a/platform/src/components/aws/vpc-v1.ts#L390-L394
d5c4855b2618198f5e9af315c5e67d4163df165a
ion
github_2023
sst
typescript
Vpc.privateSubnets
public get privateSubnets() { return this._privateSubnets.apply((subnets) => subnets.map((subnet) => subnet.id), ); }
/** * A list of private subnet IDs in the VPC. */
https://github.com/sst/ion/blob/d5c4855b2618198f5e9af315c5e67d4163df165a/platform/src/components/aws/vpc-v1.ts#L399-L403
d5c4855b2618198f5e9af315c5e67d4163df165a
ion
github_2023
sst
typescript
Vpc.securityGroups
public get securityGroups() { return [this.securityGroup.id]; }
/** * A list of VPC security group IDs. */
https://github.com/sst/ion/blob/d5c4855b2618198f5e9af315c5e67d4163df165a/platform/src/components/aws/vpc-v1.ts#L408-L410
d5c4855b2618198f5e9af315c5e67d4163df165a
ion
github_2023
sst
typescript
Vpc.nodes
public get nodes() { return { /** * The Amazon EC2 VPC. */ vpc: this.vpc, /** * The Amazon EC2 Internet Gateway. */ internetGateway: this.internetGateway, /** * The Amazon EC2 Security Group. */ securityGroup: this.securityGroup, /** * The Amazon EC2 NAT Gateway. */ natGateways: this.natGateways, /** * The Amazon EC2 Elastic IP. */ elasticIps: this.elasticIps, /** * The Amazon EC2 public subnet. */ publicSubnets: this._publicSubnets, /** * The Amazon EC2 private subnet. */ privateSubnets: this._privateSubnets, /** * The Amazon EC2 route table for the public subnet. */ publicRouteTables: this.publicRouteTables, /** * The Amazon EC2 route table for the private subnet. */ privateRouteTables: this.privateRouteTables, }; }
/** * The underlying [resources](/docs/components/#nodes) this component creates. */
https://github.com/sst/ion/blob/d5c4855b2618198f5e9af315c5e67d4163df165a/platform/src/components/aws/vpc-v1.ts#L415-L454
d5c4855b2618198f5e9af315c5e67d4163df165a
ion
github_2023
sst
typescript
Vpc.get
public static get(name: string, vpcID: Input<string>) { const vpc = ec2.Vpc.get(`${name}Vpc`, vpcID); const internetGateway = ec2.InternetGateway.get( `${name}InstanceGateway`, ec2.getInternetGatewayOutput({ filters: [{ name: "attachment.vpc-id", values: [vpc.id] }], }).internetGatewayId, ); const securityGroup = ec2.SecurityGroup.get( `${name}SecurityGroup`, ec2 .getSecurityGroupsOutput({ filters: [ { name: "group-name", values: ["*SecurityGroup*"] }, { name: "vpc-id", values: [vpc.id] }, ], }) .ids.apply((ids) => { if (!ids.length) throw new Error(`Security group not found in VPC ${vpcID}`); return ids[0]; }), ); const privateSubnets = ec2 .getSubnetsOutput({ filters: [ { name: "vpc-id", values: [vpc.id] }, { name: "tag:Name", values: ["*Private*"] }, ], }) .ids.apply((ids) => ids.map((id, i) => ec2.Subnet.get(`${name}PrivateSubnet${i + 1}`, id)), ); const privateRouteTables = privateSubnets.apply((subnets) => subnets.map((subnet, i) => ec2.RouteTable.get( `${name}PrivateRouteTable${i + 1}`, ec2.getRouteTableOutput({ subnetId: subnet.id }).routeTableId, ), ), ); const publicSubnets = ec2 .getSubnetsOutput({ filters: [ { name: "vpc-id", values: [vpc.id] }, { name: "tag:Name", values: ["*Public*"] }, ], }) .ids.apply((ids) => ids.map((id, i) => ec2.Subnet.get(`${name}PublicSubnet${i + 1}`, id)), ); const publicRouteTables = publicSubnets.apply((subnets) => subnets.map((subnet, i) => ec2.RouteTable.get( `${name}PublicRouteTable${i + 1}`, ec2.getRouteTableOutput({ subnetId: subnet.id }).routeTableId, ), ), ); const natGateways = publicSubnets.apply((subnets) => subnets.map((subnet, i) => ec2.NatGateway.get( `${name}NatGateway${i + 1}`, ec2.getNatGatewayOutput({ subnetId: subnet.id }).id, ), ), ); const elasticIps = natGateways.apply((nats) => nats.map((nat, i) => ec2.Eip.get( `${name}ElasticIp${i + 1}`, nat.allocationId as Output<string>, ), ), ); return new Vpc(name, { ref: true, vpc, internetGateway, securityGroup, privateSubnets, privateRouteTables, publicSubnets, publicRouteTables, natGateways, elasticIps, } satisfies VpcRef as VpcArgs); }
/** * Reference an existing VPC with the given ID. This is useful when you * create a VPC in one stage and want to share it in another stage. It avoids having to * create a new VPC in the other stage. * * :::tip * You can use the `static get` method to share VPCs across stages. * ::: * * @param name The name of the component. * @param vpcID The ID of the existing VPC. * * @example * Imagine you create a VPC in the `dev` stage. And in your personal stage `frank`, * instead of creating a new VPC, you want to share the VPC from `dev`. * * ```ts title="sst.config.ts" * const vpc = $app.stage === "frank" * ? sst.aws.Vpc.v1.get("MyVPC", "vpc-0be8fa4de860618bb") * : new sst.aws.Vpc.v1("MyVPC"); * ``` * * Here `vpc-0be8fa4de860618bb` is the ID of the VPC created in the `dev` stage. * You can find this by outputting the VPC ID in the `dev` stage. * * ```ts title="sst.config.ts" * return { * vpc: vpc.id * }; * ``` */
https://github.com/sst/ion/blob/d5c4855b2618198f5e9af315c5e67d4163df165a/platform/src/components/aws/vpc-v1.ts#L487-L575
d5c4855b2618198f5e9af315c5e67d4163df165a
ion
github_2023
sst
typescript
Vpc.id
public get id() { return this.vpc.id; }
/** * The VPC ID. */
https://github.com/sst/ion/blob/d5c4855b2618198f5e9af315c5e67d4163df165a/platform/src/components/aws/vpc.ts#L819-L821
d5c4855b2618198f5e9af315c5e67d4163df165a
ion
github_2023
sst
typescript
Vpc.publicSubnets
public get publicSubnets() { return this._publicSubnets.apply((subnets) => subnets.map((subnet) => subnet.id), ); }
/** * A list of public subnet IDs in the VPC. */
https://github.com/sst/ion/blob/d5c4855b2618198f5e9af315c5e67d4163df165a/platform/src/components/aws/vpc.ts#L826-L830
d5c4855b2618198f5e9af315c5e67d4163df165a
ion
github_2023
sst
typescript
Vpc.privateSubnets
public get privateSubnets() { return this._privateSubnets.apply((subnets) => subnets.map((subnet) => subnet.id), ); }
/** * A list of private subnet IDs in the VPC. */
https://github.com/sst/ion/blob/d5c4855b2618198f5e9af315c5e67d4163df165a/platform/src/components/aws/vpc.ts#L835-L839
d5c4855b2618198f5e9af315c5e67d4163df165a
ion
github_2023
sst
typescript
Vpc.securityGroups
public get securityGroups() { return [this.securityGroup.id]; }
/** * A list of VPC security group IDs. */
https://github.com/sst/ion/blob/d5c4855b2618198f5e9af315c5e67d4163df165a/platform/src/components/aws/vpc.ts#L844-L846
d5c4855b2618198f5e9af315c5e67d4163df165a
ion
github_2023
sst
typescript
Vpc.bastion
public get bastion() { return this.bastionInstance.apply((v) => { if (!v) throw new VisibleError( `VPC bastion is not enabled. Enable it with "bastion: true".`, ); return v.id; }); }
/** * The bastion instance ID. */
https://github.com/sst/ion/blob/d5c4855b2618198f5e9af315c5e67d4163df165a/platform/src/components/aws/vpc.ts#L851-L859
d5c4855b2618198f5e9af315c5e67d4163df165a
ion
github_2023
sst
typescript
Vpc.nodes
public get nodes() { return { /** * The Amazon EC2 VPC. */ vpc: this.vpc, /** * The Amazon EC2 Internet Gateway. */ internetGateway: this.internetGateway, /** * The Amazon EC2 Security Group. */ securityGroup: this.securityGroup, /** * The Amazon EC2 NAT Gateway. */ natGateways: this.natGateways, /** * The Amazon EC2 NAT instances. */ natInstances: this.natInstances, /** * The Amazon EC2 Elastic IP. */ elasticIps: this.elasticIps, /** * The Amazon EC2 public subnet. */ publicSubnets: this._publicSubnets, /** * The Amazon EC2 private subnet. */ privateSubnets: this._privateSubnets, /** * The Amazon EC2 route table for the public subnet. */ publicRouteTables: this.publicRouteTables, /** * The Amazon EC2 route table for the private subnet. */ privateRouteTables: this.privateRouteTables, /** * The Amazon EC2 bastion instance. */ bastionInstance: this.bastionInstance, /** * The AWS Cloudmap namespace. */ cloudmapNamespace: this.cloudmapNamespace, }; }
/** * The underlying [resources](/docs/components/#nodes) this component creates. */
https://github.com/sst/ion/blob/d5c4855b2618198f5e9af315c5e67d4163df165a/platform/src/components/aws/vpc.ts#L864-L915
d5c4855b2618198f5e9af315c5e67d4163df165a
ion
github_2023
sst
typescript
Vpc.get
public static get(name: string, vpcId: Input<string>) { const vpc = ec2.Vpc.get(`${name}Vpc`, vpcId); const internetGateway = ec2.InternetGateway.get( `${name}InstanceGateway`, ec2.getInternetGatewayOutput({ filters: [{ name: "attachment.vpc-id", values: [vpc.id] }], }).internetGatewayId, ); const securityGroup = ec2.SecurityGroup.get( `${name}SecurityGroup`, ec2 .getSecurityGroupsOutput({ filters: [ { name: "group-name", values: ["default"] }, { name: "vpc-id", values: [vpc.id] }, ], }) .ids.apply((ids) => { if (!ids.length) throw new VisibleError(`Security group not found in VPC ${vpcId}`); return ids[0]; }), ); const privateSubnets = ec2 .getSubnetsOutput({ filters: [ { name: "vpc-id", values: [vpc.id] }, { name: "tag:Name", values: ["*Private*"] }, ], }) .ids.apply((ids) => ids.map((id, i) => ec2.Subnet.get(`${name}PrivateSubnet${i + 1}`, id)), ); const privateRouteTables = privateSubnets.apply((subnets) => subnets.map((subnet, i) => ec2.RouteTable.get( `${name}PrivateRouteTable${i + 1}`, ec2.getRouteTableOutput({ subnetId: subnet.id }).routeTableId, ), ), ); const publicSubnets = ec2 .getSubnetsOutput({ filters: [ { name: "vpc-id", values: [vpc.id] }, { name: "tag:Name", values: ["*Public*"] }, ], }) .ids.apply((ids) => ids.map((id, i) => ec2.Subnet.get(`${name}PublicSubnet${i + 1}`, id)), ); const publicRouteTables = publicSubnets.apply((subnets) => subnets.map((subnet, i) => ec2.RouteTable.get( `${name}PublicRouteTable${i + 1}`, ec2.getRouteTableOutput({ subnetId: subnet.id }).routeTableId, ), ), ); const natGateways = publicSubnets.apply((subnets) => { const natGatewayIds = subnets.map((subnet, i) => ec2 .getNatGatewaysOutput({ filters: [ { name: "subnet-id", values: [subnet.id] }, { name: "state", values: ["available"] }, ], }) .ids.apply((ids) => ids[0]), ); return output(natGatewayIds).apply((ids) => ids .filter((id) => id) .map((id, i) => ec2.NatGateway.get(`${name}NatGateway${i + 1}`, id)), ); }); const elasticIps = natGateways.apply((nats) => nats.map((nat, i) => ec2.Eip.get( `${name}ElasticIp${i + 1}`, nat.allocationId as Output<string>, ), ), ); const natInstances = ec2 .getInstancesOutput({ filters: [ { name: "tag:sst:lookup-type", values: ["nat"] }, { name: "vpc-id", values: [vpc.id] }, ], }) .ids.apply((ids) => ids.map((id, i) => ec2.Instance.get(`${name}NatInstance${i + 1}`, id)), ); const bastionInstance = ec2 .getInstancesOutput({ filters: [ { name: "tag:sst:lookup-type", values: ["bastion"] }, { name: "vpc-id", values: [vpc.id] }, ], }) .ids.apply((ids) => ids.length ? ec2.Instance.get(`${name}BastionInstance`, ids[0]) : undefined, ); // Note: can also use servicediscovery.getDnsNamespaceOutput() here, ie. // ```ts // const namespaceId = servicediscovery.getDnsNamespaceOutput({ // name: "sst", // type: "DNS_PRIVATE", // }).id; // ``` // but if user deployed multiple VPCs into the same account. This will error because // there are multiple results. Even though `getDnsNamespaceOutput()` takes tags in args, // the tags are not used for lookup. const zone = output(vpcId).apply((vpcId) => route53.getZone({ name: "sst", privateZone: true, vpcId, }), ); const namespaceId = zone.linkedServiceDescription.apply((description) => { const match = description.match(/:namespace\/(ns-[a-z1-9]*)/)?.[1]; if (!match) throw new VisibleError( `Cloud Map namespace not found for VPC ${vpcId}`, ); return match; }); const cloudmapNamespace = servicediscovery.PrivateDnsNamespace.get( `${name}CloudmapNamespace`, namespaceId, { vpc: vpcId }, ); const privateKeyValue = bastionInstance.apply((v) => { if (!v) return; const param = ssm.Parameter.get( `${name}PrivateKey`, interpolate`/sst/vpc/${vpc.id}/private-key`, ); return param.value; }); return new Vpc(name, { ref: true, vpc, internetGateway, securityGroup, privateSubnets, privateRouteTables, publicSubnets, publicRouteTables, natGateways, natInstances, elasticIps, bastionInstance, cloudmapNamespace, privateKeyValue: output(privateKeyValue), } satisfies VpcRef as VpcArgs); }
/** * Reference an existing VPC with the given ID. This is useful when you * create a VPC in one stage and want to share it in another stage. It avoids having to * create a new VPC in the other stage. * * :::tip * You can use the `static get` method to share VPCs across stages. * ::: * * @param name The name of the component. * @param vpcId The ID of the existing VPC. * * @example * Imagine you create a VPC in the `dev` stage. And in your personal stage `frank`, * instead of creating a new VPC, you want to share the VPC from `dev`. * * ```ts title="sst.config.ts" * const vpc = $app.stage === "frank" * ? sst.aws.Vpc.get("MyVPC", "vpc-0be8fa4de860618bb") * : new sst.aws.Vpc("MyVPC"); * ``` * * Here `vpc-0be8fa4de860618bb` is the ID of the VPC created in the `dev` stage. * You can find this by outputting the VPC ID in the `dev` stage. * * ```ts title="sst.config.ts" * return { * vpc: vpc.id * }; * ``` */
https://github.com/sst/ion/blob/d5c4855b2618198f5e9af315c5e67d4163df165a/platform/src/components/aws/vpc.ts#L948-L1111
d5c4855b2618198f5e9af315c5e67d4163df165a
ion
github_2023
sst
typescript
Vpc.getSSTLink
public getSSTLink() { return { properties: { bastion: this.bastionInstance.apply((v) => v?.id), }, }; }
/** @internal */
https://github.com/sst/ion/blob/d5c4855b2618198f5e9af315c5e67d4163df165a/platform/src/components/aws/vpc.ts#L1114-L1120
d5c4855b2618198f5e9af315c5e67d4163df165a
ion
github_2023
sst
typescript
Auth.getSSTLink
public getSSTLink(): Link.Definition { return { properties: { url: this._authenticator.url, publicKey: secret(this.key.publicKeyPem), }, }; }
/** @internal */
https://github.com/sst/ion/blob/d5c4855b2618198f5e9af315c5e67d4163df165a/platform/src/components/cloudflare/auth.ts#L57-L64
d5c4855b2618198f5e9af315c5e67d4163df165a
ion
github_2023
sst
typescript
Bucket.getSSTLink
getSSTLink() { return { properties: {}, include: [ binding({ type: "r2BucketBindings", properties: { bucketName: this.bucket.name, }, }), ], }; }
/** * When you link a bucket to a worker, you can interact with it using these * [Bucket methods](https://developers.cloudflare.com/r2/api/workers/workers-api-reference/#bucket-method-definitions). * * @example * ```ts title="index.ts" {3} * import { Resource } from "sst"; * * await Resource.MyBucket.list(); * ``` * * @internal */
https://github.com/sst/ion/blob/d5c4855b2618198f5e9af315c5e67d4163df165a/platform/src/components/cloudflare/bucket.ts#L97-L109
d5c4855b2618198f5e9af315c5e67d4163df165a
ion
github_2023
sst
typescript
Bucket.name
public get name() { return this.bucket.name; }
/** * The generated name of the R2 Bucket. */
https://github.com/sst/ion/blob/d5c4855b2618198f5e9af315c5e67d4163df165a/platform/src/components/cloudflare/bucket.ts#L114-L116
d5c4855b2618198f5e9af315c5e67d4163df165a
ion
github_2023
sst
typescript
Bucket.nodes
public get nodes() { return { /** * The Cloudflare R2 Bucket. */ bucket: this.bucket, }; }
/** * The underlying [resources](/docs/components/#nodes) this component creates. */
https://github.com/sst/ion/blob/d5c4855b2618198f5e9af315c5e67d4163df165a/platform/src/components/cloudflare/bucket.ts#L121-L128
d5c4855b2618198f5e9af315c5e67d4163df165a
ion
github_2023
sst
typescript
Cron.nodes
public get nodes() { return { /** * The Cloudflare Worker. */ worker: this.worker.script, /** * The Cloudflare Worker Cron Trigger. */ trigger: this.trigger, }; }
/** * The underlying [resources](/docs/components/#nodes) this component creates. */
https://github.com/sst/ion/blob/d5c4855b2618198f5e9af315c5e67d4163df165a/platform/src/components/cloudflare/cron.ts#L148-L159
d5c4855b2618198f5e9af315c5e67d4163df165a
ion
github_2023
sst
typescript
D1.getSSTLink
getSSTLink() { return { properties: {}, include: [ binding({ type: "d1DatabaseBindings", properties: { databaseId: this.database.id, }, }), ], }; }
/** * When you link a D1 database, the database will be available to the worker and you can * query it using its [API methods](https://developers.cloudflare.com/d1/build-with-d1/d1-client-api/). * * @example * ```ts title="index.ts" {1} "Resource.MyDatabase.prepare" * import { Resource } from "sst"; * * await Resource.MyDatabase.prepare( * "SELECT id FROM todo ORDER BY id DESC LIMIT 1", * ).first(); * ``` * * @internal */
https://github.com/sst/ion/blob/d5c4855b2618198f5e9af315c5e67d4163df165a/platform/src/components/cloudflare/d1.ts#L97-L109
d5c4855b2618198f5e9af315c5e67d4163df165a
ion
github_2023
sst
typescript
D1.id
public get id() { return this.database.id; }
/** * The generated ID of the D1 database. */
https://github.com/sst/ion/blob/d5c4855b2618198f5e9af315c5e67d4163df165a/platform/src/components/cloudflare/d1.ts#L114-L116
d5c4855b2618198f5e9af315c5e67d4163df165a
ion
github_2023
sst
typescript
D1.nodes
public get nodes() { return { /** * The Cloudflare D1 database. */ database: this.database, }; }
/** * The underlying [resources](/docs/components/#nodes) this component creates. */
https://github.com/sst/ion/blob/d5c4855b2618198f5e9af315c5e67d4163df165a/platform/src/components/cloudflare/d1.ts#L121-L128
d5c4855b2618198f5e9af315c5e67d4163df165a
ion
github_2023
sst
typescript
Kv.getSSTLink
getSSTLink() { return { properties: {}, include: [ binding({ type: "kvNamespaceBindings", properties: { namespaceId: this.namespace.id, }, }), ], }; }
/** * When you link a KV storage, the storage will be available to the worker and you can * interact with it using its [API methods](https://developers.cloudflare.com/kv/api/). * * @example * ```ts title="index.ts" {3} * import { Resource } from "sst"; * * await Resource.MyStorage.get("someKey"); * ``` * * @internal */
https://github.com/sst/ion/blob/d5c4855b2618198f5e9af315c5e67d4163df165a/platform/src/components/cloudflare/kv.ts#L93-L105
d5c4855b2618198f5e9af315c5e67d4163df165a
ion
github_2023
sst
typescript
Kv.id
public get id() { return this.namespace.id; }
/** * The generated ID of the KV namespace. */
https://github.com/sst/ion/blob/d5c4855b2618198f5e9af315c5e67d4163df165a/platform/src/components/cloudflare/kv.ts#L110-L112
d5c4855b2618198f5e9af315c5e67d4163df165a
ion
github_2023
sst
typescript
Kv.nodes
public get nodes() { return { /** * The Cloudflare KV namespace. */ namespace: this.namespace, }; }
/** * The underlying [resources](/docs/components/#nodes) this component creates. */
https://github.com/sst/ion/blob/d5c4855b2618198f5e9af315c5e67d4163df165a/platform/src/components/cloudflare/kv.ts#L117-L124
d5c4855b2618198f5e9af315c5e67d4163df165a
ion
github_2023
sst
typescript
Queue.id
public get id() { return this.queue.id; }
/** * The generated id of the queue */
https://github.com/sst/ion/blob/d5c4855b2618198f5e9af315c5e67d4163df165a/platform/src/components/cloudflare/queue.ts#L69-L71
d5c4855b2618198f5e9af315c5e67d4163df165a
ion
github_2023
sst
typescript
Queue.nodes
public get nodes() { return { /** * The Cloudflare queue. */ queue: this.queue, }; }
/** * The underlying [resources](/docs/components/#nodes) this component creates. */
https://github.com/sst/ion/blob/d5c4855b2618198f5e9af315c5e67d4163df165a/platform/src/components/cloudflare/queue.ts#L76-L83
d5c4855b2618198f5e9af315c5e67d4163df165a
ion
github_2023
sst
typescript
Remix.url
public get url() { return this.router.url; }
/** * The URL of the Remix app. * * If the `domain` is set, this is the URL with the custom domain. * Otherwise, it's the autogenerated CloudFront URL. */
https://github.com/sst/ion/blob/d5c4855b2618198f5e9af315c5e67d4163df165a/platform/src/components/cloudflare/remix.ts#L435-L437
d5c4855b2618198f5e9af315c5e67d4163df165a
ion
github_2023
sst
typescript
Remix.nodes
public get nodes() { return { /** * The AWS Lambda server function that renders the site. */ server: this.server, /** * The Amazon S3 Bucket that stores the assets. */ assets: this.assets, }; }
/** * The underlying [resources](/docs/components/#nodes) this component creates. */
https://github.com/sst/ion/blob/d5c4855b2618198f5e9af315c5e67d4163df165a/platform/src/components/cloudflare/remix.ts#L442-L453
d5c4855b2618198f5e9af315c5e67d4163df165a
ion
github_2023
sst
typescript
Remix.getSSTLink
public getSSTLink() { return { properties: { url: this.url, }, }; }
/** @internal */
https://github.com/sst/ion/blob/d5c4855b2618198f5e9af315c5e67d4163df165a/platform/src/components/cloudflare/remix.ts#L456-L462
d5c4855b2618198f5e9af315c5e67d4163df165a
ion
github_2023
sst
typescript
StaticSite.url
public get url() { return this.router.url; }
/** * The URL of the website. * * If the `domain` is set, this is the URL with the custom domain. * Otherwise, it's the autogenerated worker URL. */
https://github.com/sst/ion/blob/d5c4855b2618198f5e9af315c5e67d4163df165a/platform/src/components/cloudflare/static-site.ts#L423-L425
d5c4855b2618198f5e9af315c5e67d4163df165a
ion
github_2023
sst
typescript
StaticSite.nodes
public get nodes() { return { /** * The KV namespace that stores the assets. */ assets: this.assets, /** * The worker that serves the requests. */ router: this.router, }; }
/** * The underlying [resources](/docs/components/#nodes) this component creates. */
https://github.com/sst/ion/blob/d5c4855b2618198f5e9af315c5e67d4163df165a/platform/src/components/cloudflare/static-site.ts#L430-L441
d5c4855b2618198f5e9af315c5e67d4163df165a
ion
github_2023
sst
typescript
StaticSite.getSSTLink
public getSSTLink() { return { properties: { url: this.url, }, }; }
/** @internal */
https://github.com/sst/ion/blob/d5c4855b2618198f5e9af315c5e67d4163df165a/platform/src/components/cloudflare/static-site.ts#L444-L450
d5c4855b2618198f5e9af315c5e67d4163df165a
ion
github_2023
sst
typescript
Worker.url
public get url() { return this.workerDomain ? interpolate`https://${this.workerDomain.hostname}` : this.workerUrl.url.apply((url) => (url ? `https://${url}` : url)); }
/** * The Worker URL if `url` is enabled. */
https://github.com/sst/ion/blob/d5c4855b2618198f5e9af315c5e67d4163df165a/platform/src/components/cloudflare/worker.ts#L493-L497
d5c4855b2618198f5e9af315c5e67d4163df165a
ion
github_2023
sst
typescript
Worker.nodes
public get nodes() { return { /** * The Cloudflare Worker script. */ worker: this.script, }; }
/** * The underlying [resources](/docs/components/#nodes) this component creates. */
https://github.com/sst/ion/blob/d5c4855b2618198f5e9af315c5e67d4163df165a/platform/src/components/cloudflare/worker.ts#L502-L509
d5c4855b2618198f5e9af315c5e67d4163df165a
ion
github_2023
sst
typescript
Worker.getSSTLink
getSSTLink() { return { properties: { url: this.url, }, include: [ binding({ type: "serviceBindings", properties: { service: this.script.id, }, }), ], }; }
/** * When you link a worker, say WorkerA, to another worker, WorkerB; it automatically creates * a service binding between the workers. It allows WorkerA to call WorkerB without going * through a publicly-accessible URL. * * @example * ```ts title="index.ts" {3} * import { Resource } from "sst"; * * await Resource.WorkerB.fetch(request); * ``` * * Read more about [binding Workers](https://developers.cloudflare.com/workers/runtime-apis/bindings/service-bindings/). * * @internal */
https://github.com/sst/ion/blob/d5c4855b2618198f5e9af315c5e67d4163df165a/platform/src/components/cloudflare/worker.ts#L527-L541
d5c4855b2618198f5e9af315c5e67d4163df165a
ion
github_2023
sst
typescript
getPythonFiles
async function getPythonFiles( filePath: string, ): Promise<{ pythonFiles: string[]; rootDir: string }> { try { // Get the absolute path of the file const absPath = path.resolve(filePath); // Get the directory of the file const dir = path.dirname(absPath); const pythonFiles: string[] = []; /** * Recursively walks through the directory and its subdirectories to find Python files. * * @param currentPath - The current directory path being walked. */ async function walkDirectory(currentPath: string): Promise<void> { let entries: fsSync.Dirent[]; try { entries = await fs.readdir(currentPath, { withFileTypes: true }); } catch (err) { // If there's an error accessing the path, skip it return; } for (const entry of entries) { const entryPath = path.join(currentPath, entry.name); if (entry.isDirectory()) { if (entry.name === "__pycache__") { // Skip directories named "__pycache__" continue; } // Recursively walk the subdirectory await walkDirectory(entryPath); } else if (entry.isFile()) { const ext = path.extname(entry.name).toLowerCase(); if (ext === ".py" || ext === ".pyi") { pythonFiles.push(entryPath); } } } } // Start walking from the directory await walkDirectory(dir); return { pythonFiles, rootDir: dir }; } catch (error) { throw new Error(`Error in getPythonFiles: ${(error as Error).message}`); } }
/** * Recursively retrieves all Python files (.py and .pyi) from the directory of the given file path, * excluding any directories named "__pycache__". * * @param filePath - The path to the file whose directory will be searched. * @returns A promise that resolves to an array of Python file paths and the root directory. * @throws An error if the absolute path cannot be determined or if there's an issue walking the directory. */
https://github.com/sst/ion/blob/d5c4855b2618198f5e9af315c5e67d4163df165a/platform/src/runtime/python.ts#L259-L312
d5c4855b2618198f5e9af315c5e67d4163df165a
ion
github_2023
sst
typescript
walkDirectory
async function walkDirectory(currentPath: string): Promise<void> { let entries: fsSync.Dirent[]; try { entries = await fs.readdir(currentPath, { withFileTypes: true }); } catch (err) { // If there's an error accessing the path, skip it return; } for (const entry of entries) { const entryPath = path.join(currentPath, entry.name); if (entry.isDirectory()) { if (entry.name === "__pycache__") { // Skip directories named "__pycache__" continue; } // Recursively walk the subdirectory await walkDirectory(entryPath); } else if (entry.isFile()) { const ext = path.extname(entry.name).toLowerCase(); if (ext === ".py" || ext === ".pyi") { pythonFiles.push(entryPath); } } } }
/** * Recursively walks through the directory and its subdirectories to find Python files. * * @param currentPath - The current directory path being walked. */
https://github.com/sst/ion/blob/d5c4855b2618198f5e9af315c5e67d4163df165a/platform/src/runtime/python.ts#L276-L303
d5c4855b2618198f5e9af315c5e67d4163df165a
ion
github_2023
sst
typescript
copyFilesPreservingStructure
async function copyFilesPreservingStructure( pythonFiles: string[], sourceRoot: string, destinationRoot: string, baseDir?: string, ): Promise<void> { try { const dest = baseDir ? destinationRoot.slice(0, -baseDir.length) : destinationRoot; for (const filePath of pythonFiles) { // Determine the relative path from the source root const relativePath = path.relative(sourceRoot, filePath); // Determine the destination path const destPath = path.join(dest, relativePath); // Ensure the destination directory exists const destDir = path.dirname(destPath); await fs.mkdir(destDir, { recursive: true }); // Copy the file await fs.copyFile(filePath, destPath); } } catch (error) { throw new Error( `Error in copyFilesPreservingStructure: ${(error as Error).message}`, ); } }
/** * Copies the given Python files to the destination directory, preserving their directory structure relative to the source root. * * @param pythonFiles - An array of absolute paths to Python files. * @param sourceRoot - The root directory from which the files are being copied. * @param destinationRoot - The directory where the files will be copied to. * @returns A promise that resolves when all files have been copied. * @throws An error if any file operations fail. */
https://github.com/sst/ion/blob/d5c4855b2618198f5e9af315c5e67d4163df165a/platform/src/runtime/python.ts#L323-L353
d5c4855b2618198f5e9af315c5e67d4163df165a
ion
github_2023
sst
typescript
renderHeader
function renderHeader(title: string, description: string) { return [`---`, `title: ${title}`, `description: ${description}`, `---`]; }
/*************************/
https://github.com/sst/ion/blob/d5c4855b2618198f5e9af315c5e67d4163df165a/www/generate.ts#L681-L683
d5c4855b2618198f5e9af315c5e67d4163df165a
ion
github_2023
sst
typescript
isModuleComponent
function isModuleComponent(module: TypeDoc.DeclarationReflection) { const sourceFile = module.sources![0].fileName; return ( sourceFile !== "platform/src/config.ts" && sourceFile !== "platform/src/global-config.d.ts" && !sourceFile.endsWith("/dns.ts") && !sourceFile.endsWith("/aws/permission.ts") && !sourceFile.endsWith("/cloudflare/binding.ts") ); }
/***************************************/
https://github.com/sst/ion/blob/d5c4855b2618198f5e9af315c5e67d4163df165a/www/generate.ts#L1839-L1848
d5c4855b2618198f5e9af315c5e67d4163df165a
ion
github_2023
sst
typescript
configureLogger
function configureLogger() { if (process.env.DEBUG) return; console.debug = () => {}; }
/********************/
https://github.com/sst/ion/blob/d5c4855b2618198f5e9af315c5e67d4163df165a/www/generate.ts#L1977-L1980
d5c4855b2618198f5e9af315c5e67d4163df165a
Lumos
github_2023
andrewnguonly
typescript
CSVPackedLoader.parse
public async parse(raw: string): Promise<string[]> { const { column, separator = "," } = this.options; const psv = dsvFormat(separator); // cannot use psv.parse(), unsafe-eval is not allowed let parsed = psv.parseRows(raw.trim()); if (column !== undefined) { if (!parsed[0].includes(column)) { throw new Error(`Column ${column} not found in CSV file.`); } // get index of column const columnIndex = parsed[0].indexOf(column); // Note TextLoader will raise an exception if the value is null. // eslint-disable-next-line @typescript-eslint/no-non-null-assertion return parsed.map((row) => row[columnIndex]!); } // parsed = [["foo", "bar"], ["1", "2"], ["3", "4"]] // output strings = ["foo: 1\nbar: 2", "foo: 3\nbar: 4"] // get first element of parsed const headers = parsed[0]; parsed = parsed.slice(1); return parsed.map((row) => row.map((key, index) => `${headers[index]}: ${key}`).join("\n"), ); }
/** * This function is copied from the CSVLoader class with a few * modifications so that it's able to run in a Chrome extension * context. */
https://github.com/andrewnguonly/Lumos/blob/69ff12ed3da5846eb40c3233e9dcdafb6cb64f60/src/document_loaders/csv.ts#L10-L38
69ff12ed3da5846eb40c3233e9dcdafb6cb64f60
Lumos
github_2023
andrewnguonly
typescript
classifyPrompt
const classifyPrompt = async ( options: LumosOptions, type: string, originalPrompt: string, classifcationPrompt: string, prefixTrigger?: string, ): Promise<boolean> => { // check for prefix trigger if (prefixTrigger) { if (originalPrompt.trim().toLowerCase().startsWith(prefixTrigger)) { return new Promise((resolve) => resolve(true)); } } // otherwise, attempt to classify prompt const ollama = new Ollama({ baseUrl: options.ollamaHost, model: options.ollamaModel, keepAlive: DEFAULT_KEEP_ALIVE, temperature: 0, stop: [".", ","], }).bind({ signal: controller.signal, }); const finalPrompt = `${classifcationPrompt} Answer with 'yes' or 'no'.\n\nPrompt: ${originalPrompt}`; return ollama.invoke(finalPrompt).then((response) => { console.log(`${type} classification response: ${response}`); const answer = response.trim().split(" ")[0].toLowerCase(); return answer.includes("yes"); }); };
/** * Determine if a prompt is positively classified as described in the * classifcation prompt. If so, return true. Otherwise, return false. * * @param baseURL Ollama base URL * @param model Ollama model name * @param type Type of classification. Only used for logging. * @param originalPrompt Prompt to be classified * @param classifcationPrompt Prompt that will classify originalPrompt * @param prefixTrigger Prefix trigger that will override LLM classification * @returns True if originalPrompt is positively classified by the classificationPrompt. Otherwise, false. */
https://github.com/andrewnguonly/Lumos/blob/69ff12ed3da5846eb40c3233e9dcdafb6cb64f60/src/scripts/background.ts#L77-L107
69ff12ed3da5846eb40c3233e9dcdafb6cb64f60
Lumos
github_2023
andrewnguonly
typescript
filterFunction
const filterFunction = (memoryVector: (typeof this.memoryVectors)[0]) => { if (!filter) { return true; } const doc = new Document({ metadata: memoryVector.metadata, pageContent: memoryVector.content, }); return filter(doc); };
// filter documents (MemoryVector interface is not exported...)
https://github.com/andrewnguonly/Lumos/blob/69ff12ed3da5846eb40c3233e9dcdafb6cb64f60/src/vectorstores/enhanced_memory.ts#L122-L132
69ff12ed3da5846eb40c3233e9dcdafb6cb64f60
cyphernetes
github_2023
AvitalTamir
typescript
convertQueryResourceNames
async function convertQueryResourceNames(query: string): Promise<string> { const regex = /\((\w+):(\w+)\)/g; const matches = query.match(regex); if (!matches) return query; for (const match of matches) { const [, , resourceName] = match.match(/\((\w+):(\w+)\)/) || []; if (resourceName) { const singularName = await convertResourceName(resourceName); query = query.replace(match, match.replace(resourceName, singularName)); } } return query; }
// Helper function to convert resource names in the query
https://github.com/AvitalTamir/cyphernetes/blob/941cf7a1ee1f9bc90f4f9913ced9b9791b4acd9e/web/src/api/queryApi.ts#L66-L81
941cf7a1ee1f9bc90f4f9913ced9b9791b4acd9e
inspect_ai
github_2023
UKGovernmentBEIS
typescript
filterLargeSample
function filterLargeSample(state: ApplicationState) { if (!state || !state.selectedSample) { return state; } const estimatedTotalSize = estimateSize(state.selectedSample.messages); if (estimatedTotalSize > 400000) { const { selectedSample, ...filteredState } = state; // eslint-disable-line return filteredState; } else { return state; } }
// Filters the selected Sample if it is large
https://github.com/UKGovernmentBEIS/inspect_ai/blob/fa64ceab7a943432114e5b8dada495d781b132ea/src/inspect_ai/_view/www/src/index.tsx#L70-L82
fa64ceab7a943432114e5b8dada495d781b132ea
inspect_ai
github_2023
UKGovernmentBEIS
typescript
filterLargeSelectedLog
function filterLargeSelectedLog(state: ApplicationState) { if (!state || !state.selectedLog?.contents) { return state; } const estimatedSize = estimateSize( state.selectedLog.contents.sampleSummaries, ); if (estimatedSize > 400000) { const { selectedLog, ...filteredState } = state; // eslint-disable-line return filteredState; } else { return state; } }
// Filters the selectedlog if it is too large
https://github.com/UKGovernmentBEIS/inspect_ai/blob/fa64ceab7a943432114e5b8dada495d781b132ea/src/inspect_ai/_view/www/src/index.tsx#L85-L99
fa64ceab7a943432114e5b8dada495d781b132ea
inspect_ai
github_2023
UKGovernmentBEIS
typescript
simpleHttpAPI
function simpleHttpAPI(logInfo: LogInfo): LogViewAPI { const log_dir = logInfo.log_dir; async function open_log_file() { // No op } return { client_events: async () => { // There are no client events in the case of serving via // http return Promise.resolve([]); }, eval_logs: async (): Promise<LogFiles | undefined> => { // First check based upon the log dir if (log_dir) { const headers = await fetchLogHeaders(log_dir); if (headers) { const logRecord = headers.parsed; const logs = Object.keys(logRecord).map((key) => { return { name: joinURI(log_dir, key), task: logRecord[key].eval.task, task_id: logRecord[key].eval.task_id, }; }); return Promise.resolve({ files: logs, log_dir, }); } } return undefined; }, eval_log: async ( log_file: string, _headerOnly?: number, _capabilities?: Capabilities, ) => { const response = await fetchLogFile(log_file); if (response) { return response; } else { throw new Error(`"Unable to load eval log ${log_file}`); } }, eval_log_size: async (log_file: string) => { return await fetchSize(log_file); }, eval_log_bytes: async (log_file: string, start: number, end: number) => { return await fetchRange(log_file, start, end); }, eval_log_headers: async (files: string[]) => { if (files.length === 0) { return []; } if (log_dir) { const headers = await fetchLogHeaders(log_dir); if (headers) { const keys = Object.keys(headers.parsed); const result: EvalLog[] = []; files.forEach((file) => { const fileKey = keys.find((key) => { return file.endsWith(key); }); if (fileKey) { result.push(headers.parsed[fileKey]); } }); return result; } } // No log.json could be found, and there isn't a log file, throw new Error( `Failed to load a manifest files using the directory: ${log_dir}. Please be sure you have deployed a manifest file (logs.json).`, ); }, download_file, open_log_file, }; }
/** * Fetches a file from the specified URL and parses its content. */
https://github.com/UKGovernmentBEIS/inspect_ai/blob/fa64ceab7a943432114e5b8dada495d781b132ea/src/inspect_ai/_view/www/src/api/api-http.ts#L39-L121
fa64ceab7a943432114e5b8dada495d781b132ea
inspect_ai
github_2023
UKGovernmentBEIS
typescript
fetchFile
async function fetchFile<T>( url: string, parse: (text: string) => Promise<T>, handleError?: (response: Response) => boolean, ): Promise<T | undefined> { const safe_url = encodePathParts(url); const response = await fetch(`${safe_url}`, { method: "GET" }); if (response.ok) { const text = await response.text(); return await parse(text); } else if (response.status !== 200) { if (handleError && handleError(response)) { return undefined; } const message = (await response.text()) || response.statusText; const error = new Error(`${response.status}: ${message})`); throw error; } else { throw new Error(`${response.status} - ${response.statusText} `); } }
/** * Fetches a file from the specified URL and parses its content. */
https://github.com/UKGovernmentBEIS/inspect_ai/blob/fa64ceab7a943432114e5b8dada495d781b132ea/src/inspect_ai/_view/www/src/api/api-http.ts#L126-L146
fa64ceab7a943432114e5b8dada495d781b132ea
inspect_ai
github_2023
UKGovernmentBEIS
typescript
fetchLogFile
const fetchLogFile = async (file: string): Promise<LogContents | undefined> => { return fetchFile<LogContents>(file, async (text): Promise<LogContents> => { const log = (await asyncJsonParse(text)) as EvalLog; if (log.version === 1) { if (log.results) { const untypedLog = log as any; log.results.scores = []; untypedLog.results.scorer.scorer = untypedLog.results.scorer.name; log.results.scores.push(untypedLog.results.scorer); delete untypedLog.results.scorer; log.results.scores[0].metrics = untypedLog.results.metrics; delete untypedLog.results.metrics; // migrate samples const scorerName = log.results.scores[0].name; log.samples?.forEach((sample) => { const untypedSample = sample as any; sample.scores = { [scorerName]: untypedSample.score }; delete untypedSample.score; }); } } return { raw: text, parsed: log, }; }); };
/** * Fetches a log file and parses its content, updating the log structure if necessary. */
https://github.com/UKGovernmentBEIS/inspect_ai/blob/fa64ceab7a943432114e5b8dada495d781b132ea/src/inspect_ai/_view/www/src/api/api-http.ts#L151-L178
fa64ceab7a943432114e5b8dada495d781b132ea
inspect_ai
github_2023
UKGovernmentBEIS
typescript
fetchLogHeaders
const fetchLogHeaders = async ( log_dir: string, ): Promise<LogFilesFetchResponse | undefined> => { const logs = await fetchFile<LogFilesFetchResponse>( log_dir + "/logs.json", async (text) => { const parsed = await asyncJsonParse(text); return { raw: text, parsed, }; }, (response) => { if (response.status === 404) { // Couldn't find a header file return true; } else { return false; } }, ); return logs; };
/** * Fetches a log file and parses its content, updating the log structure if necessary. */
https://github.com/UKGovernmentBEIS/inspect_ai/blob/fa64ceab7a943432114e5b8dada495d781b132ea/src/inspect_ai/_view/www/src/api/api-http.ts#L183-L205
fa64ceab7a943432114e5b8dada495d781b132ea
inspect_ai
github_2023
UKGovernmentBEIS
typescript
joinURI
function joinURI(...segments: string[]): string { return segments .map((segment) => segment.replace(/(^\/+|\/+$)/g, "")) // Remove leading/trailing slashes from each segment .join("/"); }
/** * Joins multiple URI segments into a single URI string. * * This function removes any leading or trailing slashes from each segment * and then joins them with a single slash (`/`). */
https://github.com/UKGovernmentBEIS/inspect_ai/blob/fa64ceab7a943432114e5b8dada495d781b132ea/src/inspect_ai/_view/www/src/api/api-http.ts#L213-L217
fa64ceab7a943432114e5b8dada495d781b132ea
inspect_ai
github_2023
UKGovernmentBEIS
typescript
get_log
const get_log = async ( log_file: string, cached = false, ): Promise<LogContents> => { // If the requested log is different or no cached log exists, start fetching if (!cached || log_file !== current_path || !current_log) { // If there's already a pending fetch, return the same promise if (pending_log_promise) { return pending_log_promise; } // Otherwise, create a new promise for fetching the log pending_log_promise = api .eval_log(log_file, 100) .then((log) => { current_log = log; current_path = log_file; pending_log_promise = null; return log; }) .catch((err) => { pending_log_promise = null; throw err; }); return pending_log_promise; } return current_log; };
/** * Gets a log */
https://github.com/UKGovernmentBEIS/inspect_ai/blob/fa64ceab7a943432114e5b8dada495d781b132ea/src/inspect_ai/_view/www/src/api/client-api.ts#L75-L103
fa64ceab7a943432114e5b8dada495d781b132ea
inspect_ai
github_2023
UKGovernmentBEIS
typescript
get_log_summary
const get_log_summary = async (log_file: string): Promise<EvalSummary> => { if (isEvalFile(log_file)) { const remoteLogFile = await remoteEvalFile(log_file); if (remoteLogFile) { return await remoteLogFile.readLogSummary(); } else { throw new Error("Unable to read remote eval file"); } } else { const logContents = await get_log(log_file); /** * @type {import("./Types.js").SampleSummary[]} */ const sampleSummaries = logContents.parsed.samples ? logContents.parsed.samples?.map((sample) => { return { id: sample.id, epoch: sample.epoch, input: sample.input, target: sample.target, scores: sample.scores, metadata: sample.metadata, error: sample.error?.message, }; }) : []; const parsed = logContents.parsed; return { version: parsed.version, status: parsed.status, eval: parsed.eval, plan: parsed.plan, results: parsed.results, stats: parsed.stats, error: parsed.error, sampleSummaries, }; } };
/** * Gets a log summary */
https://github.com/UKGovernmentBEIS/inspect_ai/blob/fa64ceab7a943432114e5b8dada495d781b132ea/src/inspect_ai/_view/www/src/api/client-api.ts#L109-L148
fa64ceab7a943432114e5b8dada495d781b132ea
inspect_ai
github_2023
UKGovernmentBEIS
typescript
get_log_sample
const get_log_sample = async ( log_file: string, id: string | number, epoch: number, ): Promise<EvalSample | undefined> => { if (isEvalFile(log_file)) { const remoteLogFile = await remoteEvalFile(log_file, true); try { if (remoteLogFile) { const sample = await remoteLogFile.readSample(String(id), epoch); return sample; } else { throw new Error(`Unable to read remove eval file ${log_file}`); } } catch (error) { if (error instanceof FileSizeLimitError) { throw new SampleSizeLimitedExceededError(id, epoch, error.maxBytes); } else { throw error; } } } else { const logContents = await get_log(log_file, true); if (logContents.parsed.samples && logContents.parsed.samples.length > 0) { return logContents.parsed.samples.find((sample) => { return sample.id === id && sample.epoch === epoch; }); } } return undefined; };
/** * Gets a sample */
https://github.com/UKGovernmentBEIS/inspect_ai/blob/fa64ceab7a943432114e5b8dada495d781b132ea/src/inspect_ai/_view/www/src/api/client-api.ts#L153-L183
fa64ceab7a943432114e5b8dada495d781b132ea
inspect_ai
github_2023
UKGovernmentBEIS
typescript
get_log_headers
const get_log_headers = async (log_files: string[]): Promise<EvalLog[]> => { const eval_files: Record<string, number> = {}; const json_files: Record<string, number> = {}; let index = 0; // Separate files into eval_files and json_files for (const file of log_files) { if (isEvalFile(file)) { eval_files[file] = index; } else { json_files[file] = index; } index++; } // Get the promises for eval log headers const evalLogHeadersPromises = Object.keys(eval_files).map((file) => get_eval_log_header(file).then((header) => ({ index: eval_files[file], // Store original index header, })), ); // Get the promise for json log headers const jsonLogHeadersPromise = api .eval_log_headers(Object.keys(json_files)) .then((headers) => headers.map((header, i) => ({ index: json_files[Object.keys(json_files)[i]], // Store original index header, })), ); // Wait for all promises to resolve const headers = await Promise.all([ ...evalLogHeadersPromises, jsonLogHeadersPromise, ]); // Flatten the nested array and sort headers by their original index const orderedHeaders = headers.flat().sort((a, b) => a.index - b.index); // Return only the header values in the correct order return orderedHeaders.map(({ header }) => header); };
/** * Gets log headers */
https://github.com/UKGovernmentBEIS/inspect_ai/blob/fa64ceab7a943432114e5b8dada495d781b132ea/src/inspect_ai/_view/www/src/api/client-api.ts#L198-L242
fa64ceab7a943432114e5b8dada495d781b132ea
inspect_ai
github_2023
UKGovernmentBEIS
typescript
resolveApi
const resolveApi = (): ClientAPI => { if (getVscodeApi()) { // This is VSCode return clientApi(vscodeApi); } else { // See if there is an log_file, log_dir embedded in the // document or passed via URL (could be hosted) const scriptEl = document.getElementById("log_dir_context"); if (scriptEl) { // Read the contents const context = scriptEl.textContent; if (context !== null) { const data = JSON.parse(context); if (data.log_dir || data.log_file) { const log_dir = data.log_dir || dirname(data.log_file); const api = simpleHttpApi(log_dir, data.log_file); return clientApi(api, data.log_file); } } } // See if there is url params passing info (could be hosted) const urlParams = new URLSearchParams(window.location.search); const log_file = urlParams.get("log_file"); const log_dir = urlParams.get("log_dir"); if (log_file !== null || log_dir !== null) { const resolved_log_dir = log_dir === null ? undefined : log_dir; const resolved_log_file = log_file === null ? undefined : log_file; const api = simpleHttpApi(resolved_log_dir, resolved_log_file); return clientApi(api, resolved_log_file); } // No signal information so use the standard // browser API (inspect view) return clientApi(browserApi); } };
//
https://github.com/UKGovernmentBEIS/inspect_ai/blob/fa64ceab7a943432114e5b8dada495d781b132ea/src/inspect_ai/_view/www/src/api/index.ts#L13-L49
fa64ceab7a943432114e5b8dada495d781b132ea