@dxos/functions 0.6.13 → 0.6.14-main.2b6a0f3
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/{chunk-CRAAIWU6.mjs → chunk-MT5Y7S4J.mjs} +28 -14
- package/dist/lib/browser/chunk-MT5Y7S4J.mjs.map +7 -0
- package/dist/lib/browser/{chunk-2I75VGHZ.mjs → chunk-MWJ54RSV.mjs} +16 -5
- package/dist/lib/browser/chunk-MWJ54RSV.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +7 -5
- package/dist/lib/browser/index.mjs.map +2 -2
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +9 -9
- package/dist/lib/browser/testing/index.mjs.map +3 -3
- package/dist/lib/browser/types.mjs +1 -1
- package/dist/lib/node/{chunk-OGLDVNFE.cjs → chunk-DRSTXWDN.cjs} +42 -37
- package/dist/lib/node/chunk-DRSTXWDN.cjs.map +7 -0
- package/dist/lib/node/{chunk-JV3VNH5X.cjs → chunk-O44VB3FE.cjs} +19 -8
- package/dist/lib/node/chunk-O44VB3FE.cjs.map +7 -0
- package/dist/lib/node/index.cjs +16 -14
- package/dist/lib/node/index.cjs.map +2 -2
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +15 -15
- package/dist/lib/node/testing/index.cjs.map +3 -3
- package/dist/lib/node/types.cjs +5 -5
- package/dist/lib/node/types.cjs.map +1 -1
- package/dist/lib/node-esm/chunk-5XEGOLMM.mjs +604 -0
- package/dist/lib/node-esm/chunk-5XEGOLMM.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-TJ4S5QZ3.mjs +90 -0
- package/dist/lib/node-esm/chunk-TJ4S5QZ3.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +94 -0
- package/dist/lib/node-esm/index.mjs.map +7 -0
- package/dist/lib/node-esm/meta.json +1 -0
- package/dist/lib/node-esm/testing/index.mjs +666 -0
- package/dist/lib/node-esm/testing/index.mjs.map +7 -0
- package/dist/lib/node-esm/types.mjs +14 -0
- package/dist/lib/node-esm/types.mjs.map +7 -0
- package/dist/types/src/handler.d.ts +2 -2
- package/dist/types/src/handler.d.ts.map +1 -1
- package/dist/types/src/testing/setup.d.ts.map +1 -1
- package/dist/types/src/trigger/type/websocket-trigger.d.ts +1 -0
- package/dist/types/src/trigger/type/websocket-trigger.d.ts.map +1 -1
- package/dist/types/src/types.d.ts +2 -2
- package/package.json +23 -18
- package/src/function/function-registry.test.ts +3 -2
- package/src/handler.ts +3 -2
- package/src/runtime/dev-server.test.ts +7 -6
- package/src/runtime/scheduler.test.ts +9 -6
- package/src/testing/functions-integration.test.ts +7 -5
- package/src/testing/setup.ts +10 -3
- package/src/trigger/trigger-registry.test.ts +3 -5
- package/src/trigger/type/websocket-trigger.ts +22 -6
- package/src/types.ts +4 -4
- package/dist/lib/browser/chunk-2I75VGHZ.mjs.map +0 -7
- package/dist/lib/browser/chunk-CRAAIWU6.mjs.map +0 -7
- package/dist/lib/node/chunk-JV3VNH5X.cjs.map +0 -7
- package/dist/lib/node/chunk-OGLDVNFE.cjs.map +0 -7
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
|
|
2
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
3
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
4
|
+
}) : x)(function(x) {
|
|
5
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
6
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
// packages/core/functions/src/types.ts
|
|
10
|
+
import { RawObject, S, TypedObject } from "@dxos/echo-schema";
|
|
11
|
+
var SubscriptionTriggerSchema = S.mutable(S.Struct({
|
|
12
|
+
type: S.Literal("subscription"),
|
|
13
|
+
// TODO(burdon): Define query DSL (from ECHO).
|
|
14
|
+
filter: S.Array(S.Struct({
|
|
15
|
+
type: S.String,
|
|
16
|
+
props: S.optional(S.Record({
|
|
17
|
+
key: S.String,
|
|
18
|
+
value: S.Any
|
|
19
|
+
}))
|
|
20
|
+
})),
|
|
21
|
+
options: S.optional(S.Struct({
|
|
22
|
+
// Watch changes to object (not just creation).
|
|
23
|
+
deep: S.optional(S.Boolean),
|
|
24
|
+
// Debounce changes (delay in ms).
|
|
25
|
+
delay: S.optional(S.Number)
|
|
26
|
+
}))
|
|
27
|
+
}));
|
|
28
|
+
var TimerTriggerSchema = S.mutable(S.Struct({
|
|
29
|
+
type: S.Literal("timer"),
|
|
30
|
+
cron: S.String
|
|
31
|
+
}));
|
|
32
|
+
var WebhookTriggerSchema = S.mutable(S.Struct({
|
|
33
|
+
type: S.Literal("webhook"),
|
|
34
|
+
method: S.String,
|
|
35
|
+
// Assigned port.
|
|
36
|
+
port: S.optional(S.Number)
|
|
37
|
+
}));
|
|
38
|
+
var WebsocketTriggerSchema = S.mutable(S.Struct({
|
|
39
|
+
type: S.Literal("websocket"),
|
|
40
|
+
url: S.String,
|
|
41
|
+
init: S.optional(S.Record({
|
|
42
|
+
key: S.String,
|
|
43
|
+
value: S.Any
|
|
44
|
+
}))
|
|
45
|
+
}));
|
|
46
|
+
var TriggerSpecSchema = S.Union(TimerTriggerSchema, WebhookTriggerSchema, WebsocketTriggerSchema, SubscriptionTriggerSchema);
|
|
47
|
+
var FunctionDef = class extends TypedObject({
|
|
48
|
+
typename: "dxos.org/type/FunctionDef",
|
|
49
|
+
version: "0.1.0"
|
|
50
|
+
})({
|
|
51
|
+
uri: S.String,
|
|
52
|
+
description: S.optional(S.String),
|
|
53
|
+
route: S.String,
|
|
54
|
+
handler: S.String
|
|
55
|
+
}) {
|
|
56
|
+
};
|
|
57
|
+
var FunctionTrigger = class extends TypedObject({
|
|
58
|
+
typename: "dxos.org/type/FunctionTrigger",
|
|
59
|
+
version: "0.1.0"
|
|
60
|
+
})({
|
|
61
|
+
name: S.optional(S.String),
|
|
62
|
+
enabled: S.optional(S.Boolean),
|
|
63
|
+
function: S.String.pipe(S.annotations({
|
|
64
|
+
description: "Function URI."
|
|
65
|
+
})),
|
|
66
|
+
// The `meta` property is merged into the event data passed to the function.
|
|
67
|
+
meta: S.optional(S.mutable(S.Record({
|
|
68
|
+
key: S.String,
|
|
69
|
+
value: S.Any
|
|
70
|
+
}))),
|
|
71
|
+
spec: TriggerSpecSchema
|
|
72
|
+
}) {
|
|
73
|
+
};
|
|
74
|
+
var FunctionManifestSchema = S.Struct({
|
|
75
|
+
functions: S.optional(S.mutable(S.Array(RawObject(FunctionDef)))),
|
|
76
|
+
triggers: S.optional(S.mutable(S.Array(RawObject(FunctionTrigger))))
|
|
77
|
+
});
|
|
78
|
+
var FUNCTION_SCHEMA = [
|
|
79
|
+
FunctionDef,
|
|
80
|
+
FunctionTrigger
|
|
81
|
+
];
|
|
82
|
+
|
|
83
|
+
export {
|
|
84
|
+
__require,
|
|
85
|
+
FunctionDef,
|
|
86
|
+
FunctionTrigger,
|
|
87
|
+
FunctionManifestSchema,
|
|
88
|
+
FUNCTION_SCHEMA
|
|
89
|
+
};
|
|
90
|
+
//# sourceMappingURL=chunk-TJ4S5QZ3.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/types.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { RawObject, S, TypedObject } from '@dxos/echo-schema';\n\n/**\n * Type discriminator for TriggerSpec.\n * Every spec has a type field of type FunctionTriggerType that we can use to understand which\n * type we're working with.\n * https://www.typescriptlang.org/docs/handbook/2/narrowing.html#discriminated-unions\n */\nexport type FunctionTriggerType = 'subscription' | 'timer' | 'webhook' | 'websocket';\n\nconst SubscriptionTriggerSchema = S.mutable(\n S.Struct({\n type: S.Literal('subscription'),\n // TODO(burdon): Define query DSL (from ECHO).\n filter: S.Array(\n S.Struct({\n type: S.String,\n props: S.optional(S.Record({ key: S.String, value: S.Any })),\n }),\n ),\n options: S.optional(\n S.Struct({\n // Watch changes to object (not just creation).\n deep: S.optional(S.Boolean),\n // Debounce changes (delay in ms).\n delay: S.optional(S.Number),\n }),\n ),\n }),\n);\n\nexport type SubscriptionTrigger = S.Schema.Type<typeof SubscriptionTriggerSchema>;\n\nconst TimerTriggerSchema = S.mutable(\n S.Struct({\n type: S.Literal('timer'),\n cron: S.String,\n }),\n);\n\nexport type TimerTrigger = S.Schema.Type<typeof TimerTriggerSchema>;\n\nconst WebhookTriggerSchema = S.mutable(\n S.Struct({\n type: S.Literal('webhook'),\n method: S.String,\n // Assigned port.\n port: S.optional(S.Number),\n }),\n);\n\nexport type WebhookTrigger = S.Schema.Type<typeof WebhookTriggerSchema>;\n\nconst WebsocketTriggerSchema = S.mutable(\n S.Struct({\n type: S.Literal('websocket'),\n url: S.String,\n init: S.optional(S.Record({ key: S.String, value: S.Any })),\n }),\n);\n\nexport type WebsocketTrigger = S.Schema.Type<typeof WebsocketTriggerSchema>;\n\nconst TriggerSpecSchema = S.Union(\n TimerTriggerSchema,\n WebhookTriggerSchema,\n WebsocketTriggerSchema,\n SubscriptionTriggerSchema,\n);\n\nexport type TriggerSpec = TimerTrigger | WebhookTrigger | WebsocketTrigger | SubscriptionTrigger;\n\n/**\n * Function definition.\n */\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 trigger.\n */\nexport class FunctionTrigger extends TypedObject({\n typename: 'dxos.org/type/FunctionTrigger',\n version: '0.1.0',\n})({\n name: S.optional(S.String),\n enabled: S.optional(S.Boolean),\n function: S.String.pipe(S.annotations({ description: 'Function URI.' })),\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 spec: TriggerSpecSchema,\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\n// TODO(burdon): Standards?\nexport const FUNCTION_SCHEMA = [FunctionDef, FunctionTrigger];\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;AAIA,SAASA,WAAWC,GAAGC,mBAAmB;AAU1C,IAAMC,4BAA4BC,EAAEC,QAClCD,EAAEE,OAAO;EACPC,MAAMH,EAAEI,QAAQ,cAAA;;EAEhBC,QAAQL,EAAEM,MACRN,EAAEE,OAAO;IACPC,MAAMH,EAAEO;IACRC,OAAOR,EAAES,SAAST,EAAEU,OAAO;MAAEC,KAAKX,EAAEO;MAAQK,OAAOZ,EAAEa;IAAI,CAAA,CAAA;EAC3D,CAAA,CAAA;EAEFC,SAASd,EAAES,SACTT,EAAEE,OAAO;;IAEPa,MAAMf,EAAES,SAAST,EAAEgB,OAAO;;IAE1BC,OAAOjB,EAAES,SAAST,EAAEkB,MAAM;EAC5B,CAAA,CAAA;AAEJ,CAAA,CAAA;AAKF,IAAMC,qBAAqBnB,EAAEC,QAC3BD,EAAEE,OAAO;EACPC,MAAMH,EAAEI,QAAQ,OAAA;EAChBgB,MAAMpB,EAAEO;AACV,CAAA,CAAA;AAKF,IAAMc,uBAAuBrB,EAAEC,QAC7BD,EAAEE,OAAO;EACPC,MAAMH,EAAEI,QAAQ,SAAA;EAChBkB,QAAQtB,EAAEO;;EAEVgB,MAAMvB,EAAES,SAAST,EAAEkB,MAAM;AAC3B,CAAA,CAAA;AAKF,IAAMM,yBAAyBxB,EAAEC,QAC/BD,EAAEE,OAAO;EACPC,MAAMH,EAAEI,QAAQ,WAAA;EAChBqB,KAAKzB,EAAEO;EACPmB,MAAM1B,EAAES,SAAST,EAAEU,OAAO;IAAEC,KAAKX,EAAEO;IAAQK,OAAOZ,EAAEa;EAAI,CAAA,CAAA;AAC1D,CAAA,CAAA;AAKF,IAAMc,oBAAoB3B,EAAE4B,MAC1BT,oBACAE,sBACAG,wBACAzB,yBAAAA;AAQK,IAAM8B,cAAN,cAA0BC,YAAY;EAC3CC,UAAU;EACVC,SAAS;AACX,CAAA,EAAG;EACDC,KAAKjC,EAAEO;EACP2B,aAAalC,EAAES,SAAST,EAAEO,MAAM;EAChC4B,OAAOnC,EAAEO;EACT6B,SAASpC,EAAEO;AACb,CAAA,EAAA;AAAI;AAKG,IAAM8B,kBAAN,cAA8BP,YAAY;EAC/CC,UAAU;EACVC,SAAS;AACX,CAAA,EAAG;EACDM,MAAMtC,EAAES,SAAST,EAAEO,MAAM;EACzBgC,SAASvC,EAAES,SAAST,EAAEgB,OAAO;EAC7BwB,UAAUxC,EAAEO,OAAOkC,KAAKzC,EAAE0C,YAAY;IAAER,aAAa;EAAgB,CAAA,CAAA;;EAErES,MAAM3C,EAAES,SAAST,EAAEC,QAAQD,EAAEU,OAAO;IAAEC,KAAKX,EAAEO;IAAQK,OAAOZ,EAAEa;EAAI,CAAA,CAAA,CAAA;EAClE+B,MAAMjB;AACR,CAAA,EAAA;AAAI;AAKG,IAAMkB,yBAAyB7C,EAAEE,OAAO;EAC7C4C,WAAW9C,EAAES,SAAST,EAAEC,QAAQD,EAAEM,MAAMyC,UAAUlB,WAAAA,CAAAA,CAAAA,CAAAA;EAClDmB,UAAUhD,EAAES,SAAST,EAAEC,QAAQD,EAAEM,MAAMyC,UAAUV,eAAAA,CAAAA,CAAAA,CAAAA;AACnD,CAAA;AAKO,IAAMY,kBAAkB;EAACpB;EAAaQ;;",
|
|
6
|
+
"names": ["RawObject", "S", "TypedObject", "SubscriptionTriggerSchema", "S", "mutable", "Struct", "type", "Literal", "filter", "Array", "String", "props", "optional", "Record", "key", "value", "Any", "options", "deep", "Boolean", "delay", "Number", "TimerTriggerSchema", "cron", "WebhookTriggerSchema", "method", "port", "WebsocketTriggerSchema", "url", "init", "TriggerSpecSchema", "Union", "FunctionDef", "TypedObject", "typename", "version", "uri", "description", "route", "handler", "FunctionTrigger", "name", "enabled", "function", "pipe", "annotations", "meta", "spec", "FunctionManifestSchema", "functions", "RawObject", "triggers", "FUNCTION_SCHEMA"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
|
|
2
|
+
import {
|
|
3
|
+
FunctionRegistry,
|
|
4
|
+
TriggerRegistry,
|
|
5
|
+
createSubscriptionTrigger,
|
|
6
|
+
createTimerTrigger,
|
|
7
|
+
createWebSocket,
|
|
8
|
+
createWebsocketTrigger
|
|
9
|
+
} from "./chunk-5XEGOLMM.mjs";
|
|
10
|
+
import {
|
|
11
|
+
FUNCTION_SCHEMA,
|
|
12
|
+
FunctionDef,
|
|
13
|
+
FunctionManifestSchema,
|
|
14
|
+
FunctionTrigger
|
|
15
|
+
} from "./chunk-TJ4S5QZ3.mjs";
|
|
16
|
+
|
|
17
|
+
// packages/core/functions/src/handler.ts
|
|
18
|
+
import { PublicKey } from "@dxos/client";
|
|
19
|
+
import { log } from "@dxos/log";
|
|
20
|
+
import { nonNullable } from "@dxos/util";
|
|
21
|
+
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/core/functions/src/handler.ts";
|
|
22
|
+
var subscriptionHandler = (handler, types) => {
|
|
23
|
+
return async ({ event: { data }, context, response, ...rest }) => {
|
|
24
|
+
const { client } = context;
|
|
25
|
+
const space = data.spaceKey ? client.spaces.get(PublicKey.from(data.spaceKey)) : void 0;
|
|
26
|
+
if (!space) {
|
|
27
|
+
log.error("Invalid space", void 0, {
|
|
28
|
+
F: __dxlog_file,
|
|
29
|
+
L: 132,
|
|
30
|
+
S: void 0,
|
|
31
|
+
C: (f, a) => f(...a)
|
|
32
|
+
});
|
|
33
|
+
return response.status(500);
|
|
34
|
+
}
|
|
35
|
+
registerTypes(space, types);
|
|
36
|
+
const objects = space ? data.objects?.map((id) => space.db.getObjectById(id)).filter(nonNullable) : [];
|
|
37
|
+
if (!!data.spaceKey && !space) {
|
|
38
|
+
log.warn("invalid space", {
|
|
39
|
+
data
|
|
40
|
+
}, {
|
|
41
|
+
F: __dxlog_file,
|
|
42
|
+
L: 142,
|
|
43
|
+
S: void 0,
|
|
44
|
+
C: (f, a) => f(...a)
|
|
45
|
+
});
|
|
46
|
+
} else {
|
|
47
|
+
log.info("handler", {
|
|
48
|
+
space: space?.key.truncate(),
|
|
49
|
+
objects: objects?.length
|
|
50
|
+
}, {
|
|
51
|
+
F: __dxlog_file,
|
|
52
|
+
L: 144,
|
|
53
|
+
S: void 0,
|
|
54
|
+
C: (f, a) => f(...a)
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
return handler({
|
|
58
|
+
event: {
|
|
59
|
+
data: {
|
|
60
|
+
...data,
|
|
61
|
+
space,
|
|
62
|
+
objects
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
context,
|
|
66
|
+
response,
|
|
67
|
+
...rest
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
var registerTypes = (space, types = []) => {
|
|
72
|
+
const registry = space.db.graph.schemaRegistry;
|
|
73
|
+
for (const type of types) {
|
|
74
|
+
if (!registry.hasSchema(type)) {
|
|
75
|
+
registry.addSchema([
|
|
76
|
+
type
|
|
77
|
+
]);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
export {
|
|
82
|
+
FUNCTION_SCHEMA,
|
|
83
|
+
FunctionDef,
|
|
84
|
+
FunctionManifestSchema,
|
|
85
|
+
FunctionRegistry,
|
|
86
|
+
FunctionTrigger,
|
|
87
|
+
TriggerRegistry,
|
|
88
|
+
createSubscriptionTrigger,
|
|
89
|
+
createTimerTrigger,
|
|
90
|
+
createWebSocket,
|
|
91
|
+
createWebsocketTrigger,
|
|
92
|
+
subscriptionHandler
|
|
93
|
+
};
|
|
94
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/handler.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { type Schema as S } from '@effect/schema';\n\nimport { type Client, PublicKey } from '@dxos/client';\nimport { type Space, type SpaceId } from '@dxos/client/echo';\nimport type { CoreDatabase, EchoReactiveObject } from '@dxos/echo-db';\nimport { log } from '@dxos/log';\nimport { nonNullable } 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 = {}> = (params: {\n context: FunctionContext;\n event: FunctionEvent<TData, TMeta>;\n\n /**\n * @deprecated\n */\n response: FunctionResponse;\n}) => Promise<Response | FunctionResponse | void>;\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 */\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/**\n * Space interface available to functions.\n */\nexport interface SpaceAPI {\n get id(): SpaceId;\n get crud(): CoreDatabase;\n}\n\nconst __assertFunctionSpaceIsCompatibleWithTheClientSpace = () => {\n // eslint-disable-next-line unused-imports/no-unused-vars\n const y: SpaceAPI = {} as Space;\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?: EchoReactiveObject<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?.map<EchoReactiveObject<any> | undefined>((id) => space!.db.getObjectById(id)).filter(nonNullable)\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": ";;;;;;;;;;;;;;;;;AAMA,SAAsBA,iBAAiB;AAGvC,SAASC,WAAW;AACpB,SAASC,mBAAmB;;AAiHrB,IAAMC,sBAAsB,CACjCC,SACAC,UAAAA;AAEA,SAAO,OAAO,EAAEC,OAAO,EAAEC,KAAI,GAAIC,SAASC,UAAU,GAAGC,KAAAA,MAAM;AAC3D,UAAM,EAAEC,OAAM,IAAKH;AACnB,UAAMI,QAAQL,KAAKM,WAAWF,OAAOG,OAAOC,IAAIC,UAAUC,KAAKV,KAAKM,QAAQ,CAAA,IAAKK;AACjF,QAAI,CAACN,OAAO;AACVO,UAAIC,MAAM,iBAAA,QAAA;;;;;;AACV,aAAOX,SAASY,OAAO,GAAA;IACzB;AAEAC,kBAAcV,OAAOP,KAAAA;AACrB,UAAMkB,UAAUX,QACZL,KAAKgB,SAASC,IAAyC,CAACC,OAAOb,MAAOc,GAAGC,cAAcF,EAAAA,CAAAA,EAAKG,OAAOC,WAAAA,IACnG,CAAA;AAEJ,QAAI,CAAC,CAACtB,KAAKM,YAAY,CAACD,OAAO;AAC7BO,UAAIW,KAAK,iBAAiB;QAAEvB;MAAK,GAAA;;;;;;IACnC,OAAO;AACLY,UAAIY,KAAK,WAAW;QAAEnB,OAAOA,OAAOoB,IAAIC,SAAAA;QAAYV,SAASA,SAASW;MAAO,GAAA;;;;;;IAC/E;AAEA,WAAO9B,QAAQ;MAAEE,OAAO;QAAEC,MAAM;UAAE,GAAGA;UAAMK;UAAOW;QAAQ;MAAE;MAAGf;MAASC;MAAU,GAAGC;IAAK,CAAA;EAC5F;AACF;AAGA,IAAMY,gBAAgB,CAACV,OAAcP,QAAyB,CAAA,MAAE;AAC9D,QAAM8B,WAAWvB,MAAMc,GAAGU,MAAMC;AAChC,aAAWC,QAAQjC,OAAO;AACxB,QAAI,CAAC8B,SAASI,UAAUD,IAAAA,GAAO;AAC7BH,eAASK,UAAU;QAACF;OAAK;IAC3B;EACF;AACF;",
|
|
6
|
+
"names": ["PublicKey", "log", "nonNullable", "subscriptionHandler", "handler", "types", "event", "data", "context", "response", "rest", "client", "space", "spaceKey", "spaces", "get", "PublicKey", "from", "undefined", "log", "error", "status", "registerTypes", "objects", "map", "id", "db", "getObjectById", "filter", "nonNullable", "warn", "info", "key", "truncate", "length", "registry", "graph", "schemaRegistry", "type", "hasSchema", "addSchema"]
|
|
7
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"inputs":{"packages/core/functions/src/types.ts":{"bytes":10352,"imports":[{"path":"@dxos/echo-schema","kind":"import-statement","external":true}],"format":"esm"},"packages/core/functions/src/function/function-registry.ts":{"bytes":13004,"imports":[{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/client/echo","kind":"import-statement","external":true},{"path":"@dxos/context","kind":"import-statement","external":true},{"path":"@dxos/keys","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"packages/core/functions/src/types.ts","kind":"import-statement","original":"../types"}],"format":"esm"},"packages/core/functions/src/function/index.ts":{"bytes":529,"imports":[{"path":"packages/core/functions/src/function/function-registry.ts","kind":"import-statement","original":"./function-registry"}],"format":"esm"},"packages/core/functions/src/handler.ts":{"bytes":10610,"imports":[{"path":"@dxos/client","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"format":"esm"},"packages/core/functions/src/trigger/type/subscription-trigger.ts":{"bytes":10343,"imports":[{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/client/echo","kind":"import-statement","external":true},{"path":"@dxos/echo-db","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true}],"format":"esm"},"packages/core/functions/src/trigger/type/timer-trigger.ts":{"bytes":4173,"imports":[{"path":"cron","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true}],"format":"esm"},"packages/core/functions/src/trigger/type/websocket-trigger.ts":{"bytes":13341,"imports":[{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true}],"format":"esm"},"packages/core/functions/src/trigger/type/index.ts":{"bytes":864,"imports":[{"path":"packages/core/functions/src/trigger/type/subscription-trigger.ts","kind":"import-statement","original":"./subscription-trigger"},{"path":"packages/core/functions/src/trigger/type/timer-trigger.ts","kind":"import-statement","original":"./timer-trigger"},{"path":"packages/core/functions/src/trigger/type/websocket-trigger.ts","kind":"import-statement","original":"./websocket-trigger"}],"format":"esm"},"packages/core/functions/src/trigger/trigger-registry.ts":{"bytes":28453,"imports":[{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/client/echo","kind":"import-statement","external":true},{"path":"@dxos/context","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/keys","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"packages/core/functions/src/trigger/type/index.ts","kind":"import-statement","original":"./type"},{"path":"packages/core/functions/src/types.ts","kind":"import-statement","original":"../types"}],"format":"esm"},"packages/core/functions/src/trigger/index.ts":{"bytes":603,"imports":[{"path":"packages/core/functions/src/trigger/trigger-registry.ts","kind":"import-statement","original":"./trigger-registry"},{"path":"packages/core/functions/src/trigger/type/index.ts","kind":"import-statement","original":"./type"}],"format":"esm"},"packages/core/functions/src/index.ts":{"bytes":840,"imports":[{"path":"packages/core/functions/src/function/index.ts","kind":"import-statement","original":"./function"},{"path":"packages/core/functions/src/handler.ts","kind":"import-statement","original":"./handler"},{"path":"packages/core/functions/src/trigger/index.ts","kind":"import-statement","original":"./trigger"},{"path":"packages/core/functions/src/types.ts","kind":"import-statement","original":"./types"}],"format":"esm"},"packages/core/functions/src/testing/types.ts":{"bytes":1131,"imports":[{"path":"@dxos/echo-schema","kind":"import-statement","external":true}],"format":"esm"},"packages/core/functions/src/runtime/dev-server.ts":{"bytes":28958,"imports":[{"path":"express","kind":"import-statement","external":true},{"path":"get-port-please","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/context","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"packages/core/functions/src/runtime/scheduler.ts":{"bytes":21084,"imports":[{"path":"node:path","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/client/echo","kind":"import-statement","external":true},{"path":"@dxos/context","kind":"import-statement","external":true},{"path":"@dxos/echo-protocol","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true}],"format":"esm"},"packages/core/functions/src/runtime/index.ts":{"bytes":598,"imports":[{"path":"packages/core/functions/src/runtime/dev-server.ts","kind":"import-statement","original":"./dev-server"},{"path":"packages/core/functions/src/runtime/scheduler.ts","kind":"import-statement","original":"./scheduler"}],"format":"esm"},"packages/core/functions/src/testing/setup.ts":{"bytes":12707,"imports":[{"path":"get-port-please","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/client","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"packages/core/functions/src/testing/types.ts","kind":"import-statement","original":"./types"},{"path":"packages/core/functions/src/function/index.ts","kind":"import-statement","original":"../function"},{"path":"packages/core/functions/src/runtime/index.ts","kind":"import-statement","original":"../runtime"},{"path":"packages/core/functions/src/trigger/index.ts","kind":"import-statement","original":"../trigger"},{"path":"packages/core/functions/src/types.ts","kind":"import-statement","original":"../types"}],"format":"esm"},"packages/core/functions/src/testing/util.ts":{"bytes":4292,"imports":[{"path":"@dxos/client/echo","kind":"import-statement","external":true},{"path":"@dxos/client/testing","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/protocols/proto/dxos/client/services","kind":"import-statement","external":true},{"path":"packages/core/functions/src/types.ts","kind":"import-statement","original":"../types"}],"format":"esm"},"packages/core/functions/src/testing/manifest.ts":{"bytes":1139,"imports":[],"format":"esm"},"packages/core/functions/src/testing/index.ts":{"bytes":749,"imports":[{"path":"packages/core/functions/src/testing/setup.ts","kind":"import-statement","original":"./setup"},{"path":"packages/core/functions/src/testing/types.ts","kind":"import-statement","original":"./types"},{"path":"packages/core/functions/src/testing/util.ts","kind":"import-statement","original":"./util"},{"path":"packages/core/functions/src/testing/manifest.ts","kind":"import-statement","original":"./manifest"}],"format":"esm"}},"outputs":{"packages/core/functions/dist/lib/node-esm/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":5751},"packages/core/functions/dist/lib/node-esm/index.mjs":{"imports":[{"path":"packages/core/functions/dist/lib/node-esm/chunk-5XEGOLMM.mjs","kind":"import-statement"},{"path":"packages/core/functions/dist/lib/node-esm/chunk-TJ4S5QZ3.mjs","kind":"import-statement"},{"path":"@dxos/client","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"exports":["FUNCTION_SCHEMA","FunctionDef","FunctionManifestSchema","FunctionRegistry","FunctionTrigger","TriggerRegistry","createSubscriptionTrigger","createTimerTrigger","createWebSocket","createWebsocketTrigger","subscriptionHandler"],"entryPoint":"packages/core/functions/src/index.ts","inputs":{"packages/core/functions/src/index.ts":{"bytesInOutput":0},"packages/core/functions/src/handler.ts":{"bytesInOutput":1624}},"bytes":2334},"packages/core/functions/dist/lib/node-esm/testing/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":32237},"packages/core/functions/dist/lib/node-esm/testing/index.mjs":{"imports":[{"path":"packages/core/functions/dist/lib/node-esm/chunk-5XEGOLMM.mjs","kind":"import-statement"},{"path":"packages/core/functions/dist/lib/node-esm/chunk-TJ4S5QZ3.mjs","kind":"import-statement"},{"path":"get-port-please","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/client","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"express","kind":"import-statement","external":true},{"path":"get-port-please","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/context","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/client/echo","kind":"import-statement","external":true},{"path":"@dxos/context","kind":"import-statement","external":true},{"path":"@dxos/echo-protocol","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/client/echo","kind":"import-statement","external":true},{"path":"@dxos/client/testing","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/protocols/proto/dxos/client/services","kind":"import-statement","external":true}],"exports":["TestType","createFunctionRuntime","createInitializedClients","inviteMember","startFunctionsHost","testFunctionManifest","triggerWebhook"],"entryPoint":"packages/core/functions/src/testing/index.ts","inputs":{"packages/core/functions/src/testing/setup.ts":{"bytesInOutput":2775},"packages/core/functions/src/testing/types.ts":{"bytesInOutput":182},"packages/core/functions/src/runtime/dev-server.ts":{"bytesInOutput":7860},"packages/core/functions/src/runtime/scheduler.ts":{"bytesInOutput":5330},"packages/core/functions/src/testing/index.ts":{"bytesInOutput":0},"packages/core/functions/src/testing/util.ts":{"bytesInOutput":1051},"packages/core/functions/src/testing/manifest.ts":{"bytesInOutput":146}},"bytes":18147},"packages/core/functions/dist/lib/node-esm/chunk-5XEGOLMM.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":33089},"packages/core/functions/dist/lib/node-esm/chunk-5XEGOLMM.mjs":{"imports":[{"path":"packages/core/functions/dist/lib/node-esm/chunk-TJ4S5QZ3.mjs","kind":"import-statement"},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/client/echo","kind":"import-statement","external":true},{"path":"@dxos/context","kind":"import-statement","external":true},{"path":"@dxos/keys","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/client/echo","kind":"import-statement","external":true},{"path":"@dxos/echo-db","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"cron","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/client/echo","kind":"import-statement","external":true},{"path":"@dxos/context","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/keys","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"exports":["FunctionRegistry","TriggerRegistry","createSubscriptionTrigger","createTimerTrigger","createWebSocket","createWebsocketTrigger"],"inputs":{"packages/core/functions/src/function/function-registry.ts":{"bytesInOutput":3046},"packages/core/functions/src/trigger/type/subscription-trigger.ts":{"bytesInOutput":2008},"packages/core/functions/src/trigger/type/timer-trigger.ts":{"bytesInOutput":898},"packages/core/functions/src/trigger/type/websocket-trigger.ts":{"bytesInOutput":3491},"packages/core/functions/src/trigger/trigger-registry.ts":{"bytesInOutput":7421}},"bytes":17539},"packages/core/functions/dist/lib/node-esm/types.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":93},"packages/core/functions/dist/lib/node-esm/types.mjs":{"imports":[{"path":"packages/core/functions/dist/lib/node-esm/chunk-TJ4S5QZ3.mjs","kind":"import-statement"}],"exports":["FUNCTION_SCHEMA","FunctionDef","FunctionManifestSchema","FunctionTrigger"],"entryPoint":"packages/core/functions/src/types.ts","inputs":{},"bytes":335},"packages/core/functions/dist/lib/node-esm/chunk-TJ4S5QZ3.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":5699},"packages/core/functions/dist/lib/node-esm/chunk-TJ4S5QZ3.mjs":{"imports":[{"path":"@dxos/echo-schema","kind":"import-statement","external":true}],"exports":["FUNCTION_SCHEMA","FunctionDef","FunctionManifestSchema","FunctionTrigger","__require"],"inputs":{"packages/core/functions/src/types.ts":{"bytesInOutput":2005}},"bytes":2651}}}
|