sst 3.0.22 → 3.0.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/test/event.test.js +1 -7
- package/package.json +1 -1
- package/dist/auth/adapter/adapter.d.ts +0 -24
- package/dist/auth/adapter/adapter.js +0 -4
- package/dist/auth/adapter/apple.d.ts +0 -5
- package/dist/auth/adapter/apple.js +0 -22
- package/dist/auth/adapter/code.d.ts +0 -8
- package/dist/auth/adapter/code.js +0 -47
- package/dist/auth/adapter/facebook.d.ts +0 -5
- package/dist/auth/adapter/facebook.js +0 -27
- package/dist/auth/adapter/github.d.ts +0 -12
- package/dist/auth/adapter/github.js +0 -23
- package/dist/auth/adapter/google.d.ts +0 -17
- package/dist/auth/adapter/google.js +0 -22
- package/dist/auth/adapter/index.d.ts +0 -11
- package/dist/auth/adapter/index.js +0 -10
- package/dist/auth/adapter/link.d.ts +0 -6
- package/dist/auth/adapter/link.js +0 -27
- package/dist/auth/adapter/microsoft.d.ts +0 -11
- package/dist/auth/adapter/microsoft.js +0 -16
- package/dist/auth/adapter/oauth.d.ts +0 -33
- package/dist/auth/adapter/oauth.js +0 -79
- package/dist/auth/adapter/oidc.d.ts +0 -19
- package/dist/auth/adapter/oidc.js +0 -45
- package/dist/auth/adapter/spotify.d.ts +0 -12
- package/dist/auth/adapter/spotify.js +0 -22
- package/dist/auth/example/bun.d.ts +0 -2
- package/dist/auth/example/bun.js +0 -46
- package/dist/auth/handler.d.ts +0 -58
- package/dist/auth/handler.js +0 -207
- package/dist/auth/index.d.ts +0 -10
- package/dist/auth/index.js +0 -10
- package/dist/auth/session.d.ts +0 -25
- package/dist/auth/session.js +0 -28
- package/dist/aws/bus.d.ts +0 -24
- package/dist/aws/bus.js +0 -57
- package/dist/aws/client.d.ts +0 -3
- package/dist/aws/client.js +0 -7
- package/dist/aws/realtime.d.ts +0 -61
- package/dist/aws/realtime.js +0 -76
- package/dist/event/bus.d.ts +0 -20
- package/dist/event/bus.js +0 -57
- package/dist/event/destination.d.ts +0 -19
- package/dist/event/destination.js +0 -6
- package/dist/event/event.d.ts +0 -75
- package/dist/event/event.js +0 -43
- package/dist/event/index.d.ts +0 -75
- package/dist/event/index.js +0 -43
- package/dist/index.d.ts +0 -3
- package/dist/index.js +0 -3
- package/dist/realtime/index.d.ts +0 -25
- package/dist/realtime/index.js +0 -24
- package/dist/resource.d.ts +0 -9
- package/dist/resource.js +0 -50
- package/dist/util/prettify.d.ts +0 -3
- package/dist/util/prettify.js +0 -1
- package/dist/vector/index.d.ts +0 -193
- package/dist/vector/index.js +0 -62
- package/dist/vector-client.d.ts +0 -186
- package/dist/vector-client.js +0 -41
package/dist/event/event.d.ts
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { ZodSchema, z } from "zod";
|
|
2
|
-
export declare namespace event {
|
|
3
|
-
export type Definition = {
|
|
4
|
-
type: string;
|
|
5
|
-
$input: any;
|
|
6
|
-
$output: any;
|
|
7
|
-
$metadata: any;
|
|
8
|
-
$payload: any;
|
|
9
|
-
create: (...args: any[]) => Promise<any>;
|
|
10
|
-
};
|
|
11
|
-
export function builder<MetadataFunction extends (type: string, properties: any) => any, Validator extends (schema: any) => (input: any) => any, MetadataSchema extends Parameters<Validator>[0] | undefined>(input: {
|
|
12
|
-
metadata?: MetadataSchema;
|
|
13
|
-
metadataFn?: MetadataFunction;
|
|
14
|
-
validator: Validator;
|
|
15
|
-
}): {
|
|
16
|
-
<Type extends string, Schema extends Parameters<Validator>[0]>(type: Type, schema: Schema): {
|
|
17
|
-
create: undefined extends MetadataSchema ? (properties: inferParser<Schema>["in"]) => Promise<{
|
|
18
|
-
type: Type;
|
|
19
|
-
properties: inferParser<Schema>["out"];
|
|
20
|
-
metadata: ReturnType<MetadataFunction>;
|
|
21
|
-
}> : (properties: inferParser<Schema>["in"], metadata: inferParser<MetadataSchema>["in"]) => Promise<{
|
|
22
|
-
type: Type;
|
|
23
|
-
properties: inferParser<Schema>["out"];
|
|
24
|
-
metadata: ReturnType<MetadataFunction>;
|
|
25
|
-
}>;
|
|
26
|
-
type: Type;
|
|
27
|
-
$input: inferParser<Schema>["in"];
|
|
28
|
-
$output: inferParser<Schema>["out"];
|
|
29
|
-
$payload: {
|
|
30
|
-
type: Type;
|
|
31
|
-
properties: inferParser<Schema>["out"];
|
|
32
|
-
metadata: ReturnType<MetadataFunction>;
|
|
33
|
-
};
|
|
34
|
-
$metadata: ReturnType<MetadataFunction>;
|
|
35
|
-
};
|
|
36
|
-
coerce<Events extends Definition>(_events: Events | Events[], raw: any): { [K in Events["type"]]: Extract<Events, {
|
|
37
|
-
type: K;
|
|
38
|
-
}>["$payload"]; }[Events["type"]];
|
|
39
|
-
};
|
|
40
|
-
export function ZodValidator<Schema extends ZodSchema>(schema: Schema): (input: z.input<Schema>) => z.output<Schema>;
|
|
41
|
-
type ParserZodEsque<TInput, TParsedInput> = {
|
|
42
|
-
_input: TInput;
|
|
43
|
-
_output: TParsedInput;
|
|
44
|
-
};
|
|
45
|
-
type ParserValibotEsque<TInput, TParsedInput> = {
|
|
46
|
-
_types?: {
|
|
47
|
-
input: TInput;
|
|
48
|
-
output: TParsedInput;
|
|
49
|
-
};
|
|
50
|
-
};
|
|
51
|
-
type ParserMyZodEsque<TInput> = {
|
|
52
|
-
parse: (input: any) => TInput;
|
|
53
|
-
};
|
|
54
|
-
type ParserSuperstructEsque<TInput> = {
|
|
55
|
-
create: (input: unknown) => TInput;
|
|
56
|
-
};
|
|
57
|
-
type ParserCustomValidatorEsque<TInput> = (input: unknown) => Promise<TInput> | TInput;
|
|
58
|
-
type ParserYupEsque<TInput> = {
|
|
59
|
-
validateSync: (input: unknown) => TInput;
|
|
60
|
-
};
|
|
61
|
-
type ParserScaleEsque<TInput> = {
|
|
62
|
-
assert(value: unknown): asserts value is TInput;
|
|
63
|
-
};
|
|
64
|
-
export type ParserWithoutInput<TInput> = ParserCustomValidatorEsque<TInput> | ParserMyZodEsque<TInput> | ParserScaleEsque<TInput> | ParserSuperstructEsque<TInput> | ParserYupEsque<TInput>;
|
|
65
|
-
export type ParserWithInputOutput<TInput, TParsedInput> = ParserZodEsque<TInput, TParsedInput> | ParserValibotEsque<TInput, TParsedInput>;
|
|
66
|
-
export type Parser = ParserWithInputOutput<any, any> | ParserWithoutInput<any>;
|
|
67
|
-
export type inferParser<TParser extends Parser> = TParser extends ParserWithInputOutput<infer $TIn, infer $TOut> ? {
|
|
68
|
-
in: $TIn;
|
|
69
|
-
out: $TOut;
|
|
70
|
-
} : TParser extends ParserWithoutInput<infer $InOut> ? {
|
|
71
|
-
in: $InOut;
|
|
72
|
-
out: $InOut;
|
|
73
|
-
} : never;
|
|
74
|
-
export {};
|
|
75
|
-
}
|
package/dist/event/event.js
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
export var event;
|
|
2
|
-
(function (event) {
|
|
3
|
-
function builder(input) {
|
|
4
|
-
const validator = input.validator;
|
|
5
|
-
const metadataValidator = input.metadata ? validator(input.metadata) : null;
|
|
6
|
-
const fn = function event(type, schema) {
|
|
7
|
-
const validate = validator(schema);
|
|
8
|
-
async function create(properties, metadata) {
|
|
9
|
-
if (metadataValidator) {
|
|
10
|
-
metadata = metadataValidator(metadata);
|
|
11
|
-
}
|
|
12
|
-
if (input.metadataFn) {
|
|
13
|
-
metadata = input.metadataFn(type, properties);
|
|
14
|
-
}
|
|
15
|
-
properties = validate(properties);
|
|
16
|
-
return {
|
|
17
|
-
type,
|
|
18
|
-
properties,
|
|
19
|
-
metadata,
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
return {
|
|
23
|
-
create: create,
|
|
24
|
-
type,
|
|
25
|
-
$input: {},
|
|
26
|
-
$output: {},
|
|
27
|
-
$payload: {},
|
|
28
|
-
$metadata: {},
|
|
29
|
-
};
|
|
30
|
-
};
|
|
31
|
-
fn.coerce = (_events, raw) => {
|
|
32
|
-
return raw;
|
|
33
|
-
};
|
|
34
|
-
return fn;
|
|
35
|
-
}
|
|
36
|
-
event.builder = builder;
|
|
37
|
-
function ZodValidator(schema) {
|
|
38
|
-
return (input) => {
|
|
39
|
-
return schema.parse(input);
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
event.ZodValidator = ZodValidator;
|
|
43
|
-
})(event || (event = {}));
|
package/dist/event/index.d.ts
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { ZodSchema, z } from "zod";
|
|
2
|
-
export declare namespace event {
|
|
3
|
-
export type Definition = {
|
|
4
|
-
type: string;
|
|
5
|
-
$input: any;
|
|
6
|
-
$output: any;
|
|
7
|
-
$metadata: any;
|
|
8
|
-
$payload: any;
|
|
9
|
-
create: (...args: any[]) => Promise<any>;
|
|
10
|
-
};
|
|
11
|
-
export function builder<MetadataFunction extends (type: string, properties: any) => any, Validator extends (schema: any) => (input: any) => any, MetadataSchema extends Parameters<Validator>[0] | undefined>(input: {
|
|
12
|
-
metadata?: MetadataSchema;
|
|
13
|
-
metadataFn?: MetadataFunction;
|
|
14
|
-
validator: Validator;
|
|
15
|
-
}): {
|
|
16
|
-
<Type extends string, Schema extends Parameters<Validator>[0]>(type: Type, schema: Schema): {
|
|
17
|
-
create: undefined extends MetadataSchema ? (properties: inferParser<Schema>["in"]) => Promise<{
|
|
18
|
-
type: Type;
|
|
19
|
-
properties: inferParser<Schema>["out"];
|
|
20
|
-
metadata: ReturnType<MetadataFunction>;
|
|
21
|
-
}> : (properties: inferParser<Schema>["in"], metadata: inferParser<MetadataSchema>["in"]) => Promise<{
|
|
22
|
-
type: Type;
|
|
23
|
-
properties: inferParser<Schema>["out"];
|
|
24
|
-
metadata: ReturnType<MetadataFunction>;
|
|
25
|
-
}>;
|
|
26
|
-
type: Type;
|
|
27
|
-
$input: inferParser<Schema>["in"];
|
|
28
|
-
$output: inferParser<Schema>["out"];
|
|
29
|
-
$payload: {
|
|
30
|
-
type: Type;
|
|
31
|
-
properties: inferParser<Schema>["out"];
|
|
32
|
-
metadata: ReturnType<MetadataFunction>;
|
|
33
|
-
};
|
|
34
|
-
$metadata: ReturnType<MetadataFunction>;
|
|
35
|
-
};
|
|
36
|
-
coerce<Events extends Definition>(_events: Events | Events[], raw: any): { [K in Events["type"]]: Extract<Events, {
|
|
37
|
-
type: K;
|
|
38
|
-
}>["$payload"]; }[Events["type"]];
|
|
39
|
-
};
|
|
40
|
-
export function ZodValidator<Schema extends ZodSchema>(schema: Schema): (input: z.input<Schema>) => z.output<Schema>;
|
|
41
|
-
type ParserZodEsque<TInput, TParsedInput> = {
|
|
42
|
-
_input: TInput;
|
|
43
|
-
_output: TParsedInput;
|
|
44
|
-
};
|
|
45
|
-
type ParserValibotEsque<TInput, TParsedInput> = {
|
|
46
|
-
_types?: {
|
|
47
|
-
input: TInput;
|
|
48
|
-
output: TParsedInput;
|
|
49
|
-
};
|
|
50
|
-
};
|
|
51
|
-
type ParserMyZodEsque<TInput> = {
|
|
52
|
-
parse: (input: any) => TInput;
|
|
53
|
-
};
|
|
54
|
-
type ParserSuperstructEsque<TInput> = {
|
|
55
|
-
create: (input: unknown) => TInput;
|
|
56
|
-
};
|
|
57
|
-
type ParserCustomValidatorEsque<TInput> = (input: unknown) => Promise<TInput> | TInput;
|
|
58
|
-
type ParserYupEsque<TInput> = {
|
|
59
|
-
validateSync: (input: unknown) => TInput;
|
|
60
|
-
};
|
|
61
|
-
type ParserScaleEsque<TInput> = {
|
|
62
|
-
assert(value: unknown): asserts value is TInput;
|
|
63
|
-
};
|
|
64
|
-
export type ParserWithoutInput<TInput> = ParserCustomValidatorEsque<TInput> | ParserMyZodEsque<TInput> | ParserScaleEsque<TInput> | ParserSuperstructEsque<TInput> | ParserYupEsque<TInput>;
|
|
65
|
-
export type ParserWithInputOutput<TInput, TParsedInput> = ParserZodEsque<TInput, TParsedInput> | ParserValibotEsque<TInput, TParsedInput>;
|
|
66
|
-
export type Parser = ParserWithInputOutput<any, any> | ParserWithoutInput<any>;
|
|
67
|
-
export type inferParser<TParser extends Parser> = TParser extends ParserWithInputOutput<infer $TIn, infer $TOut> ? {
|
|
68
|
-
in: $TIn;
|
|
69
|
-
out: $TOut;
|
|
70
|
-
} : TParser extends ParserWithoutInput<infer $InOut> ? {
|
|
71
|
-
in: $InOut;
|
|
72
|
-
out: $InOut;
|
|
73
|
-
} : never;
|
|
74
|
-
export {};
|
|
75
|
-
}
|
package/dist/event/index.js
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
export var event;
|
|
2
|
-
(function (event) {
|
|
3
|
-
function builder(input) {
|
|
4
|
-
const validator = input.validator;
|
|
5
|
-
const metadataValidator = input.metadata ? validator(input.metadata) : null;
|
|
6
|
-
const fn = function event(type, schema) {
|
|
7
|
-
const validate = validator(schema);
|
|
8
|
-
async function create(properties, metadata) {
|
|
9
|
-
if (metadataValidator) {
|
|
10
|
-
metadata = metadataValidator(metadata);
|
|
11
|
-
}
|
|
12
|
-
if (input.metadataFn) {
|
|
13
|
-
metadata = input.metadataFn(type, properties);
|
|
14
|
-
}
|
|
15
|
-
properties = validate(properties);
|
|
16
|
-
return {
|
|
17
|
-
type,
|
|
18
|
-
properties,
|
|
19
|
-
metadata,
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
return {
|
|
23
|
-
create: create,
|
|
24
|
-
type,
|
|
25
|
-
$input: {},
|
|
26
|
-
$output: {},
|
|
27
|
-
$payload: {},
|
|
28
|
-
$metadata: {},
|
|
29
|
-
};
|
|
30
|
-
};
|
|
31
|
-
fn.coerce = (_events, raw) => {
|
|
32
|
-
return raw;
|
|
33
|
-
};
|
|
34
|
-
return fn;
|
|
35
|
-
}
|
|
36
|
-
event.builder = builder;
|
|
37
|
-
function ZodValidator(schema) {
|
|
38
|
-
return (input) => {
|
|
39
|
-
return schema.parse(input);
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
event.ZodValidator = ZodValidator;
|
|
43
|
-
})(event || (event = {}));
|
package/dist/index.d.ts
DELETED
package/dist/index.js
DELETED
package/dist/realtime/index.d.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { realtime } from "../aws/realtime.js";
|
|
2
|
-
export type RealtimeAuthResult = realtime.AuthResult;
|
|
3
|
-
/**
|
|
4
|
-
* @deprecated import from `sst/aws/realtime` instead.
|
|
5
|
-
*
|
|
6
|
-
* Creates an authorization handler for the `Realtime` component, that validates
|
|
7
|
-
* the token and grants permissions for the topics the client can subscribe and publish to.
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
* ```js
|
|
11
|
-
* import { RealtimeAuthHandler, Resource } from "sst";
|
|
12
|
-
*
|
|
13
|
-
* export const handler = RealtimeAuthHandler(async (token) => {
|
|
14
|
-
* // Validate the token
|
|
15
|
-
* console.log(token);
|
|
16
|
-
*
|
|
17
|
-
* // Return the topics to subscribe and publish
|
|
18
|
-
* return {
|
|
19
|
-
* subscribe: [`${Resource.App.name}/${Resource.App.stage}/chat/room1`],
|
|
20
|
-
* publish: [`${Resource.App.name}/${Resource.App.stage}/chat/room1`],
|
|
21
|
-
* };
|
|
22
|
-
* });
|
|
23
|
-
* ```
|
|
24
|
-
*/
|
|
25
|
-
export declare const RealtimeAuthHandler: typeof realtime.authorizer;
|
package/dist/realtime/index.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { realtime } from "../aws/realtime.js";
|
|
2
|
-
/**
|
|
3
|
-
* @deprecated import from `sst/aws/realtime` instead.
|
|
4
|
-
*
|
|
5
|
-
* Creates an authorization handler for the `Realtime` component, that validates
|
|
6
|
-
* the token and grants permissions for the topics the client can subscribe and publish to.
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* ```js
|
|
10
|
-
* import { RealtimeAuthHandler, Resource } from "sst";
|
|
11
|
-
*
|
|
12
|
-
* export const handler = RealtimeAuthHandler(async (token) => {
|
|
13
|
-
* // Validate the token
|
|
14
|
-
* console.log(token);
|
|
15
|
-
*
|
|
16
|
-
* // Return the topics to subscribe and publish
|
|
17
|
-
* return {
|
|
18
|
-
* subscribe: [`${Resource.App.name}/${Resource.App.stage}/chat/room1`],
|
|
19
|
-
* publish: [`${Resource.App.name}/${Resource.App.stage}/chat/room1`],
|
|
20
|
-
* };
|
|
21
|
-
* });
|
|
22
|
-
* ```
|
|
23
|
-
*/
|
|
24
|
-
export const RealtimeAuthHandler = realtime.authorizer;
|
package/dist/resource.d.ts
DELETED
package/dist/resource.js
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { env } from "node:process";
|
|
2
|
-
const raw = {
|
|
3
|
-
// @ts-expect-error,
|
|
4
|
-
...globalThis.$SST_LINKS,
|
|
5
|
-
};
|
|
6
|
-
for (const [key, value] of Object.entries(env)) {
|
|
7
|
-
if (key.startsWith("SST_RESOURCE_") && value) {
|
|
8
|
-
raw[key.slice("SST_RESOURCE_".length)] = JSON.parse(value);
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
export function fromCloudflareEnv(input) {
|
|
12
|
-
for (let [key, value] of Object.entries(input)) {
|
|
13
|
-
if (typeof value === "string") {
|
|
14
|
-
try {
|
|
15
|
-
value = JSON.parse(value);
|
|
16
|
-
}
|
|
17
|
-
catch { }
|
|
18
|
-
}
|
|
19
|
-
raw[key] = value;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
export function wrapCloudflareHandler(handler) {
|
|
23
|
-
if (typeof handler === "function" && handler.hasOwnProperty("prototype")) {
|
|
24
|
-
return class extends handler {
|
|
25
|
-
constructor(ctx, env) {
|
|
26
|
-
fromCloudflareEnv(env);
|
|
27
|
-
super(ctx, env);
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
function wrap(fn) {
|
|
32
|
-
return function (req, env, ...rest) {
|
|
33
|
-
fromCloudflareEnv(env);
|
|
34
|
-
return fn(req, env, ...rest);
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
const result = {};
|
|
38
|
-
for (const [key, value] of Object.entries(handler)) {
|
|
39
|
-
result[key] = wrap(value);
|
|
40
|
-
}
|
|
41
|
-
return result;
|
|
42
|
-
}
|
|
43
|
-
export const Resource = new Proxy(raw, {
|
|
44
|
-
get(_target, prop) {
|
|
45
|
-
if (prop in raw) {
|
|
46
|
-
return raw[prop];
|
|
47
|
-
}
|
|
48
|
-
throw new Error(`"${prop}" is not linked`);
|
|
49
|
-
},
|
|
50
|
-
});
|
package/dist/util/prettify.d.ts
DELETED
package/dist/util/prettify.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/vector/index.d.ts
DELETED
|
@@ -1,193 +0,0 @@
|
|
|
1
|
-
import { Resource } from "../resource.js";
|
|
2
|
-
export interface PutEvent {
|
|
3
|
-
/**
|
|
4
|
-
* The vector to store in the database.
|
|
5
|
-
* @example
|
|
6
|
-
* ```js
|
|
7
|
-
* {
|
|
8
|
-
* vector: [32.4, 6.55, 11.2, 10.3, 87.9],
|
|
9
|
-
* }
|
|
10
|
-
* ```
|
|
11
|
-
*/
|
|
12
|
-
vector: number[];
|
|
13
|
-
/**
|
|
14
|
-
* Metadata for the event in JSON format.
|
|
15
|
-
* This metadata will be used to filter when quering and removing vectors.
|
|
16
|
-
* @example
|
|
17
|
-
* ```js
|
|
18
|
-
* {
|
|
19
|
-
* metadata: {
|
|
20
|
-
* type: "movie",
|
|
21
|
-
* id: "movie-123",
|
|
22
|
-
* name: "Spiderman",
|
|
23
|
-
* }
|
|
24
|
-
* }
|
|
25
|
-
* ```
|
|
26
|
-
*/
|
|
27
|
-
metadata: Record<string, any>;
|
|
28
|
-
}
|
|
29
|
-
export interface QueryEvent {
|
|
30
|
-
/**
|
|
31
|
-
* The vector used to query the database.
|
|
32
|
-
* @example
|
|
33
|
-
* ```js
|
|
34
|
-
* {
|
|
35
|
-
* vector: [32.4, 6.55, 11.2, 10.3, 87.9],
|
|
36
|
-
* }
|
|
37
|
-
* ```
|
|
38
|
-
*/
|
|
39
|
-
vector: number[];
|
|
40
|
-
/**
|
|
41
|
-
* The metadata used to filter the vectors.
|
|
42
|
-
* Only vectors that match the provided fields will be returned.
|
|
43
|
-
* @example
|
|
44
|
-
* ```js
|
|
45
|
-
* {
|
|
46
|
-
* include: {
|
|
47
|
-
* type: "movie",
|
|
48
|
-
* release: "2001",
|
|
49
|
-
* }
|
|
50
|
-
* }
|
|
51
|
-
* ```
|
|
52
|
-
* This will match the vector with metadata:
|
|
53
|
-
* ```js
|
|
54
|
-
* {
|
|
55
|
-
* type: "movie",
|
|
56
|
-
* name: "Spiderman",
|
|
57
|
-
* release: "2001",
|
|
58
|
-
* }
|
|
59
|
-
* ```
|
|
60
|
-
*
|
|
61
|
-
* But not the vector with metadata:
|
|
62
|
-
* ```js
|
|
63
|
-
* {
|
|
64
|
-
* type: "book",
|
|
65
|
-
* name: "Spiderman",
|
|
66
|
-
* release: "2001",
|
|
67
|
-
* }
|
|
68
|
-
* ```
|
|
69
|
-
*/
|
|
70
|
-
include: Record<string, any>;
|
|
71
|
-
/**
|
|
72
|
-
* Exclude vectors with metadata that match the provided fields.
|
|
73
|
-
* @example
|
|
74
|
-
* ```js
|
|
75
|
-
* {
|
|
76
|
-
* include: {
|
|
77
|
-
* type: "movie",
|
|
78
|
-
* release: "2001",
|
|
79
|
-
* },
|
|
80
|
-
* exclude: {
|
|
81
|
-
* name: "Spiderman",
|
|
82
|
-
* }
|
|
83
|
-
* }
|
|
84
|
-
* ```
|
|
85
|
-
* This will match the vector with metadata:
|
|
86
|
-
* ```js
|
|
87
|
-
* {
|
|
88
|
-
* type: "movie",
|
|
89
|
-
* name: "A Beautiful Mind",
|
|
90
|
-
* release: "2001",
|
|
91
|
-
* }
|
|
92
|
-
* ```
|
|
93
|
-
*
|
|
94
|
-
* But not the vector with metadata:
|
|
95
|
-
* ```js
|
|
96
|
-
* {
|
|
97
|
-
* type: "book",
|
|
98
|
-
* name: "Spiderman",
|
|
99
|
-
* release: "2001",
|
|
100
|
-
* }
|
|
101
|
-
* ```
|
|
102
|
-
*/
|
|
103
|
-
exclude?: Record<string, any>;
|
|
104
|
-
/**
|
|
105
|
-
* The threshold of similarity between the prompt and the queried vectors.
|
|
106
|
-
* Only vectors with a similarity score higher than the threshold will be returned.
|
|
107
|
-
* Expected value is between 0 and 1.
|
|
108
|
-
* - 0 means the prompt and the queried vectors are completely different.
|
|
109
|
-
* - 1 means the prompt and the queried vectors are identical.
|
|
110
|
-
* @default `0`
|
|
111
|
-
* @example
|
|
112
|
-
* ```js
|
|
113
|
-
* {
|
|
114
|
-
* threshold: 0.5,
|
|
115
|
-
* }
|
|
116
|
-
* ```
|
|
117
|
-
*/
|
|
118
|
-
threshold?: number;
|
|
119
|
-
/**
|
|
120
|
-
* The number of results to return.
|
|
121
|
-
* @default `10`
|
|
122
|
-
* @example
|
|
123
|
-
* ```js
|
|
124
|
-
* {
|
|
125
|
-
* count: 10,
|
|
126
|
-
* }
|
|
127
|
-
* ```
|
|
128
|
-
*/
|
|
129
|
-
count?: number;
|
|
130
|
-
}
|
|
131
|
-
export interface RemoveEvent {
|
|
132
|
-
/**
|
|
133
|
-
* The metadata used to filter the removal of vectors.
|
|
134
|
-
* Only vectors with metadata that match the provided fields will be removed.
|
|
135
|
-
* @example
|
|
136
|
-
* To remove vectors for movie with id "movie-123":
|
|
137
|
-
* ```js
|
|
138
|
-
* {
|
|
139
|
-
* include: {
|
|
140
|
-
* id: "movie-123",
|
|
141
|
-
* }
|
|
142
|
-
* }
|
|
143
|
-
* ```
|
|
144
|
-
* To remove vectors for all movies:
|
|
145
|
-
* ```js
|
|
146
|
-
* {
|
|
147
|
-
* include: {
|
|
148
|
-
* type: "movie",
|
|
149
|
-
* }
|
|
150
|
-
* }
|
|
151
|
-
* ```
|
|
152
|
-
*/
|
|
153
|
-
include: Record<string, any>;
|
|
154
|
-
}
|
|
155
|
-
export interface QueryResponse {
|
|
156
|
-
/**
|
|
157
|
-
* Metadata for the event in JSON format that was provided when storing the vector.
|
|
158
|
-
*/
|
|
159
|
-
metadata: Record<string, any>;
|
|
160
|
-
/**
|
|
161
|
-
* The similarity score between the prompt and the queried vector.
|
|
162
|
-
*/
|
|
163
|
-
score: number;
|
|
164
|
-
}
|
|
165
|
-
export interface VectorClientResponse {
|
|
166
|
-
put: (event: PutEvent) => Promise<void>;
|
|
167
|
-
query: (event: QueryEvent) => Promise<QueryResponse>;
|
|
168
|
-
remove: (event: RemoveEvent) => Promise<void>;
|
|
169
|
-
}
|
|
170
|
-
/**
|
|
171
|
-
* Create a client to interact with the Vector database.
|
|
172
|
-
* @example
|
|
173
|
-
* ```js
|
|
174
|
-
* import { VectorClient } from "sst";
|
|
175
|
-
* const client = VectorClient("MyVectorDB");
|
|
176
|
-
*
|
|
177
|
-
* // Store a vector into the db
|
|
178
|
-
* await client.put({
|
|
179
|
-
* vector: [32.4, 6.55, 11.2, 10.3, 87.9],
|
|
180
|
-
* metadata: { type: "movie", genre: "comedy" },
|
|
181
|
-
* });
|
|
182
|
-
*
|
|
183
|
-
* // Query vectors similar to the provided vector
|
|
184
|
-
* const result = await client.query({
|
|
185
|
-
* vector: [32.4, 6.55, 11.2, 10.3, 87.9],
|
|
186
|
-
* include: { type: "movie" },
|
|
187
|
-
* exclude: { genre: "thriller" },
|
|
188
|
-
* });
|
|
189
|
-
* ```
|
|
190
|
-
*/
|
|
191
|
-
export declare function VectorClient<T extends keyof {
|
|
192
|
-
[key in keyof Resource as "sst.aws.Vector" extends Resource[key]["type"] ? string extends key ? never : key : never]: Resource[key];
|
|
193
|
-
}>(name: T): VectorClientResponse;
|
package/dist/vector/index.js
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import { LambdaClient, InvokeCommand, } from "@aws-sdk/client-lambda";
|
|
2
|
-
import { Resource } from "../resource.js";
|
|
3
|
-
const lambda = new LambdaClient();
|
|
4
|
-
/**
|
|
5
|
-
* Create a client to interact with the Vector database.
|
|
6
|
-
* @example
|
|
7
|
-
* ```js
|
|
8
|
-
* import { VectorClient } from "sst";
|
|
9
|
-
* const client = VectorClient("MyVectorDB");
|
|
10
|
-
*
|
|
11
|
-
* // Store a vector into the db
|
|
12
|
-
* await client.put({
|
|
13
|
-
* vector: [32.4, 6.55, 11.2, 10.3, 87.9],
|
|
14
|
-
* metadata: { type: "movie", genre: "comedy" },
|
|
15
|
-
* });
|
|
16
|
-
*
|
|
17
|
-
* // Query vectors similar to the provided vector
|
|
18
|
-
* const result = await client.query({
|
|
19
|
-
* vector: [32.4, 6.55, 11.2, 10.3, 87.9],
|
|
20
|
-
* include: { type: "movie" },
|
|
21
|
-
* exclude: { genre: "thriller" },
|
|
22
|
-
* });
|
|
23
|
-
* ```
|
|
24
|
-
*/
|
|
25
|
-
export function VectorClient(name) {
|
|
26
|
-
return {
|
|
27
|
-
put: async (event) => {
|
|
28
|
-
const ret = await lambda.send(new InvokeCommand({
|
|
29
|
-
// @ts-expect-error
|
|
30
|
-
FunctionName: Resource[name].putFunction,
|
|
31
|
-
Payload: JSON.stringify(event),
|
|
32
|
-
}));
|
|
33
|
-
parsePayload(ret, "Failed to store into the vector db");
|
|
34
|
-
},
|
|
35
|
-
query: async (event) => {
|
|
36
|
-
const ret = await lambda.send(new InvokeCommand({
|
|
37
|
-
// @ts-expect-error
|
|
38
|
-
FunctionName: Resource[name].queryFunction,
|
|
39
|
-
Payload: JSON.stringify(event),
|
|
40
|
-
}));
|
|
41
|
-
return parsePayload(ret, "Failed to query the vector db");
|
|
42
|
-
},
|
|
43
|
-
remove: async (event) => {
|
|
44
|
-
const ret = await lambda.send(new InvokeCommand({
|
|
45
|
-
// @ts-expect-error
|
|
46
|
-
FunctionName: Resource[name].removeFunction,
|
|
47
|
-
Payload: JSON.stringify(event),
|
|
48
|
-
}));
|
|
49
|
-
parsePayload(ret, "Failed to remove from the vector db");
|
|
50
|
-
},
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
function parsePayload(output, message) {
|
|
54
|
-
const payload = JSON.parse(Buffer.from(output.Payload).toString());
|
|
55
|
-
// Set cause to the payload so that it can be logged in CloudWatch
|
|
56
|
-
if (output.FunctionError) {
|
|
57
|
-
const e = new Error(message);
|
|
58
|
-
e.cause = payload;
|
|
59
|
-
throw e;
|
|
60
|
-
}
|
|
61
|
-
return payload;
|
|
62
|
-
}
|