sst 3.0.1-8 → 3.0.1
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/bin/sst.mjs +28 -0
- package/dist/auth/adapter/adapter.d.ts +24 -0
- package/dist/auth/adapter/adapter.js +4 -0
- package/dist/auth/adapter/apple.d.ts +5 -0
- package/dist/auth/adapter/apple.js +22 -0
- package/dist/auth/adapter/code.d.ts +8 -0
- package/dist/auth/adapter/code.js +47 -0
- package/dist/auth/adapter/facebook.d.ts +5 -0
- package/dist/auth/adapter/facebook.js +27 -0
- package/dist/auth/adapter/github.d.ts +12 -0
- package/dist/auth/adapter/github.js +23 -0
- package/dist/auth/adapter/google.d.ts +17 -0
- package/dist/auth/adapter/google.js +22 -0
- package/dist/auth/adapter/index.d.ts +11 -0
- package/dist/auth/adapter/index.js +10 -0
- package/dist/auth/adapter/link.d.ts +6 -0
- package/dist/auth/adapter/link.js +27 -0
- package/dist/auth/adapter/microsoft.d.ts +11 -0
- package/dist/auth/adapter/microsoft.js +16 -0
- package/dist/auth/adapter/oauth.d.ts +33 -0
- package/dist/auth/adapter/oauth.js +82 -0
- package/dist/auth/adapter/oidc.d.ts +19 -0
- package/dist/auth/adapter/oidc.js +48 -0
- package/dist/auth/adapter/spotify.d.ts +12 -0
- package/dist/auth/adapter/spotify.js +22 -0
- package/dist/auth/example/bun.d.ts +2 -0
- package/dist/auth/example/bun.js +46 -0
- package/dist/auth/handler.d.ts +57 -0
- package/dist/auth/handler.js +207 -0
- package/dist/auth/index.d.ts +10 -0
- package/dist/auth/index.js +10 -0
- package/dist/auth/session.d.ts +25 -0
- package/dist/auth/session.js +28 -0
- package/dist/aws/auth.d.ts +9 -0
- package/dist/aws/auth.js +12 -0
- package/dist/aws/bus.d.ts +29 -0
- package/dist/aws/bus.js +69 -0
- package/dist/aws/client.d.ts +3 -0
- package/dist/aws/client.js +36 -0
- package/dist/aws/realtime.d.ts +84 -0
- package/dist/aws/realtime.js +82 -0
- package/dist/event/index.d.ts +72 -0
- package/dist/event/index.js +35 -0
- package/dist/event/validator.d.ts +4 -0
- package/dist/event/validator.js +11 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/realtime/index.d.ts +25 -0
- package/dist/realtime/index.js +24 -0
- package/dist/resource.d.ts +6 -4
- package/dist/resource.js +54 -5
- package/dist/util/prettify.d.ts +3 -0
- package/dist/util/prettify.js +1 -0
- package/dist/vector/index.d.ts +238 -0
- package/dist/vector/index.js +68 -0
- package/package.json +46 -11
- package/dist/vector-client.d.ts +0 -126
- package/dist/vector-client.js +0 -38
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
export declare namespace event {
|
|
2
|
+
export type Definition = {
|
|
3
|
+
type: string;
|
|
4
|
+
$input: any;
|
|
5
|
+
$output: any;
|
|
6
|
+
$metadata: any;
|
|
7
|
+
$payload: any;
|
|
8
|
+
create: (...args: any[]) => Promise<any>;
|
|
9
|
+
};
|
|
10
|
+
export function builder<Metadata extends ((type: string, properties: any) => any) | Parameters<Validator>[0], Validator extends (schema: any) => (input: any) => any>(input: {
|
|
11
|
+
validator: Validator;
|
|
12
|
+
metadata?: Metadata;
|
|
13
|
+
}): {
|
|
14
|
+
<Type extends string, Schema extends Parameters<Validator>[0]>(type: Type, schema: Schema): {
|
|
15
|
+
create: Metadata extends (type: string, properties: any) => any ? (properties: inferParser<Schema>["in"]) => Promise<{
|
|
16
|
+
type: Type;
|
|
17
|
+
properties: inferParser<Schema>["out"];
|
|
18
|
+
metadata: Metadata extends (type: string, properties: any) => any ? ReturnType<Metadata> : inferParser<Metadata>["out"];
|
|
19
|
+
}> : (properties: inferParser<Schema>["in"], metadata: inferParser<Metadata>["in"]) => Promise<{
|
|
20
|
+
type: Type;
|
|
21
|
+
properties: inferParser<Schema>["out"];
|
|
22
|
+
metadata: Metadata extends (type: string, properties: any) => any ? ReturnType<Metadata> : inferParser<Metadata>["out"];
|
|
23
|
+
}>;
|
|
24
|
+
type: Type;
|
|
25
|
+
$input: inferParser<Schema>["in"];
|
|
26
|
+
$output: inferParser<Schema>["out"];
|
|
27
|
+
$payload: {
|
|
28
|
+
type: Type;
|
|
29
|
+
properties: inferParser<Schema>["out"];
|
|
30
|
+
metadata: Metadata extends (type: string, properties: any) => any ? ReturnType<Metadata> : inferParser<Metadata>["out"];
|
|
31
|
+
};
|
|
32
|
+
$metadata: Metadata extends (type: string, properties: any) => any ? ReturnType<Metadata> : inferParser<Metadata>["out"];
|
|
33
|
+
};
|
|
34
|
+
coerce<Events extends Definition>(_events: Events | Events[], raw: any): { [K in Events["type"]]: Extract<Events, {
|
|
35
|
+
type: K;
|
|
36
|
+
}>["$payload"]; }[Events["type"]];
|
|
37
|
+
};
|
|
38
|
+
type ParserZodEsque<TInput, TParsedInput> = {
|
|
39
|
+
_input: TInput;
|
|
40
|
+
_output: TParsedInput;
|
|
41
|
+
};
|
|
42
|
+
type ParserValibotEsque<TInput, TParsedInput> = {
|
|
43
|
+
_types?: {
|
|
44
|
+
input: TInput;
|
|
45
|
+
output: TParsedInput;
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
type ParserMyZodEsque<TInput> = {
|
|
49
|
+
parse: (input: any) => TInput;
|
|
50
|
+
};
|
|
51
|
+
type ParserSuperstructEsque<TInput> = {
|
|
52
|
+
create: (input: unknown) => TInput;
|
|
53
|
+
};
|
|
54
|
+
type ParserCustomValidatorEsque<TInput> = (input: unknown) => Promise<TInput> | TInput;
|
|
55
|
+
type ParserYupEsque<TInput> = {
|
|
56
|
+
validateSync: (input: unknown) => TInput;
|
|
57
|
+
};
|
|
58
|
+
type ParserScaleEsque<TInput> = {
|
|
59
|
+
assert(value: unknown): asserts value is TInput;
|
|
60
|
+
};
|
|
61
|
+
export type ParserWithoutInput<TInput> = ParserCustomValidatorEsque<TInput> | ParserMyZodEsque<TInput> | ParserScaleEsque<TInput> | ParserSuperstructEsque<TInput> | ParserYupEsque<TInput>;
|
|
62
|
+
export type ParserWithInputOutput<TInput, TParsedInput> = ParserZodEsque<TInput, TParsedInput> | ParserValibotEsque<TInput, TParsedInput>;
|
|
63
|
+
export type Parser = ParserWithInputOutput<any, any> | ParserWithoutInput<any>;
|
|
64
|
+
export type inferParser<TParser extends Parser> = TParser extends ParserWithInputOutput<infer $TIn, infer $TOut> ? {
|
|
65
|
+
in: $TIn;
|
|
66
|
+
out: $TOut;
|
|
67
|
+
} : TParser extends ParserWithoutInput<infer $InOut> ? {
|
|
68
|
+
in: $InOut;
|
|
69
|
+
out: $InOut;
|
|
70
|
+
} : never;
|
|
71
|
+
export {};
|
|
72
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export var event;
|
|
2
|
+
(function (event) {
|
|
3
|
+
function builder(input) {
|
|
4
|
+
const validator = input.validator;
|
|
5
|
+
const fn = function event(type, schema) {
|
|
6
|
+
const validate = validator(schema);
|
|
7
|
+
async function create(properties, metadata) {
|
|
8
|
+
metadata = input.metadata
|
|
9
|
+
? typeof input.metadata === "function"
|
|
10
|
+
? input.metadata(type, properties)
|
|
11
|
+
: input.metadata(metadata)
|
|
12
|
+
: {};
|
|
13
|
+
properties = validate(properties);
|
|
14
|
+
return {
|
|
15
|
+
type,
|
|
16
|
+
properties,
|
|
17
|
+
metadata,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
return {
|
|
21
|
+
create: create,
|
|
22
|
+
type,
|
|
23
|
+
$input: {},
|
|
24
|
+
$output: {},
|
|
25
|
+
$payload: {},
|
|
26
|
+
$metadata: {},
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
fn.coerce = (_events, raw) => {
|
|
30
|
+
return raw;
|
|
31
|
+
};
|
|
32
|
+
return fn;
|
|
33
|
+
}
|
|
34
|
+
event.builder = builder;
|
|
35
|
+
})(event || (event = {}));
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { ZodSchema, z } from "zod";
|
|
2
|
+
export declare function ZodValidator<Schema extends ZodSchema>(schema: Schema): (input: z.input<Schema>) => z.output<Schema>;
|
|
3
|
+
import { BaseSchema, Input } from "valibot";
|
|
4
|
+
export declare function ValibotValidator<T extends BaseSchema>(schema: T): (value: Input<T>) => import("valibot").Output<T>;
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -0,0 +1,25 @@
|
|
|
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;
|
|
@@ -0,0 +1,24 @@
|
|
|
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
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
export interface Resource {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
App: {
|
|
3
|
+
name: string;
|
|
4
|
+
stage: string;
|
|
5
|
+
};
|
|
6
6
|
}
|
|
7
|
+
export declare function fromCloudflareEnv(input: any): void;
|
|
8
|
+
export declare function wrapCloudflareHandler(handler: any): any;
|
|
7
9
|
export declare const Resource: Resource;
|
package/dist/resource.js
CHANGED
|
@@ -1,8 +1,57 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { env } from "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 { }
|
|
5
18
|
}
|
|
6
|
-
|
|
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
|
+
if (!env.SST_RESOURCE_App) {
|
|
49
|
+
throw new Error("It does not look like SST links are active. If this is in local development and you are not starting this process through the multiplexer, wrap your command with `sst dev -- <command>`");
|
|
50
|
+
}
|
|
51
|
+
let msg = `"${prop}" is not linked in your sst.config.ts`;
|
|
52
|
+
if (env.AWS_LAMBDA_FUNCTION_NAME) {
|
|
53
|
+
msg += ` to ${env.AWS_LAMBDA_FUNCTION_NAME}`;
|
|
54
|
+
}
|
|
55
|
+
throw new Error(msg);
|
|
7
56
|
},
|
|
8
57
|
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,238 @@
|
|
|
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 as JSON.
|
|
15
|
+
* This will be used to filter when querying 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
|
+
* Given this filter.
|
|
45
|
+
* ```js
|
|
46
|
+
* {
|
|
47
|
+
* include: {
|
|
48
|
+
* type: "movie",
|
|
49
|
+
* release: "2001"
|
|
50
|
+
* }
|
|
51
|
+
* }
|
|
52
|
+
* ```
|
|
53
|
+
* It will match a vector with the metadata:
|
|
54
|
+
* ```js
|
|
55
|
+
* {
|
|
56
|
+
* type: "movie",
|
|
57
|
+
* name: "Spiderman",
|
|
58
|
+
* release: "2001"
|
|
59
|
+
* }
|
|
60
|
+
* ```
|
|
61
|
+
*
|
|
62
|
+
* But not a vector with this metadata:
|
|
63
|
+
* ```js
|
|
64
|
+
* {
|
|
65
|
+
* type: "book",
|
|
66
|
+
* name: "Spiderman",
|
|
67
|
+
* release: "2001"
|
|
68
|
+
* }
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
include: Record<string, any>;
|
|
72
|
+
/**
|
|
73
|
+
* Exclude vectors with metadata that match the provided fields.
|
|
74
|
+
* @example
|
|
75
|
+
* Given this filter.
|
|
76
|
+
* ```js
|
|
77
|
+
* {
|
|
78
|
+
* include: {
|
|
79
|
+
* type: "movie",
|
|
80
|
+
* release: "2001"
|
|
81
|
+
* },
|
|
82
|
+
* exclude: {
|
|
83
|
+
* name: "Spiderman"
|
|
84
|
+
* }
|
|
85
|
+
* }
|
|
86
|
+
* ```
|
|
87
|
+
* This will match a vector with metadata:
|
|
88
|
+
* ```js
|
|
89
|
+
* {
|
|
90
|
+
* type: "movie",
|
|
91
|
+
* name: "A Beautiful Mind",
|
|
92
|
+
* release: "2001"
|
|
93
|
+
* }
|
|
94
|
+
* ```
|
|
95
|
+
*
|
|
96
|
+
* But not a vector with the metadata:
|
|
97
|
+
* ```js
|
|
98
|
+
* {
|
|
99
|
+
* type: "book",
|
|
100
|
+
* name: "Spiderman",
|
|
101
|
+
* release: "2001"
|
|
102
|
+
* }
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
exclude?: Record<string, any>;
|
|
106
|
+
/**
|
|
107
|
+
* The threshold of similarity between the prompt and the queried vectors.
|
|
108
|
+
* Only vectors with a similarity score higher than the threshold will be returned.
|
|
109
|
+
*
|
|
110
|
+
* This will return values is between 0 and 1.
|
|
111
|
+
* - `0` means the prompt and the queried vectors are completely different.
|
|
112
|
+
* - `1` means the prompt and the queried vectors are identical.
|
|
113
|
+
*
|
|
114
|
+
* @default `0`
|
|
115
|
+
* @example
|
|
116
|
+
* ```js
|
|
117
|
+
* {
|
|
118
|
+
* threshold: 0.5
|
|
119
|
+
* }
|
|
120
|
+
* ```
|
|
121
|
+
*/
|
|
122
|
+
threshold?: number;
|
|
123
|
+
/**
|
|
124
|
+
* The number of results to return.
|
|
125
|
+
* @default `10`
|
|
126
|
+
* @example
|
|
127
|
+
* ```js
|
|
128
|
+
* {
|
|
129
|
+
* count: 10
|
|
130
|
+
* }
|
|
131
|
+
* ```
|
|
132
|
+
*/
|
|
133
|
+
count?: number;
|
|
134
|
+
}
|
|
135
|
+
export interface RemoveEvent {
|
|
136
|
+
/**
|
|
137
|
+
* The metadata used to filter the removal of vectors.
|
|
138
|
+
* Only vectors with metadata that match the provided fields will be removed.
|
|
139
|
+
* @example
|
|
140
|
+
* To remove vectors for movie with id `movie-123`:
|
|
141
|
+
* ```js
|
|
142
|
+
* {
|
|
143
|
+
* include: {
|
|
144
|
+
* id: "movie-123",
|
|
145
|
+
* }
|
|
146
|
+
* }
|
|
147
|
+
* ```
|
|
148
|
+
* To remove vectors for all _movies_:
|
|
149
|
+
* ```js
|
|
150
|
+
* {
|
|
151
|
+
* include: {
|
|
152
|
+
* type: "movie",
|
|
153
|
+
* }
|
|
154
|
+
* }
|
|
155
|
+
* ```
|
|
156
|
+
*/
|
|
157
|
+
include: Record<string, any>;
|
|
158
|
+
}
|
|
159
|
+
export interface QueryResponse {
|
|
160
|
+
/**
|
|
161
|
+
* List of results matching the query.
|
|
162
|
+
*/
|
|
163
|
+
results: {
|
|
164
|
+
/**
|
|
165
|
+
* Metadata for the event that was provided when storing the vector.
|
|
166
|
+
*/
|
|
167
|
+
metadata: Record<string, any>;
|
|
168
|
+
/**
|
|
169
|
+
* The similarity score between the prompt and the queried vector.
|
|
170
|
+
*/
|
|
171
|
+
score: number;
|
|
172
|
+
}[];
|
|
173
|
+
}
|
|
174
|
+
export interface VectorClientResponse {
|
|
175
|
+
/**
|
|
176
|
+
* Store a vector into the database.
|
|
177
|
+
* @example
|
|
178
|
+
* ```ts title="src/lambda.ts"
|
|
179
|
+
* await client.put({
|
|
180
|
+
* vector: [32.4, 6.55, 11.2, 10.3, 87.9],
|
|
181
|
+
* metadata: { type: "movie", genre: "comedy" },
|
|
182
|
+
* });
|
|
183
|
+
* ```
|
|
184
|
+
*/
|
|
185
|
+
put: (event: PutEvent) => Promise<void>;
|
|
186
|
+
/**
|
|
187
|
+
* Query vectors that are similar to the given vector
|
|
188
|
+
* @example
|
|
189
|
+
* ```ts title="src/lambda.ts"
|
|
190
|
+
* const result = await client.query({
|
|
191
|
+
* vector: [32.4, 6.55, 11.2, 10.3, 87.9],
|
|
192
|
+
* include: { type: "movie" },
|
|
193
|
+
* exclude: { genre: "thriller" },
|
|
194
|
+
* });
|
|
195
|
+
* ```
|
|
196
|
+
*/
|
|
197
|
+
query: (event: QueryEvent) => Promise<QueryResponse>;
|
|
198
|
+
/**
|
|
199
|
+
* Remove vectors from the database.
|
|
200
|
+
* @example
|
|
201
|
+
* ```ts title="src/lambda.ts"
|
|
202
|
+
* await client.remove({
|
|
203
|
+
* include: { type: "movie" },
|
|
204
|
+
* });
|
|
205
|
+
* ```
|
|
206
|
+
*/
|
|
207
|
+
remove: (event: RemoveEvent) => Promise<void>;
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Create a client to interact with the Vector database.
|
|
211
|
+
* @example
|
|
212
|
+
* ```ts title="src/lambda.ts"
|
|
213
|
+
* import { VectorClient } from "sst";
|
|
214
|
+
* const client = VectorClient("MyVectorDB");
|
|
215
|
+
* ```
|
|
216
|
+
*
|
|
217
|
+
* Store a vector into the db
|
|
218
|
+
*
|
|
219
|
+
* ```ts title="src/lambda.ts"
|
|
220
|
+
* await client.put({
|
|
221
|
+
* vector: [32.4, 6.55, 11.2, 10.3, 87.9],
|
|
222
|
+
* metadata: { type: "movie", genre: "comedy" },
|
|
223
|
+
* });
|
|
224
|
+
* ```
|
|
225
|
+
*
|
|
226
|
+
* Query vectors that are similar to the given vector
|
|
227
|
+
*
|
|
228
|
+
* ```ts title="src/lambda.ts"
|
|
229
|
+
* const result = await client.query({
|
|
230
|
+
* vector: [32.4, 6.55, 11.2, 10.3, 87.9],
|
|
231
|
+
* include: { type: "movie" },
|
|
232
|
+
* exclude: { genre: "thriller" },
|
|
233
|
+
* });
|
|
234
|
+
* ```
|
|
235
|
+
*/
|
|
236
|
+
export declare function VectorClient<T extends keyof {
|
|
237
|
+
[key in keyof Resource as "sst.aws.Vector" extends Resource[key]["type"] ? string extends key ? never : key : never]: Resource[key];
|
|
238
|
+
}>(name: T): VectorClientResponse;
|
|
@@ -0,0 +1,68 @@
|
|
|
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
|
+
* ```ts title="src/lambda.ts"
|
|
8
|
+
* import { VectorClient } from "sst";
|
|
9
|
+
* const client = VectorClient("MyVectorDB");
|
|
10
|
+
* ```
|
|
11
|
+
*
|
|
12
|
+
* Store a vector into the db
|
|
13
|
+
*
|
|
14
|
+
* ```ts title="src/lambda.ts"
|
|
15
|
+
* await client.put({
|
|
16
|
+
* vector: [32.4, 6.55, 11.2, 10.3, 87.9],
|
|
17
|
+
* metadata: { type: "movie", genre: "comedy" },
|
|
18
|
+
* });
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* Query vectors that are similar to the given vector
|
|
22
|
+
*
|
|
23
|
+
* ```ts title="src/lambda.ts"
|
|
24
|
+
* const result = await client.query({
|
|
25
|
+
* vector: [32.4, 6.55, 11.2, 10.3, 87.9],
|
|
26
|
+
* include: { type: "movie" },
|
|
27
|
+
* exclude: { genre: "thriller" },
|
|
28
|
+
* });
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export function VectorClient(name) {
|
|
32
|
+
return {
|
|
33
|
+
put: async (event) => {
|
|
34
|
+
const ret = await lambda.send(new InvokeCommand({
|
|
35
|
+
// @ts-expect-error
|
|
36
|
+
FunctionName: Resource[name].putFunction,
|
|
37
|
+
Payload: JSON.stringify(event),
|
|
38
|
+
}));
|
|
39
|
+
parsePayload(ret, "Failed to store into the vector db");
|
|
40
|
+
},
|
|
41
|
+
query: async (event) => {
|
|
42
|
+
const ret = await lambda.send(new InvokeCommand({
|
|
43
|
+
// @ts-expect-error
|
|
44
|
+
FunctionName: Resource[name].queryFunction,
|
|
45
|
+
Payload: JSON.stringify(event),
|
|
46
|
+
}));
|
|
47
|
+
return parsePayload(ret, "Failed to query the vector db");
|
|
48
|
+
},
|
|
49
|
+
remove: async (event) => {
|
|
50
|
+
const ret = await lambda.send(new InvokeCommand({
|
|
51
|
+
// @ts-expect-error
|
|
52
|
+
FunctionName: Resource[name].removeFunction,
|
|
53
|
+
Payload: JSON.stringify(event),
|
|
54
|
+
}));
|
|
55
|
+
parsePayload(ret, "Failed to remove from the vector db");
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
function parsePayload(output, message) {
|
|
60
|
+
const payload = JSON.parse(Buffer.from(output.Payload).toString());
|
|
61
|
+
// Set cause to the payload so that it can be logged in CloudWatch
|
|
62
|
+
if (output.FunctionError) {
|
|
63
|
+
const e = new Error(message);
|
|
64
|
+
e.cause = payload;
|
|
65
|
+
throw e;
|
|
66
|
+
}
|
|
67
|
+
return payload;
|
|
68
|
+
}
|
package/package.json
CHANGED
|
@@ -2,26 +2,61 @@
|
|
|
2
2
|
"$schema": "https://json.schemastore.org/package.json",
|
|
3
3
|
"name": "sst",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"
|
|
5
|
+
"sideEffects": false,
|
|
6
|
+
"version": "3.0.1",
|
|
6
7
|
"main": "./dist/index.js",
|
|
7
8
|
"exports": {
|
|
8
9
|
".": "./dist/index.js",
|
|
10
|
+
"./auth": "./dist/auth/index.js",
|
|
11
|
+
"./auth/adapter": "./dist/auth/adapter/index.js",
|
|
12
|
+
"./event": "./dist/event/index.js",
|
|
13
|
+
"./realtime": "./dist/realtime/index.js",
|
|
9
14
|
"./*": "./dist/*.js"
|
|
10
15
|
},
|
|
16
|
+
"scripts": {
|
|
17
|
+
"build": "tsc",
|
|
18
|
+
"dev": "tsc -w",
|
|
19
|
+
"release": "./scripts/release.ts"
|
|
20
|
+
},
|
|
11
21
|
"devDependencies": {
|
|
12
|
-
"@tsconfig/
|
|
13
|
-
"@types/
|
|
14
|
-
"
|
|
22
|
+
"@tsconfig/node20": "20.1.4",
|
|
23
|
+
"@types/bun": "^1.1.6",
|
|
24
|
+
"@types/node": "20.11.0",
|
|
25
|
+
"hono": "4.3.9",
|
|
26
|
+
"typescript": "5.3.3",
|
|
27
|
+
"valibot": "0.30.0",
|
|
28
|
+
"zod": "3.23.8"
|
|
15
29
|
},
|
|
16
30
|
"files": [
|
|
17
|
-
"dist"
|
|
31
|
+
"dist",
|
|
32
|
+
"bin"
|
|
18
33
|
],
|
|
19
|
-
"
|
|
20
|
-
"
|
|
34
|
+
"bin": {
|
|
35
|
+
"sst": "./bin/sst.mjs"
|
|
21
36
|
},
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
|
|
37
|
+
"peerDependencies": {
|
|
38
|
+
"hono": "4.x",
|
|
39
|
+
"valibot": "0.30.x"
|
|
40
|
+
},
|
|
41
|
+
"peerDependenciesMeta": {
|
|
42
|
+
"hono": {
|
|
43
|
+
"optional": true
|
|
44
|
+
},
|
|
45
|
+
"valibot": {
|
|
46
|
+
"optional": true
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
"optionalDependencies": {
|
|
50
|
+
"sst-linux-x64": "3.0.1",
|
|
51
|
+
"sst-linux-x86": "3.0.1",
|
|
52
|
+
"sst-linux-arm64": "3.0.1",
|
|
53
|
+
"sst-darwin-x64": "3.0.1",
|
|
54
|
+
"sst-darwin-arm64": "3.0.1"
|
|
55
|
+
},
|
|
56
|
+
"dependencies": {
|
|
57
|
+
"@aws-sdk/client-lambda": "3.478.0",
|
|
58
|
+
"aws4fetch": "^1.0.18",
|
|
59
|
+
"jose": "5.2.3",
|
|
60
|
+
"openid-client": "5.6.4"
|
|
26
61
|
}
|
|
27
62
|
}
|