@dxos/functions 0.7.5-main.499c70c → 0.7.5-main.5ae2ba8
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/lib/browser/bundler/index.mjs +239 -0
- package/dist/lib/browser/bundler/index.mjs.map +7 -0
- package/dist/lib/browser/{chunk-PKOLPTSC.mjs → chunk-IXJNRWJP.mjs} +53 -17
- package/dist/lib/browser/chunk-IXJNRWJP.mjs.map +7 -0
- package/dist/lib/browser/{chunk-BCNGUHHW.mjs → chunk-XLM3CJXO.mjs} +2 -2
- package/dist/lib/browser/{chunk-B3FGASHJ.mjs → chunk-YJEIETRB.mjs} +6 -3
- package/dist/lib/browser/{chunk-B3FGASHJ.mjs.map → chunk-YJEIETRB.mjs.map} +3 -3
- package/dist/lib/browser/edge/index.mjs +1 -1
- package/dist/lib/browser/index.mjs +24 -10
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +2 -2
- package/dist/lib/browser/types/index.mjs +1 -3
- package/dist/lib/node/bundler/index.cjs +261 -0
- package/dist/lib/node/bundler/index.cjs.map +7 -0
- package/dist/lib/node/{chunk-RYEY2RR2.cjs → chunk-MGCKR53Q.cjs} +54 -21
- package/dist/lib/node/chunk-MGCKR53Q.cjs.map +7 -0
- package/dist/lib/node/{chunk-ZDG466QT.cjs → chunk-MZMHE4DC.cjs} +9 -6
- package/dist/lib/node/{chunk-ZDG466QT.cjs.map → chunk-MZMHE4DC.cjs.map} +3 -3
- package/dist/lib/node/{chunk-UHWSNERM.cjs → chunk-TLSUCABH.cjs} +15 -15
- package/dist/lib/node/edge/index.cjs +8 -8
- package/dist/lib/node/edge/index.cjs.map +1 -1
- package/dist/lib/node/index.cjs +44 -29
- package/dist/lib/node/index.cjs.map +3 -3
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +7 -7
- package/dist/lib/node/types/index.cjs +10 -12
- package/dist/lib/node/types/index.cjs.map +2 -2
- package/dist/lib/node-esm/bundler/index.mjs +239 -0
- package/dist/lib/node-esm/bundler/index.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-TPGS4PIH.mjs → chunk-CKTHJQ7M.mjs} +2 -2
- package/dist/lib/node-esm/{chunk-2UWB6JYW.mjs → chunk-FCZGNRNF.mjs} +53 -17
- package/dist/lib/node-esm/chunk-FCZGNRNF.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-CN74WOTT.mjs → chunk-T2KBXTMR.mjs} +6 -3
- package/dist/lib/node-esm/{chunk-CN74WOTT.mjs.map → chunk-T2KBXTMR.mjs.map} +3 -3
- package/dist/lib/node-esm/edge/index.mjs +1 -1
- package/dist/lib/node-esm/index.mjs +24 -10
- package/dist/lib/node-esm/index.mjs.map +3 -3
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/testing/index.mjs +2 -2
- package/dist/lib/node-esm/types/index.mjs +1 -3
- package/dist/types/src/bundler/bundler.d.ts +51 -0
- package/dist/types/src/bundler/bundler.d.ts.map +1 -0
- package/dist/types/src/bundler/bundler.test.d.ts +2 -0
- package/dist/types/src/bundler/bundler.test.d.ts.map +1 -0
- package/dist/types/src/bundler/index.d.ts +2 -0
- package/dist/types/src/bundler/index.d.ts.map +1 -0
- package/dist/types/src/edge/functions.d.ts.map +1 -1
- package/dist/types/src/handler.d.ts +29 -4
- package/dist/types/src/handler.d.ts.map +1 -1
- package/dist/types/src/testing/types.d.ts +2 -2
- package/dist/types/src/types/index.d.ts +1 -0
- package/dist/types/src/types/index.d.ts.map +1 -1
- package/dist/types/src/types/schema.d.ts +20 -23
- package/dist/types/src/types/schema.d.ts.map +1 -1
- package/dist/types/src/types/trace.d.ts +103 -0
- package/dist/types/src/types/trace.d.ts.map +1 -0
- package/dist/types/src/types/types.d.ts +50 -9
- package/dist/types/src/types/types.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +33 -19
- package/src/bundler/bundler.test.ts +59 -0
- package/src/bundler/bundler.ts +264 -0
- package/src/bundler/index.ts +5 -0
- package/src/edge/functions.ts +5 -1
- package/src/handler.ts +58 -9
- package/src/trigger/trigger-registry.test.ts +3 -1
- package/src/types/index.ts +1 -0
- package/src/types/schema.ts +4 -6
- package/src/types/trace.ts +49 -0
- package/src/types/types.ts +19 -2
- package/dist/lib/browser/chunk-PKOLPTSC.mjs.map +0 -7
- package/dist/lib/node/chunk-RYEY2RR2.cjs.map +0 -7
- package/dist/lib/node-esm/chunk-2UWB6JYW.mjs.map +0 -7
- /package/dist/lib/browser/{chunk-BCNGUHHW.mjs.map → chunk-XLM3CJXO.mjs.map} +0 -0
- /package/dist/lib/node/{chunk-UHWSNERM.cjs.map → chunk-TLSUCABH.cjs.map} +0 -0
- /package/dist/lib/node-esm/{chunk-TPGS4PIH.mjs.map → chunk-CKTHJQ7M.mjs.map} +0 -0
|
@@ -16,8 +16,8 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var
|
|
20
|
-
__export(
|
|
19
|
+
var chunk_MGCKR53Q_exports = {};
|
|
20
|
+
__export(chunk_MGCKR53Q_exports, {
|
|
21
21
|
FUNCTION_TYPES: () => FUNCTION_TYPES,
|
|
22
22
|
FunctionDef: () => FunctionDef,
|
|
23
23
|
FunctionManifestSchema: () => FunctionManifestSchema,
|
|
@@ -25,31 +25,24 @@ __export(chunk_RYEY2RR2_exports, {
|
|
|
25
25
|
FunctionTriggerSchema: () => FunctionTriggerSchema,
|
|
26
26
|
FunctionType: () => FunctionType,
|
|
27
27
|
ScriptType: () => ScriptType,
|
|
28
|
-
TextType: () => TextType,
|
|
29
28
|
TriggerKind: () => TriggerKind,
|
|
30
29
|
TriggerSchema: () => TriggerSchema
|
|
31
30
|
});
|
|
32
|
-
module.exports = __toCommonJS(
|
|
31
|
+
module.exports = __toCommonJS(chunk_MGCKR53Q_exports);
|
|
33
32
|
var import_echo_schema = require("@dxos/echo-schema");
|
|
33
|
+
var import_schema = require("@dxos/schema");
|
|
34
34
|
var import_echo_schema2 = require("@dxos/echo-schema");
|
|
35
|
-
var
|
|
36
|
-
typename: "dxos.org/type/Text",
|
|
37
|
-
version: "0.1.0"
|
|
38
|
-
})({
|
|
39
|
-
content: import_echo_schema.S.String
|
|
40
|
-
}) {
|
|
41
|
-
};
|
|
35
|
+
var import_echo_schema3 = require("@dxos/echo-schema");
|
|
42
36
|
var ScriptType = class extends (0, import_echo_schema.TypedObject)({
|
|
43
37
|
typename: "dxos.org/type/Script",
|
|
44
38
|
version: "0.1.0"
|
|
45
39
|
})({
|
|
46
|
-
// TODO(burdon): Change to URI?
|
|
47
40
|
name: import_echo_schema.S.optional(import_echo_schema.S.String),
|
|
48
41
|
description: import_echo_schema.S.optional(import_echo_schema.S.String),
|
|
49
42
|
// TODO(burdon): Change to hash of deployed content.
|
|
50
43
|
// Whether source has changed since last deploy.
|
|
51
44
|
changed: import_echo_schema.S.optional(import_echo_schema.S.Boolean),
|
|
52
|
-
source: (0, import_echo_schema.Ref)(TextType)
|
|
45
|
+
source: (0, import_echo_schema.Ref)(import_schema.TextType)
|
|
53
46
|
}) {
|
|
54
47
|
};
|
|
55
48
|
var FunctionType = class extends (0, import_echo_schema.TypedObject)({
|
|
@@ -59,10 +52,12 @@ var FunctionType = class extends (0, import_echo_schema.TypedObject)({
|
|
|
59
52
|
// TODO(burdon): Rename to id/uri?
|
|
60
53
|
name: import_echo_schema.S.NonEmptyString,
|
|
61
54
|
version: import_echo_schema.S.String,
|
|
55
|
+
description: import_echo_schema.S.optional(import_echo_schema.S.String),
|
|
62
56
|
// Reference to a source script if it exists within ECHO.
|
|
63
57
|
// TODO(burdon): Don't ref ScriptType directly (core).
|
|
64
58
|
source: import_echo_schema.S.optional((0, import_echo_schema.Ref)(ScriptType)),
|
|
65
59
|
inputSchema: import_echo_schema.S.optional(import_echo_schema.JsonSchemaType),
|
|
60
|
+
outputSchema: import_echo_schema.S.optional(import_echo_schema.JsonSchemaType),
|
|
66
61
|
// Local binding to a function name.
|
|
67
62
|
binding: import_echo_schema.S.optional(import_echo_schema.S.String)
|
|
68
63
|
}) {
|
|
@@ -72,6 +67,8 @@ var TriggerKind;
|
|
|
72
67
|
TriggerKind2["Timer"] = "timer";
|
|
73
68
|
TriggerKind2["Webhook"] = "webhook";
|
|
74
69
|
TriggerKind2["Subscription"] = "subscription";
|
|
70
|
+
TriggerKind2["Email"] = "email";
|
|
71
|
+
TriggerKind2["Queue"] = "queue";
|
|
75
72
|
})(TriggerKind || (TriggerKind = {}));
|
|
76
73
|
var typeLiteralAnnotations = {
|
|
77
74
|
[import_echo_schema2.AST.TitleAnnotationId]: "Type"
|
|
@@ -85,6 +82,13 @@ var TimerTriggerSchema = import_echo_schema2.S.Struct({
|
|
|
85
82
|
]
|
|
86
83
|
})
|
|
87
84
|
}).pipe(import_echo_schema2.S.mutable);
|
|
85
|
+
var EmailTriggerSchema = import_echo_schema2.S.Struct({
|
|
86
|
+
type: import_echo_schema2.S.Literal("email").annotations(typeLiteralAnnotations)
|
|
87
|
+
}).pipe(import_echo_schema2.S.mutable);
|
|
88
|
+
var QueueTriggerSchema = import_echo_schema2.S.Struct({
|
|
89
|
+
type: import_echo_schema2.S.Literal("queue").annotations(typeLiteralAnnotations),
|
|
90
|
+
queue: import_echo_schema2.DXN
|
|
91
|
+
}).pipe(import_echo_schema2.S.mutable);
|
|
88
92
|
var WebhookTriggerSchema = import_echo_schema2.S.Struct({
|
|
89
93
|
type: import_echo_schema2.S.Literal("webhook").annotations(typeLiteralAnnotations),
|
|
90
94
|
method: import_echo_schema2.S.optional(import_echo_schema2.S.String.annotations({
|
|
@@ -126,16 +130,12 @@ var SubscriptionTriggerSchema = import_echo_schema2.S.Struct({
|
|
|
126
130
|
[import_echo_schema2.AST.TitleAnnotationId]: "Options"
|
|
127
131
|
}))
|
|
128
132
|
}).pipe(import_echo_schema2.S.mutable);
|
|
129
|
-
var TriggerSchema = import_echo_schema2.S.Union(
|
|
130
|
-
//
|
|
131
|
-
TimerTriggerSchema,
|
|
132
|
-
WebhookTriggerSchema,
|
|
133
|
-
SubscriptionTriggerSchema
|
|
134
|
-
).annotations({
|
|
133
|
+
var TriggerSchema = import_echo_schema2.S.Union(TimerTriggerSchema, WebhookTriggerSchema, SubscriptionTriggerSchema, EmailTriggerSchema, QueueTriggerSchema).annotations({
|
|
135
134
|
[import_echo_schema2.AST.TitleAnnotationId]: "Trigger"
|
|
136
135
|
});
|
|
137
136
|
var FunctionTriggerSchema = import_echo_schema2.S.Struct({
|
|
138
137
|
// TODO(burdon): What type does this reference.
|
|
138
|
+
// TODO(wittjosiah): This should probably be a Ref?
|
|
139
139
|
function: import_echo_schema2.S.optional(import_echo_schema2.S.String.annotations({
|
|
140
140
|
[import_echo_schema2.AST.TitleAnnotationId]: "Function"
|
|
141
141
|
})),
|
|
@@ -174,6 +174,40 @@ var FUNCTION_TYPES = [
|
|
|
174
174
|
FunctionDef,
|
|
175
175
|
FunctionTrigger
|
|
176
176
|
];
|
|
177
|
+
var InvocationTrace = import_echo_schema3.S.Struct({
|
|
178
|
+
id: import_echo_schema3.ObjectId,
|
|
179
|
+
/**
|
|
180
|
+
* Queue DXN for function/workflow invocation events.
|
|
181
|
+
*/
|
|
182
|
+
invocationTraceQueue: (0, import_echo_schema3.Ref)(import_echo_schema3.Expando),
|
|
183
|
+
/**
|
|
184
|
+
* DXN of the invoked function/workflow.
|
|
185
|
+
*/
|
|
186
|
+
invocationTarget: (0, import_echo_schema3.Ref)(import_echo_schema3.Expando),
|
|
187
|
+
/**
|
|
188
|
+
* Present for automatic invocations.
|
|
189
|
+
*/
|
|
190
|
+
trigger: import_echo_schema3.S.optional((0, import_echo_schema3.Ref)(FunctionTrigger))
|
|
191
|
+
}).pipe((0, import_echo_schema3.EchoObject)("dxos.org/type/InvocationTrace", "0.1.0"));
|
|
192
|
+
var TraceEventLog = import_echo_schema3.S.Struct({
|
|
193
|
+
timestampMs: import_echo_schema3.S.Number,
|
|
194
|
+
level: import_echo_schema3.S.String,
|
|
195
|
+
message: import_echo_schema3.S.String,
|
|
196
|
+
context: import_echo_schema3.S.optional(import_echo_schema3.S.Object)
|
|
197
|
+
});
|
|
198
|
+
var TraceEventException = import_echo_schema3.S.Struct({
|
|
199
|
+
timestampMs: import_echo_schema3.S.Number,
|
|
200
|
+
message: import_echo_schema3.S.String,
|
|
201
|
+
name: import_echo_schema3.S.String,
|
|
202
|
+
stack: import_echo_schema3.S.optional(import_echo_schema3.S.String)
|
|
203
|
+
});
|
|
204
|
+
var TraceEvent = import_echo_schema3.S.Struct({
|
|
205
|
+
id: import_echo_schema3.ObjectId,
|
|
206
|
+
outcome: import_echo_schema3.S.String,
|
|
207
|
+
truncated: import_echo_schema3.S.Boolean,
|
|
208
|
+
logs: import_echo_schema3.S.Array(TraceEventLog),
|
|
209
|
+
exceptions: import_echo_schema3.S.Array(TraceEventException)
|
|
210
|
+
}).pipe((0, import_echo_schema3.EchoObject)("dxos.org/type/TraceEvent", "0.1.0"));
|
|
177
211
|
// Annotate the CommonJS export names for ESM import in node:
|
|
178
212
|
0 && (module.exports = {
|
|
179
213
|
FUNCTION_TYPES,
|
|
@@ -183,8 +217,7 @@ var FUNCTION_TYPES = [
|
|
|
183
217
|
FunctionTriggerSchema,
|
|
184
218
|
FunctionType,
|
|
185
219
|
ScriptType,
|
|
186
|
-
TextType,
|
|
187
220
|
TriggerKind,
|
|
188
221
|
TriggerSchema
|
|
189
222
|
});
|
|
190
|
-
//# sourceMappingURL=chunk-
|
|
223
|
+
//# sourceMappingURL=chunk-MGCKR53Q.cjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/types/schema.ts", "../../../src/types/types.ts", "../../../src/types/trace.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport { JsonSchemaType, Ref, S, TypedObject } from '@dxos/echo-schema';\nimport { TextType } from '@dxos/schema';\n\n/**\n * Source script.\n */\nexport class ScriptType extends TypedObject({\n typename: 'dxos.org/type/Script',\n version: '0.1.0',\n})({\n name: S.optional(S.String),\n description: S.optional(S.String),\n // TODO(burdon): Change to hash of deployed content.\n // Whether source has changed since last deploy.\n changed: S.optional(S.Boolean),\n source: Ref(TextType),\n}) {}\n\n/**\n * Function deployment.\n */\n// TODO(burdon): Move to core/functions.\nexport class FunctionType extends TypedObject({\n typename: 'dxos.org/type/Function',\n version: '0.1.0',\n})({\n // TODO(burdon): Rename to id/uri?\n name: S.NonEmptyString,\n version: S.String,\n\n description: S.optional(S.String),\n\n // Reference to a source script if it exists within ECHO.\n // TODO(burdon): Don't ref ScriptType directly (core).\n source: S.optional(Ref(ScriptType)),\n\n inputSchema: S.optional(JsonSchemaType),\n outputSchema: S.optional(JsonSchemaType),\n\n // Local binding to a function name.\n binding: S.optional(S.String),\n}) {}\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { AST, OptionsAnnotationId, RawObject, S, TypedObject, DXN } from '@dxos/echo-schema';\n\n/**\n * Type discriminator for TriggerType.\n * Every spec has a type field of type TriggerKind that we can use to understand which type we're working with.\n * https://www.typescriptlang.org/docs/handbook/2/narrowing.html#discriminated-unions\n */\nexport enum TriggerKind {\n Timer = 'timer',\n Webhook = 'webhook',\n Subscription = 'subscription',\n Email = 'email',\n Queue = 'queue',\n}\n\n// TODO(burdon): Rename prop kind.\nconst typeLiteralAnnotations = { [AST.TitleAnnotationId]: 'Type' };\n\n/**\n * Cron timer.\n */\nconst TimerTriggerSchema = S.Struct({\n type: S.Literal(TriggerKind.Timer).annotations(typeLiteralAnnotations),\n cron: S.String.annotations({\n [AST.TitleAnnotationId]: 'Cron',\n [AST.ExamplesAnnotationId]: ['0 0 * * *'],\n }),\n}).pipe(S.mutable);\n\nexport type TimerTrigger = S.Schema.Type<typeof TimerTriggerSchema>;\n\nconst EmailTriggerSchema = S.Struct({\n type: S.Literal(TriggerKind.Email).annotations(typeLiteralAnnotations),\n}).pipe(S.mutable);\n\nexport type EmailTrigger = S.Schema.Type<typeof EmailTriggerSchema>;\n\nconst QueueTriggerSchema = S.Struct({\n type: S.Literal(TriggerKind.Queue).annotations(typeLiteralAnnotations),\n queue: DXN,\n}).pipe(S.mutable);\n\nexport type QueueTrigger = S.Schema.Type<typeof QueueTriggerSchema>;\n\n/**\n * Webhook.\n */\nconst WebhookTriggerSchema = S.Struct({\n type: S.Literal(TriggerKind.Webhook).annotations(typeLiteralAnnotations),\n method: S.optional(\n S.String.annotations({\n [AST.TitleAnnotationId]: 'Method',\n [OptionsAnnotationId]: ['GET', 'POST'],\n }),\n ),\n port: S.optional(\n S.Number.annotations({\n [AST.TitleAnnotationId]: 'Port',\n }),\n ),\n}).pipe(S.mutable);\n\nexport type WebhookTrigger = S.Schema.Type<typeof WebhookTriggerSchema>;\n\n// TODO(burdon): Use ECHO definition (from https://github.com/dxos/dxos/pull/8233).\nconst QuerySchema = S.Struct({\n type: S.optional(S.String.annotations({ [AST.TitleAnnotationId]: 'Type' })),\n props: S.optional(S.Record({ key: S.String, value: S.Any })),\n}).annotations({ [AST.TitleAnnotationId]: 'Query' });\n\n/**\n * Subscription.\n */\nconst SubscriptionTriggerSchema = S.Struct({\n type: S.Literal(TriggerKind.Subscription).annotations(typeLiteralAnnotations),\n // TODO(burdon): Define query DSL (from ECHO). Reconcile with Table.Query.\n filter: QuerySchema,\n options: S.optional(\n S.Struct({\n // Watch changes to object (not just creation).\n deep: S.optional(S.Boolean.annotations({ [AST.TitleAnnotationId]: 'Nested' })),\n // Debounce changes (delay in ms).\n delay: S.optional(S.Number.annotations({ [AST.TitleAnnotationId]: 'Delay' })),\n }).annotations({ [AST.TitleAnnotationId]: 'Options' }),\n ),\n}).pipe(S.mutable);\n\nexport type SubscriptionTrigger = S.Schema.Type<typeof SubscriptionTriggerSchema>;\n\n/**\n * Trigger schema (discriminated union).\n */\nexport const TriggerSchema = S.Union(\n TimerTriggerSchema,\n WebhookTriggerSchema,\n SubscriptionTriggerSchema,\n EmailTriggerSchema,\n QueueTriggerSchema,\n).annotations({\n [AST.TitleAnnotationId]: 'Trigger',\n});\n\nexport type TriggerType = S.Schema.Type<typeof TriggerSchema>;\n\n/**\n * Function trigger.\n */\nexport const FunctionTriggerSchema = S.Struct({\n // TODO(burdon): What type does this reference.\n // TODO(wittjosiah): This should probably be a Ref?\n function: S.optional(S.String.annotations({ [AST.TitleAnnotationId]: 'Function' })),\n\n enabled: S.optional(S.Boolean.annotations({ [AST.TitleAnnotationId]: 'Enabled' })),\n\n // TODO(burdon): Flatten entire schema.\n spec: S.optional(TriggerSchema),\n\n // TODO(burdon): Get meta from function.\n // The `meta` property is merged into the event data passed to the function.\n meta: S.optional(S.mutable(S.Record({ key: S.String, value: S.Any }))),\n});\n\nexport type FunctionTriggerType = S.Schema.Type<typeof FunctionTriggerSchema>;\n\n/**\n * Function trigger.\n */\nexport class FunctionTrigger extends TypedObject({\n typename: 'dxos.org/type/FunctionTrigger',\n version: '0.1.0',\n})(FunctionTriggerSchema.fields) {}\n\n/**\n * Function definition.\n * @deprecated (Use dxos.org/type/Function)\n */\n// TODO(burdon): Reconcile with FunctionType.\nexport class FunctionDef extends TypedObject({\n typename: 'dxos.org/type/FunctionDef',\n version: '0.1.0',\n})({\n uri: S.String,\n description: S.optional(S.String),\n route: S.String,\n handler: S.String,\n}) {}\n\n/**\n * Function manifest file.\n */\nexport const FunctionManifestSchema = S.Struct({\n functions: S.optional(S.mutable(S.Array(RawObject(FunctionDef)))),\n triggers: S.optional(S.mutable(S.Array(RawObject(FunctionTrigger)))),\n});\n\nexport type FunctionManifest = S.Schema.Type<typeof FunctionManifestSchema>;\n\nexport const FUNCTION_TYPES = [FunctionDef, FunctionTrigger];\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { EchoObject, Expando, ObjectId, Ref, S } from '@dxos/echo-schema';\n\nimport { FunctionTrigger } from './types';\n\nconst InvocationTrace = S.Struct({\n id: ObjectId,\n /**\n * Queue DXN for function/workflow invocation events.\n */\n invocationTraceQueue: Ref(Expando),\n /**\n * DXN of the invoked function/workflow.\n */\n invocationTarget: Ref(Expando),\n /**\n * Present for automatic invocations.\n */\n trigger: S.optional(Ref(FunctionTrigger)),\n}).pipe(EchoObject('dxos.org/type/InvocationTrace', '0.1.0'));\n\nexport type InvocationTraceEvent = S.Schema.Type<typeof InvocationTrace>;\n\nconst TraceEventLog = S.Struct({\n timestampMs: S.Number,\n level: S.String,\n message: S.String,\n context: S.optional(S.Object),\n});\n\nconst TraceEventException = S.Struct({\n timestampMs: S.Number,\n message: S.String,\n name: S.String,\n stack: S.optional(S.String),\n});\n\nconst TraceEvent = S.Struct({\n id: ObjectId,\n outcome: S.String,\n truncated: S.Boolean,\n logs: S.Array(TraceEventLog),\n exceptions: S.Array(TraceEventException),\n}).pipe(EchoObject('dxos.org/type/TraceEvent', '0.1.0'));\n\nexport type TraceEvent = S.Schema.Type<typeof TraceEvent>;\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,yBAAoD;AACpD,oBAAyB;ACDzB,IAAAA,sBAAyE;ACAzE,IAAAA,sBAAsD;AFM/C,IAAMC,aAAN,kBAAyBC,gCAAY;EAC1CC,UAAU;EACVC,SAAS;AACX,CAAA,EAAG;EACDC,MAAMC,qBAAEC,SAASD,qBAAEE,MAAM;EACzBC,aAAaH,qBAAEC,SAASD,qBAAEE,MAAM;;;EAGhCE,SAASJ,qBAAEC,SAASD,qBAAEK,OAAO;EAC7BC,YAAQC,wBAAIC,sBAAAA;AACd,CAAA,EAAA;AAAI;AAMG,IAAMC,eAAN,kBAA2Bb,gCAAY;EAC5CC,UAAU;EACVC,SAAS;AACX,CAAA,EAAG;;EAEDC,MAAMC,qBAAEU;EACRZ,SAASE,qBAAEE;EAEXC,aAAaH,qB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C,SAASD,oBAAAA,EAAE2B,QAAQ3B,oBAAAA,EAAE+D,UAAMC,+BAAUT,eAAAA,CAAAA,CAAAA,CAAAA;AACnD,CAAA;AAIO,IAAMW,iBAAiB;EAACT;EAAaF;;ACzJ5C,IAAMY,kBAAkBnE,oBAAAA,EAAEoB,OAAO;EAC/BgD,IAAIC;;;;EAIJC,0BAAsB/D,oBAAAA,KAAIgE,2BAAAA;;;;EAI1BC,sBAAkBjE,oBAAAA,KAAIgE,2BAAAA;;;;EAItBE,SAASzE,oBAAAA,EAAEC,aAASM,oBAAAA,KAAIgD,eAAAA,CAAAA;AAC1B,CAAA,EAAG7B,SAAKgD,gCAAW,iCAAiC,OAAA,CAAA;AAIpD,IAAMC,gBAAgB3E,oBAAAA,EAAEoB,OAAO;EAC7BwD,aAAa5E,oBAAAA,EAAEoC;EACfyC,OAAO7E,oBAAAA,EAAEE;EACT4E,SAAS9E,oBAAAA,EAAEE;EACX6E,SAAS/E,oBAAAA,EAAEC,SAASD,oBAAAA,EAAEgF,MAAM;AAC9B,CAAA;AAEA,IAAMC,sBAAsBjF,oBAAAA,EAAEoB,OAAO;EACnCwD,aAAa5E,oBAAAA,EAAEoC;EACf0C,SAAS9E,oBAAAA,EAAEE;EACXH,MAAMC,oBAAAA,EAAEE;EACRgF,OAAOlF,oBAAAA,EAAEC,SAASD,oBAAAA,EAAEE,MAAM;AAC5B,CAAA;AAEA,IAAMiF,aAAanF,oBAAAA,EAAEoB,OAAO;EAC1BgD,IAAIC;EACJe,SAASpF,oBAAAA,EAAEE;EACXmF,WAAWrF,oBAAAA,EAAEK;EACbiF,MAAMtF,oBAAAA,EAAE+D,MAAMY,aAAAA;EACdY,YAAYvF,oBAAAA,EAAE+D,MAAMkB,mBAAAA;AACtB,CAAA,EAAGvD,SAAKgD,gCAAW,4BAA4B,OAAA,CAAA;",
|
|
6
|
+
"names": ["import_echo_schema", "ScriptType", "TypedObject", "typename", "version", "name", "S", "optional", "String", "description", "changed", "Boolean", "source", "Ref", "TextType", "FunctionType", "NonEmptyString", "inputSchema", "JsonSchemaType", "outputSchema", "binding", "TriggerKind", "typeLiteralAnnotations", "AST", "TitleAnnotationId", "TimerTriggerSchema", "Struct", "type", "Literal", "annotations", "cron", "ExamplesAnnotationId", "pipe", "mutable", "EmailTriggerSchema", "QueueTriggerSchema", "queue", "DXN", "WebhookTriggerSchema", "method", "OptionsAnnotationId", "port", "Number", "QuerySchema", "props", "Record", "key", "value", "Any", "SubscriptionTriggerSchema", "filter", "options", "deep", "delay", "TriggerSchema", "Union", "FunctionTriggerSchema", "function", "enabled", "spec", "meta", "FunctionTrigger", "fields", "FunctionDef", "uri", "route", "handler", "FunctionManifestSchema", "functions", "Array", "RawObject", "triggers", "FUNCTION_TYPES", "InvocationTrace", "id", "ObjectId", "invocationTraceQueue", "Expando", "invocationTarget", "trigger", "EchoObject", "TraceEventLog", "timestampMs", "level", "message", "context", "Object", "TraceEventException", "stack", "TraceEvent", "outcome", "truncated", "logs", "exceptions"]
|
|
7
|
+
}
|
|
@@ -16,8 +16,8 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var
|
|
20
|
-
__export(
|
|
19
|
+
var chunk_MZMHE4DC_exports = {};
|
|
20
|
+
__export(chunk_MZMHE4DC_exports, {
|
|
21
21
|
FUNCTIONS_PRESET_META_KEY: () => FUNCTIONS_PRESET_META_KEY,
|
|
22
22
|
getInvocationUrl: () => getInvocationUrl,
|
|
23
23
|
getUserFunctionUrlInMetadata: () => getUserFunctionUrlInMetadata,
|
|
@@ -26,7 +26,7 @@ __export(chunk_ZDG466QT_exports, {
|
|
|
26
26
|
setUserFunctionUrlInMetadata: () => setUserFunctionUrlInMetadata,
|
|
27
27
|
uploadWorkerFunction: () => uploadWorkerFunction
|
|
28
28
|
});
|
|
29
|
-
module.exports = __toCommonJS(
|
|
29
|
+
module.exports = __toCommonJS(chunk_MZMHE4DC_exports);
|
|
30
30
|
var import_edge_client = require("@dxos/edge-client");
|
|
31
31
|
var import_invariant = require("@dxos/invariant");
|
|
32
32
|
var import_log = require("@dxos/log");
|
|
@@ -91,9 +91,12 @@ var getInvocationUrl = (functionUrl, edgeUrl, options = {}) => {
|
|
|
91
91
|
const url = new URL(`./${relativeUrl}`, baseUrl.toString());
|
|
92
92
|
options.spaceId && url.searchParams.set("spaceId", options.spaceId);
|
|
93
93
|
options.subjectId && url.searchParams.set("subjectId", options.subjectId);
|
|
94
|
-
url.protocol = "https";
|
|
94
|
+
url.protocol = isSecure(url.protocol) ? "https" : "http";
|
|
95
95
|
return url.toString();
|
|
96
96
|
};
|
|
97
|
+
var isSecure = (protocol) => {
|
|
98
|
+
return protocol === "https:" || protocol === "wss:";
|
|
99
|
+
};
|
|
97
100
|
var createEdgeIdentity = (client) => {
|
|
98
101
|
const identity = client.halo.identity.get();
|
|
99
102
|
const device = client.halo.device;
|
|
@@ -122,7 +125,7 @@ var incrementSemverPatch = (version) => {
|
|
|
122
125
|
const patchNum = Number(patch);
|
|
123
126
|
(0, import_invariant.invariant)(!Number.isNaN(patchNum), "Unexpected function version format.", {
|
|
124
127
|
F: __dxlog_file,
|
|
125
|
-
L:
|
|
128
|
+
L: 109,
|
|
126
129
|
S: void 0,
|
|
127
130
|
A: [
|
|
128
131
|
"!Number.isNaN(patchNum)",
|
|
@@ -148,4 +151,4 @@ var publicKeyToDid = (key) => {
|
|
|
148
151
|
setUserFunctionUrlInMetadata,
|
|
149
152
|
uploadWorkerFunction
|
|
150
153
|
});
|
|
151
|
-
//# sourceMappingURL=chunk-
|
|
154
|
+
//# sourceMappingURL=chunk-MZMHE4DC.cjs.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/edge/functions.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport { type DID } from 'iso-did/types';\n\nimport { type Client } from '@dxos/client';\nimport { type ObjectMeta } from '@dxos/echo-schema';\nimport { EdgeHttpClient, type EdgeIdentity } from '@dxos/edge-client';\nimport { invariant } from '@dxos/invariant';\nimport type { PublicKey, SpaceId } from '@dxos/keys';\nimport { log } from '@dxos/log';\nimport { type UploadFunctionResponseBody } from '@dxos/protocols';\n\n// TODO: use URL scheme for source?\nconst FUNCTIONS_META_KEY = 'dxos.org/service/function';\n\nexport const FUNCTIONS_PRESET_META_KEY = 'dxos.org/service/function-preset';\n\nexport type UploadWorkerArgs = {\n client: Client;\n name?: string;\n source: string;\n version: string;\n functionId?: string;\n spaceId: SpaceId;\n};\n\nexport const uploadWorkerFunction = async ({\n client,\n name,\n version,\n source,\n spaceId,\n functionId,\n}: UploadWorkerArgs): Promise<UploadFunctionResponseBody> => {\n const edgeUrl = client.config.values.runtime?.services?.edge?.url;\n invariant(edgeUrl, 'Edge is not configured.');\n const edgeClient = new EdgeHttpClient(edgeUrl);\n const edgeIdentity = createEdgeIdentity(client);\n edgeClient.setIdentity(edgeIdentity);\n const response = await edgeClient.uploadFunction({ spaceId, functionId }, { name, version, script: source });\n\n log('Uploaded', {\n functionId,\n source,\n name,\n identityKey: edgeIdentity.identityKey,\n response,\n });\n\n return response;\n};\n\nexport const getUserFunctionUrlInMetadata = (meta: ObjectMeta) => {\n return meta.keys.find((key) => key.source === FUNCTIONS_META_KEY)?.id;\n};\n\nexport const setUserFunctionUrlInMetadata = (meta: ObjectMeta, functionUrl: string) => {\n const key = meta.keys.find((key) => key.source === FUNCTIONS_META_KEY);\n if (key) {\n if (key.id !== functionUrl) {\n throw new Error('Metadata mismatch');\n }\n } else {\n meta.keys.push({ source: FUNCTIONS_META_KEY, id: functionUrl });\n }\n};\n\nexport const getInvocationUrl = (functionUrl: string, edgeUrl: string, options: InvocationOptions = {}) => {\n const baseUrl = new URL('functions/', edgeUrl);\n\n // Leading slashes cause the URL to be treated as an absolute path.\n const relativeUrl = functionUrl.replace(/^\\//, '');\n const url = new URL(`./${relativeUrl}`, baseUrl.toString());\n options.spaceId && url.searchParams.set('spaceId', options.spaceId);\n options.subjectId && url.searchParams.set('subjectId', options.subjectId);\n url.protocol = 'https';\n return url.toString();\n};\n\nconst createEdgeIdentity = (client: Client): EdgeIdentity => {\n const identity = client.halo.identity.get();\n const device = client.halo.device;\n if (!identity || !device) {\n throw new Error('Identity not available');\n }\n return {\n identityKey: identity.identityKey.toHex(),\n peerKey: device.deviceKey.toHex(),\n presentCredentials: async ({ challenge }) => {\n const identityService = client.services.services.IdentityService!;\n const authCredential = await identityService.createAuthCredential();\n return identityService.signPresentation({\n presentation: { credentials: [authCredential] },\n nonce: challenge,\n });\n },\n };\n};\n\nexport const incrementSemverPatch = (version: string): string => {\n const [major, minor, patch] = version.split('.');\n const patchNum = Number(patch);\n invariant(!Number.isNaN(patchNum), 'Unexpected function version format.');\n return [major, minor, String(patchNum + 1)].join('.');\n};\n\nexport const publicKeyToDid = (key: PublicKey): DID => {\n return `did:key:${key.toHex()}`;\n};\n\nexport type InvocationOptions = {\n spaceId?: SpaceId;\n subjectId?: string;\n};\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAQA,yBAAkD;AAClD,uBAA0B;AAE1B,iBAAoB;;AAIpB,IAAMA,qBAAqB;AAEpB,IAAMC,4BAA4B;AAWlC,IAAMC,uBAAuB,OAAO,EACzCC,QACAC,MACAC,SACAC,QACAC,SACAC,WAAU,MACO;AACjB,QAAMC,UAAUN,OAAOO,OAAOC,OAAOC,SAASC,UAAUC,MAAMC;AAC9DC,kCAAUP,SAAS,2BAAA;;;;;;;;;AACnB,QAAMQ,aAAa,IAAIC,kCAAeT,OAAAA;AACtC,QAAMU,eAAeC,mBAAmBjB,MAAAA;AACxCc,aAAWI,YAAYF,YAAAA;AACvB,QAAMG,WAAW,MAAML,WAAWM,eAAe;IAAEhB;IAASC;EAAW,GAAG;IAAEJ;IAAMC;IAASmB,QAAQlB;EAAO,CAAA;AAE1GmB,sBAAI,YAAY;IACdjB;IACAF;IACAF;IACAsB,aAAaP,aAAaO;IAC1BJ;EACF,GAAA;;;;;;AAEA,SAAOA;AACT;AAEO,IAAMK,+BAA+B,CAACC,SAAAA;AAC3C,SAAOA,KAAKC,KAAKC,KAAK,CAACC,QAAQA,IAAIzB,WAAWN,kBAAAA,GAAqBgC;AACrE;AAEO,IAAMC,+BAA+B,CAACL,MAAkBM,gBAAAA;AAC7D,QAAMH,MAAMH,KAAKC,KAAKC,KAAK,CAACC,SAAQA,KAAIzB,WAAWN,kBAAAA;AACnD,MAAI+B,KAAK;AACP,QAAIA,IAAIC,OAAOE,aAAa;AAC1B,YAAM,IAAIC,MAAM,mBAAA;IAClB;EACF,OAAO;AACLP,SAAKC,KAAKO,KAAK;MAAE9B,QAAQN;MAAoBgC,IAAIE;IAAY,CAAA;EAC/D;AACF;AAEO,IAAMG,mBAAmB,CAACH,aAAqBzB,SAAiB6B,UAA6B,CAAC,MAAC;AACpG,QAAMC,UAAU,IAAIC,IAAI,cAAc/B,OAAAA;AAGtC,QAAMgC,cAAcP,YAAYQ,QAAQ,OAAO,EAAA;AAC/C,QAAM3B,MAAM,IAAIyB,IAAI,KAAKC,WAAAA,IAAeF,QAAQI,SAAQ,CAAA;AACxDL,UAAQ/B,WAAWQ,IAAI6B,aAAaC,IAAI,WAAWP,QAAQ/B,OAAO;AAClE+B,UAAQQ,aAAa/B,IAAI6B,aAAaC,IAAI,aAAaP,QAAQQ,SAAS;AACxE/B,MAAIgC,
|
|
6
|
-
"names": ["FUNCTIONS_META_KEY", "FUNCTIONS_PRESET_META_KEY", "uploadWorkerFunction", "client", "name", "version", "source", "spaceId", "functionId", "edgeUrl", "config", "values", "runtime", "services", "edge", "url", "invariant", "edgeClient", "EdgeHttpClient", "edgeIdentity", "createEdgeIdentity", "setIdentity", "response", "uploadFunction", "script", "log", "identityKey", "getUserFunctionUrlInMetadata", "meta", "keys", "find", "key", "id", "setUserFunctionUrlInMetadata", "functionUrl", "Error", "push", "getInvocationUrl", "options", "baseUrl", "URL", "relativeUrl", "replace", "toString", "searchParams", "set", "subjectId", "protocol", "identity", "halo", "get", "device", "toHex", "peerKey", "deviceKey", "presentCredentials", "challenge", "identityService", "IdentityService", "authCredential", "createAuthCredential", "signPresentation", "presentation", "credentials", "nonce", "incrementSemverPatch", "major", "minor", "patch", "split", "patchNum", "Number", "isNaN", "String", "join", "publicKeyToDid"]
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport { type DID } from 'iso-did/types';\n\nimport { type Client } from '@dxos/client';\nimport { type ObjectMeta } from '@dxos/echo-schema';\nimport { EdgeHttpClient, type EdgeIdentity } from '@dxos/edge-client';\nimport { invariant } from '@dxos/invariant';\nimport type { PublicKey, SpaceId } from '@dxos/keys';\nimport { log } from '@dxos/log';\nimport { type UploadFunctionResponseBody } from '@dxos/protocols';\n\n// TODO: use URL scheme for source?\nconst FUNCTIONS_META_KEY = 'dxos.org/service/function';\n\nexport const FUNCTIONS_PRESET_META_KEY = 'dxos.org/service/function-preset';\n\nexport type UploadWorkerArgs = {\n client: Client;\n name?: string;\n source: string;\n version: string;\n functionId?: string;\n spaceId: SpaceId;\n};\n\nexport const uploadWorkerFunction = async ({\n client,\n name,\n version,\n source,\n spaceId,\n functionId,\n}: UploadWorkerArgs): Promise<UploadFunctionResponseBody> => {\n const edgeUrl = client.config.values.runtime?.services?.edge?.url;\n invariant(edgeUrl, 'Edge is not configured.');\n const edgeClient = new EdgeHttpClient(edgeUrl);\n const edgeIdentity = createEdgeIdentity(client);\n edgeClient.setIdentity(edgeIdentity);\n const response = await edgeClient.uploadFunction({ spaceId, functionId }, { name, version, script: source });\n\n log('Uploaded', {\n functionId,\n source,\n name,\n identityKey: edgeIdentity.identityKey,\n response,\n });\n\n return response;\n};\n\nexport const getUserFunctionUrlInMetadata = (meta: ObjectMeta) => {\n return meta.keys.find((key) => key.source === FUNCTIONS_META_KEY)?.id;\n};\n\nexport const setUserFunctionUrlInMetadata = (meta: ObjectMeta, functionUrl: string) => {\n const key = meta.keys.find((key) => key.source === FUNCTIONS_META_KEY);\n if (key) {\n if (key.id !== functionUrl) {\n throw new Error('Metadata mismatch');\n }\n } else {\n meta.keys.push({ source: FUNCTIONS_META_KEY, id: functionUrl });\n }\n};\n\nexport const getInvocationUrl = (functionUrl: string, edgeUrl: string, options: InvocationOptions = {}) => {\n const baseUrl = new URL('functions/', edgeUrl);\n\n // Leading slashes cause the URL to be treated as an absolute path.\n const relativeUrl = functionUrl.replace(/^\\//, '');\n const url = new URL(`./${relativeUrl}`, baseUrl.toString());\n options.spaceId && url.searchParams.set('spaceId', options.spaceId);\n options.subjectId && url.searchParams.set('subjectId', options.subjectId);\n url.protocol = isSecure(url.protocol) ? 'https' : 'http';\n return url.toString();\n};\n\nconst isSecure = (protocol: string) => {\n return protocol === 'https:' || protocol === 'wss:';\n};\n\nconst createEdgeIdentity = (client: Client): EdgeIdentity => {\n const identity = client.halo.identity.get();\n const device = client.halo.device;\n if (!identity || !device) {\n throw new Error('Identity not available');\n }\n return {\n identityKey: identity.identityKey.toHex(),\n peerKey: device.deviceKey.toHex(),\n presentCredentials: async ({ challenge }) => {\n const identityService = client.services.services.IdentityService!;\n const authCredential = await identityService.createAuthCredential();\n return identityService.signPresentation({\n presentation: { credentials: [authCredential] },\n nonce: challenge,\n });\n },\n };\n};\n\nexport const incrementSemverPatch = (version: string): string => {\n const [major, minor, patch] = version.split('.');\n const patchNum = Number(patch);\n invariant(!Number.isNaN(patchNum), 'Unexpected function version format.');\n return [major, minor, String(patchNum + 1)].join('.');\n};\n\nexport const publicKeyToDid = (key: PublicKey): DID => {\n return `did:key:${key.toHex()}`;\n};\n\nexport type InvocationOptions = {\n spaceId?: SpaceId;\n subjectId?: string;\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAQA,yBAAkD;AAClD,uBAA0B;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
|
+
"names": ["FUNCTIONS_META_KEY", "FUNCTIONS_PRESET_META_KEY", "uploadWorkerFunction", "client", "name", "version", "source", "spaceId", "functionId", "edgeUrl", "config", "values", "runtime", "services", "edge", "url", "invariant", "edgeClient", "EdgeHttpClient", "edgeIdentity", "createEdgeIdentity", "setIdentity", "response", "uploadFunction", "script", "log", "identityKey", "getUserFunctionUrlInMetadata", "meta", "keys", "find", "key", "id", "setUserFunctionUrlInMetadata", "functionUrl", "Error", "push", "getInvocationUrl", "options", "baseUrl", "URL", "relativeUrl", "replace", "toString", "searchParams", "set", "subjectId", "protocol", "isSecure", "identity", "halo", "get", "device", "toHex", "peerKey", "deviceKey", "presentCredentials", "challenge", "identityService", "IdentityService", "authCredential", "createAuthCredential", "signPresentation", "presentation", "credentials", "nonce", "incrementSemverPatch", "major", "minor", "patch", "split", "patchNum", "Number", "isNaN", "String", "join", "publicKeyToDid"]
|
|
7
7
|
}
|
|
@@ -16,15 +16,15 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var
|
|
20
|
-
__export(
|
|
19
|
+
var chunk_TLSUCABH_exports = {};
|
|
20
|
+
__export(chunk_TLSUCABH_exports, {
|
|
21
21
|
FunctionRegistry: () => FunctionRegistry,
|
|
22
22
|
TriggerRegistry: () => TriggerRegistry,
|
|
23
23
|
createSubscriptionTrigger: () => createSubscriptionTrigger,
|
|
24
24
|
createTimerTrigger: () => createTimerTrigger
|
|
25
25
|
});
|
|
26
|
-
module.exports = __toCommonJS(
|
|
27
|
-
var
|
|
26
|
+
module.exports = __toCommonJS(chunk_TLSUCABH_exports);
|
|
27
|
+
var import_chunk_MGCKR53Q = require("./chunk-MGCKR53Q.cjs");
|
|
28
28
|
var import_async = require("@dxos/async");
|
|
29
29
|
var import_echo = require("@dxos/client/echo");
|
|
30
30
|
var import_context = require("@dxos/context");
|
|
@@ -85,14 +85,14 @@ var FunctionRegistry = class extends import_context.Resource {
|
|
|
85
85
|
if (!functions?.length) {
|
|
86
86
|
return;
|
|
87
87
|
}
|
|
88
|
-
if (!space.db.graph.schemaRegistry.hasSchema(
|
|
88
|
+
if (!space.db.graph.schemaRegistry.hasSchema(import_chunk_MGCKR53Q.FunctionDef)) {
|
|
89
89
|
space.db.graph.schemaRegistry.addSchema([
|
|
90
|
-
|
|
90
|
+
import_chunk_MGCKR53Q.FunctionDef
|
|
91
91
|
]);
|
|
92
92
|
}
|
|
93
|
-
const { objects: existing } = await space.db.query(import_echo.Filter.schema(
|
|
93
|
+
const { objects: existing } = await space.db.query(import_echo.Filter.schema(import_chunk_MGCKR53Q.FunctionDef)).run();
|
|
94
94
|
const { added } = (0, import_util.diff)(existing, functions, (a, b) => a.uri === b.uri);
|
|
95
|
-
added.forEach((def) => space.db.add((0, import_echo.create)(
|
|
95
|
+
added.forEach((def) => space.db.add((0, import_echo.create)(import_chunk_MGCKR53Q.FunctionDef, def)));
|
|
96
96
|
if (added.length > 0) {
|
|
97
97
|
await space.db.flush({
|
|
98
98
|
indexes: true,
|
|
@@ -118,7 +118,7 @@ var FunctionRegistry = class extends import_context.Resource {
|
|
|
118
118
|
if (this._ctx.disposed) {
|
|
119
119
|
break;
|
|
120
120
|
}
|
|
121
|
-
this._ctx.onDispose(space.db.query(import_echo.Filter.schema(
|
|
121
|
+
this._ctx.onDispose(space.db.query(import_echo.Filter.schema(import_chunk_MGCKR53Q.FunctionDef)).subscribe(({ objects }) => {
|
|
122
122
|
const { added } = (0, import_util.diff)(registered, objects, (a, b) => a.uri === b.uri);
|
|
123
123
|
if (added.length > 0) {
|
|
124
124
|
registered.push(...added);
|
|
@@ -335,9 +335,9 @@ var TriggerRegistry = class extends import_context2.Resource {
|
|
|
335
335
|
if (!manifest.triggers?.length) {
|
|
336
336
|
return;
|
|
337
337
|
}
|
|
338
|
-
if (!space.db.graph.schemaRegistry.hasSchema(
|
|
338
|
+
if (!space.db.graph.schemaRegistry.hasSchema(import_chunk_MGCKR53Q.FunctionTrigger)) {
|
|
339
339
|
space.db.graph.schemaRegistry.addSchema([
|
|
340
|
-
|
|
340
|
+
import_chunk_MGCKR53Q.FunctionTrigger
|
|
341
341
|
]);
|
|
342
342
|
}
|
|
343
343
|
const manifestTriggers = manifest.triggers.map((trigger) => {
|
|
@@ -351,11 +351,11 @@ var TriggerRegistry = class extends import_context2.Resource {
|
|
|
351
351
|
].join(":"))
|
|
352
352
|
];
|
|
353
353
|
}
|
|
354
|
-
return (0, import_echo3.create)(
|
|
354
|
+
return (0, import_echo3.create)(import_chunk_MGCKR53Q.FunctionTrigger, trigger, {
|
|
355
355
|
keys
|
|
356
356
|
});
|
|
357
357
|
});
|
|
358
|
-
const { objects: existing } = await space.db.query(import_echo3.Filter.schema(
|
|
358
|
+
const { objects: existing } = await space.db.query(import_echo3.Filter.schema(import_chunk_MGCKR53Q.FunctionTrigger)).run();
|
|
359
359
|
const { added } = (0, import_util2.diff)(existing, manifestTriggers, import_echo3.compareForeignKeys);
|
|
360
360
|
added.forEach((trigger) => {
|
|
361
361
|
space.db.add(trigger);
|
|
@@ -390,7 +390,7 @@ var TriggerRegistry = class extends import_context2.Resource {
|
|
|
390
390
|
if (this._ctx.disposed) {
|
|
391
391
|
break;
|
|
392
392
|
}
|
|
393
|
-
this._ctx.onDispose(space.db.query(import_echo3.Filter.schema(
|
|
393
|
+
this._ctx.onDispose(space.db.query(import_echo3.Filter.schema(import_chunk_MGCKR53Q.FunctionTrigger)).subscribe(async ({ objects: current }) => {
|
|
394
394
|
import_log4.log.info("update", {
|
|
395
395
|
space: space.key,
|
|
396
396
|
registered: registered.length,
|
|
@@ -491,4 +491,4 @@ var TriggerRegistry = class extends import_context2.Resource {
|
|
|
491
491
|
createSubscriptionTrigger,
|
|
492
492
|
createTimerTrigger
|
|
493
493
|
});
|
|
494
|
-
//# sourceMappingURL=chunk-
|
|
494
|
+
//# sourceMappingURL=chunk-TLSUCABH.cjs.map
|
|
@@ -18,16 +18,16 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var edge_exports = {};
|
|
20
20
|
__export(edge_exports, {
|
|
21
|
-
FUNCTIONS_PRESET_META_KEY: () =>
|
|
22
|
-
getInvocationUrl: () =>
|
|
23
|
-
getUserFunctionUrlInMetadata: () =>
|
|
24
|
-
incrementSemverPatch: () =>
|
|
25
|
-
publicKeyToDid: () =>
|
|
26
|
-
setUserFunctionUrlInMetadata: () =>
|
|
27
|
-
uploadWorkerFunction: () =>
|
|
21
|
+
FUNCTIONS_PRESET_META_KEY: () => import_chunk_MZMHE4DC.FUNCTIONS_PRESET_META_KEY,
|
|
22
|
+
getInvocationUrl: () => import_chunk_MZMHE4DC.getInvocationUrl,
|
|
23
|
+
getUserFunctionUrlInMetadata: () => import_chunk_MZMHE4DC.getUserFunctionUrlInMetadata,
|
|
24
|
+
incrementSemverPatch: () => import_chunk_MZMHE4DC.incrementSemverPatch,
|
|
25
|
+
publicKeyToDid: () => import_chunk_MZMHE4DC.publicKeyToDid,
|
|
26
|
+
setUserFunctionUrlInMetadata: () => import_chunk_MZMHE4DC.setUserFunctionUrlInMetadata,
|
|
27
|
+
uploadWorkerFunction: () => import_chunk_MZMHE4DC.uploadWorkerFunction
|
|
28
28
|
});
|
|
29
29
|
module.exports = __toCommonJS(edge_exports);
|
|
30
|
-
var
|
|
30
|
+
var import_chunk_MZMHE4DC = require("../chunk-MZMHE4DC.cjs");
|
|
31
31
|
var import_chunk_JEQ2X3Z6 = require("../chunk-JEQ2X3Z6.cjs");
|
|
32
32
|
// Annotate the CommonJS export names for ESM import in node:
|
|
33
33
|
0 && (module.exports = {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["index.cjs"],
|
|
4
|
-
"sourcesContent": ["import {\n FUNCTIONS_PRESET_META_KEY,\n getInvocationUrl,\n getUserFunctionUrlInMetadata,\n incrementSemverPatch,\n publicKeyToDid,\n setUserFunctionUrlInMetadata,\n uploadWorkerFunction\n} from \"../chunk-
|
|
4
|
+
"sourcesContent": ["import {\n FUNCTIONS_PRESET_META_KEY,\n getInvocationUrl,\n getUserFunctionUrlInMetadata,\n incrementSemverPatch,\n publicKeyToDid,\n setUserFunctionUrlInMetadata,\n uploadWorkerFunction\n} from \"../chunk-MZMHE4DC.cjs\";\nimport \"../chunk-JEQ2X3Z6.cjs\";\nexport {\n FUNCTIONS_PRESET_META_KEY,\n getInvocationUrl,\n getUserFunctionUrlInMetadata,\n incrementSemverPatch,\n publicKeyToDid,\n setUserFunctionUrlInMetadata,\n uploadWorkerFunction\n};\n//# sourceMappingURL=index.cjs.map\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,4BAQO;AACP,4BAAO;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/lib/node/index.cjs
CHANGED
|
@@ -18,38 +18,53 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var node_exports = {};
|
|
20
20
|
__export(node_exports, {
|
|
21
|
-
FUNCTIONS_PRESET_META_KEY: () =>
|
|
22
|
-
FUNCTION_TYPES: () =>
|
|
23
|
-
FunctionDef: () =>
|
|
24
|
-
FunctionManifestSchema: () =>
|
|
25
|
-
FunctionRegistry: () =>
|
|
26
|
-
FunctionTrigger: () =>
|
|
27
|
-
FunctionTriggerSchema: () =>
|
|
28
|
-
FunctionType: () =>
|
|
29
|
-
ScriptType: () =>
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
getInvocationUrl: () =>
|
|
37
|
-
getUserFunctionUrlInMetadata: () =>
|
|
38
|
-
incrementSemverPatch: () =>
|
|
39
|
-
publicKeyToDid: () =>
|
|
40
|
-
setUserFunctionUrlInMetadata: () =>
|
|
21
|
+
FUNCTIONS_PRESET_META_KEY: () => import_chunk_MZMHE4DC.FUNCTIONS_PRESET_META_KEY,
|
|
22
|
+
FUNCTION_TYPES: () => import_chunk_MGCKR53Q.FUNCTION_TYPES,
|
|
23
|
+
FunctionDef: () => import_chunk_MGCKR53Q.FunctionDef,
|
|
24
|
+
FunctionManifestSchema: () => import_chunk_MGCKR53Q.FunctionManifestSchema,
|
|
25
|
+
FunctionRegistry: () => import_chunk_TLSUCABH.FunctionRegistry,
|
|
26
|
+
FunctionTrigger: () => import_chunk_MGCKR53Q.FunctionTrigger,
|
|
27
|
+
FunctionTriggerSchema: () => import_chunk_MGCKR53Q.FunctionTriggerSchema,
|
|
28
|
+
FunctionType: () => import_chunk_MGCKR53Q.FunctionType,
|
|
29
|
+
ScriptType: () => import_chunk_MGCKR53Q.ScriptType,
|
|
30
|
+
TriggerKind: () => import_chunk_MGCKR53Q.TriggerKind,
|
|
31
|
+
TriggerRegistry: () => import_chunk_TLSUCABH.TriggerRegistry,
|
|
32
|
+
TriggerSchema: () => import_chunk_MGCKR53Q.TriggerSchema,
|
|
33
|
+
createSubscriptionTrigger: () => import_chunk_TLSUCABH.createSubscriptionTrigger,
|
|
34
|
+
createTimerTrigger: () => import_chunk_TLSUCABH.createTimerTrigger,
|
|
35
|
+
defineFunction: () => defineFunction,
|
|
36
|
+
getInvocationUrl: () => import_chunk_MZMHE4DC.getInvocationUrl,
|
|
37
|
+
getUserFunctionUrlInMetadata: () => import_chunk_MZMHE4DC.getUserFunctionUrlInMetadata,
|
|
38
|
+
incrementSemverPatch: () => import_chunk_MZMHE4DC.incrementSemverPatch,
|
|
39
|
+
publicKeyToDid: () => import_chunk_MZMHE4DC.publicKeyToDid,
|
|
40
|
+
setUserFunctionUrlInMetadata: () => import_chunk_MZMHE4DC.setUserFunctionUrlInMetadata,
|
|
41
41
|
subscriptionHandler: () => subscriptionHandler,
|
|
42
|
-
uploadWorkerFunction: () =>
|
|
42
|
+
uploadWorkerFunction: () => import_chunk_MZMHE4DC.uploadWorkerFunction
|
|
43
43
|
});
|
|
44
44
|
module.exports = __toCommonJS(node_exports);
|
|
45
|
-
var
|
|
46
|
-
var
|
|
47
|
-
var
|
|
45
|
+
var import_chunk_MZMHE4DC = require("./chunk-MZMHE4DC.cjs");
|
|
46
|
+
var import_chunk_TLSUCABH = require("./chunk-TLSUCABH.cjs");
|
|
47
|
+
var import_chunk_MGCKR53Q = require("./chunk-MGCKR53Q.cjs");
|
|
48
48
|
var import_chunk_JEQ2X3Z6 = require("./chunk-JEQ2X3Z6.cjs");
|
|
49
|
+
var import_schema = require("@effect/schema");
|
|
49
50
|
var import_client = require("@dxos/client");
|
|
50
51
|
var import_log = require("@dxos/log");
|
|
51
52
|
var import_util = require("@dxos/util");
|
|
52
53
|
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/core/functions/src/handler.ts";
|
|
54
|
+
var defineFunction = (params) => {
|
|
55
|
+
if (!import_schema.Schema.isSchema(params.inputSchema)) {
|
|
56
|
+
throw new Error("Input schema must be a valid schema");
|
|
57
|
+
}
|
|
58
|
+
if (typeof params.handler !== "function") {
|
|
59
|
+
throw new Error("Handler must be a function");
|
|
60
|
+
}
|
|
61
|
+
return {
|
|
62
|
+
description: params.description,
|
|
63
|
+
inputSchema: params.inputSchema,
|
|
64
|
+
outputSchema: params.outputSchema ?? import_schema.Schema.Any,
|
|
65
|
+
handler: params.handler
|
|
66
|
+
};
|
|
67
|
+
};
|
|
53
68
|
var subscriptionHandler = (handler, types) => {
|
|
54
69
|
return async ({ event: { data }, context, response, ...rest }) => {
|
|
55
70
|
const { client } = context;
|
|
@@ -57,20 +72,20 @@ var subscriptionHandler = (handler, types) => {
|
|
|
57
72
|
if (!space) {
|
|
58
73
|
import_log.log.error("Invalid space", void 0, {
|
|
59
74
|
F: __dxlog_file,
|
|
60
|
-
L:
|
|
75
|
+
L: 179,
|
|
61
76
|
S: void 0,
|
|
62
77
|
C: (f, a) => f(...a)
|
|
63
78
|
});
|
|
64
79
|
return response.status(500);
|
|
65
80
|
}
|
|
66
81
|
registerTypes(space, types);
|
|
67
|
-
const objects = space ? data.objects?.map((id) => space.db.getObjectById(id)).filter(import_util.
|
|
82
|
+
const objects = space ? data.objects?.map((id) => space.db.getObjectById(id)).filter(import_util.isNonNullable) : [];
|
|
68
83
|
if (!!data.spaceKey && !space) {
|
|
69
84
|
import_log.log.warn("invalid space", {
|
|
70
85
|
data
|
|
71
86
|
}, {
|
|
72
87
|
F: __dxlog_file,
|
|
73
|
-
L:
|
|
88
|
+
L: 191,
|
|
74
89
|
S: void 0,
|
|
75
90
|
C: (f, a) => f(...a)
|
|
76
91
|
});
|
|
@@ -80,7 +95,7 @@ var subscriptionHandler = (handler, types) => {
|
|
|
80
95
|
objects: objects?.length
|
|
81
96
|
}, {
|
|
82
97
|
F: __dxlog_file,
|
|
83
|
-
L:
|
|
98
|
+
L: 193,
|
|
84
99
|
S: void 0,
|
|
85
100
|
C: (f, a) => f(...a)
|
|
86
101
|
});
|
|
@@ -120,12 +135,12 @@ var registerTypes = (space, types = []) => {
|
|
|
120
135
|
FunctionTriggerSchema,
|
|
121
136
|
FunctionType,
|
|
122
137
|
ScriptType,
|
|
123
|
-
TextType,
|
|
124
138
|
TriggerKind,
|
|
125
139
|
TriggerRegistry,
|
|
126
140
|
TriggerSchema,
|
|
127
141
|
createSubscriptionTrigger,
|
|
128
142
|
createTimerTrigger,
|
|
143
|
+
defineFunction,
|
|
129
144
|
getInvocationUrl,
|
|
130
145
|
getUserFunctionUrlInMetadata,
|
|
131
146
|
incrementSemverPatch,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/handler.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport {
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
6
|
-
"names": ["
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { Schema as S } from '@effect/schema';\nimport { type Effect } from 'effect';\n\nimport { type Client, PublicKey } from '@dxos/client';\nimport { type Space, type SpaceId } from '@dxos/client/echo';\nimport type { CoreDatabase, EchoDatabase, QueryResult, ReactiveEchoObject } from '@dxos/echo-db';\nimport { type HasId } from '@dxos/echo-schema';\nimport { type DXN } from '@dxos/keys';\nimport { log } from '@dxos/log';\nimport { isNonNullable } from '@dxos/util';\n\n// TODO(burdon): Model after http request. Ref Lambda/OpenFaaS.\n// https://docs.aws.amazon.com/lambda/latest/dg/typescript-handler.html\n// https://www.serverless.com/framework/docs/providers/aws/guide/serverless.yml/#functions\n// https://www.npmjs.com/package/aws-lambda\n\n/**\n * Function handler.\n */\nexport type FunctionHandler<TData = {}, TMeta = {}, TOutput = any> = (params: {\n context: FunctionContext;\n event: FunctionEvent<TData, TMeta>;\n /**\n * @deprecated\n */\n response: FunctionResponse;\n}) => TOutput | Promise<TOutput> | Effect.Effect<TOutput, any>;\n\n/**\n * Function context.\n */\nexport interface FunctionContext {\n getSpace: (spaceId: SpaceId) => Promise<SpaceAPI>;\n\n /**\n * Space from which the function was invoked.\n */\n space: SpaceAPI | undefined;\n\n ai: FunctionContextAi;\n\n /**\n * @deprecated\n */\n // TODO(burdon): Limit access to individual space.\n client: Client;\n /**\n * @deprecated\n */\n // TODO(burdon): Replace with storage service abstraction.\n dataDir?: string;\n}\n\nexport interface FunctionContextAi {\n // TODO(dmaretskyi): Refer to cloudflare AI docs for more comprehensive typedefs.\n run(model: string, inputs: any, options?: any): Promise<any>;\n}\n\n/**\n * Event payload.\n */\n// TODO(dmaretskyi): Update type definitions to match the actual payload.\nexport type FunctionEvent<TData = {}, TMeta = {}> = {\n data: FunctionEventMeta<TMeta> & TData;\n};\n\n/**\n * Metadata from trigger.\n */\nexport type FunctionEventMeta<TMeta = {}> = {\n meta: TMeta;\n};\n\n/**\n * Function response.\n */\nexport type FunctionResponse = {\n status(code: number): FunctionResponse;\n};\n\n//\n// API.\n//\n\n// TODO(dmaretskyi): Temporary API to get the queues working.\n// TODO(dmaretskyi): To be replaced with integrating queues into echo.\nexport interface QueuesAPI {\n queryQueue(queue: DXN, options?: {}): Promise<QueryResult>;\n insertIntoQueue(queue: DXN, objects: HasId[]): Promise<void>;\n}\n\n/**\n * Space interface available to functions.\n */\nexport interface SpaceAPI {\n get id(): SpaceId;\n /**\n * @deprecated\n */\n get crud(): CoreDatabase;\n get db(): EchoDatabase;\n // TODO(dmaretskyi): Align with echo api --- queues.get(id).append(items);\n get queues(): QueuesAPI;\n}\n\n// TODO(wittjosiah): Fix this.\nconst __assertFunctionSpaceIsCompatibleWithTheClientSpace = () => {\n // const _: SpaceAPI = {} as Space;\n};\n\nexport type FunctionDefinition = {\n description?: string;\n inputSchema: S.Schema.AnyNoContext;\n outputSchema?: S.Schema.AnyNoContext;\n handler: FunctionHandler<any>;\n};\n\nexport type DefineFunctionParams<T, O = any> = {\n description?: string;\n inputSchema: S.Schema<T, any>;\n outputSchema?: S.Schema<O, any>;\n handler: FunctionHandler<T, any, O>;\n};\n\n// TODO(dmaretskyi): Bind input type to function handler.\nexport const defineFunction = <T, O>(params: DefineFunctionParams<T, O>): FunctionDefinition => {\n if (!S.isSchema(params.inputSchema)) {\n throw new Error('Input schema must be a valid schema');\n }\n if (typeof params.handler !== 'function') {\n throw new Error('Handler must be a function');\n }\n\n return {\n description: params.description,\n inputSchema: params.inputSchema,\n outputSchema: params.outputSchema ?? S.Any,\n handler: params.handler,\n };\n};\n\n//\n// Subscription utils.\n//\n\nexport type RawSubscriptionData = {\n spaceKey?: string;\n objects?: string[];\n};\n\nexport type SubscriptionData = {\n space?: Space;\n objects?: ReactiveEchoObject<any>[];\n};\n\n/**\n * Handler wrapper for subscription events; extracts space and objects.\n *\n * To test:\n * ```\n * curl -s -X POST -H \"Content-Type: application/json\" --data '{\"space\": \"0446...1cbb\"}' http://localhost:7100/dev/email-extractor\n * ```\n *\n * NOTE: Get space key from devtools or `dx space list --json`\n */\n// TODO(burdon): Evolve into plugin definition like Composer.\nexport const subscriptionHandler = <TMeta>(\n handler: FunctionHandler<SubscriptionData, TMeta>,\n types?: S.Schema<any>[],\n): FunctionHandler<RawSubscriptionData, TMeta> => {\n return async ({ event: { data }, context, response, ...rest }) => {\n const { client } = context;\n const space = data.spaceKey ? client.spaces.get(PublicKey.from(data.spaceKey)) : undefined;\n if (!space) {\n log.error('Invalid space');\n return response.status(500);\n }\n\n registerTypes(space, types);\n const objects = space\n ? data.objects\n ?.map<ReactiveEchoObject<any> | undefined>((id) => space!.db.getObjectById(id))\n .filter(isNonNullable)\n : [];\n\n if (!!data.spaceKey && !space) {\n log.warn('invalid space', { data });\n } else {\n log.info('handler', { space: space?.key.truncate(), objects: objects?.length });\n }\n\n return handler({ event: { data: { ...data, space, objects } }, context, response, ...rest });\n };\n};\n\n// TODO(burdon): Evolve types as part of function metadata.\nconst registerTypes = (space: Space, types: S.Schema<any>[] = []) => {\n const registry = space.db.graph.schemaRegistry;\n for (const type of types) {\n if (!registry.hasSchema(type)) {\n registry.addSchema([type]);\n }\n }\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,oBAA4B;AAG5B,oBAAuC;AAKvC,iBAAoB;AACpB,kBAA8B;;AAoHvB,IAAMA,iBAAiB,CAAOC,WAAAA;AACnC,MAAI,CAACC,cAAAA,OAAEC,SAASF,OAAOG,WAAW,GAAG;AACnC,UAAM,IAAIC,MAAM,qCAAA;EAClB;AACA,MAAI,OAAOJ,OAAOK,YAAY,YAAY;AACxC,UAAM,IAAID,MAAM,4BAAA;EAClB;AAEA,SAAO;IACLE,aAAaN,OAAOM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+
"names": ["defineFunction", "params", "S", "isSchema", "inputSchema", "Error", "handler", "description", "outputSchema", "Any", "subscriptionHandler", "types", "event", "data", "context", "response", "rest", "client", "space", "spaceKey", "spaces", "get", "PublicKey", "from", "undefined", "log", "error", "status", "registerTypes", "objects", "map", "id", "db", "getObjectById", "filter", "isNonNullable", "warn", "info", "key", "truncate", "length", "registry", "graph", "schemaRegistry", "type", "hasSchema", "addSchema"]
|
|
7
7
|
}
|