@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
|
@@ -2,7 +2,7 @@ import "@dxos/node-std/globals";
|
|
|
2
2
|
import {
|
|
3
3
|
FunctionDef,
|
|
4
4
|
FunctionTrigger
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-MWJ54RSV.mjs";
|
|
6
6
|
|
|
7
7
|
// packages/core/functions/src/function/function-registry.ts
|
|
8
8
|
import { Event } from "@dxos/async";
|
|
@@ -218,7 +218,6 @@ var createTimerTrigger = async (ctx, space, spec, callback) => {
|
|
|
218
218
|
};
|
|
219
219
|
|
|
220
220
|
// packages/core/functions/src/trigger/type/websocket-trigger.ts
|
|
221
|
-
import WebSocket from "ws";
|
|
222
221
|
import { sleep, Trigger } from "@dxos/async";
|
|
223
222
|
import { log as log4 } from "@dxos/log";
|
|
224
223
|
var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/core/functions/src/trigger/type/websocket-trigger.ts";
|
|
@@ -231,14 +230,14 @@ var createWebsocketTrigger = async (ctx, space, spec, callback, options = {
|
|
|
231
230
|
let ws;
|
|
232
231
|
for (let attempt = 1; attempt <= options.maxAttempts; attempt++) {
|
|
233
232
|
const open = new Trigger();
|
|
234
|
-
ws =
|
|
233
|
+
ws = await createWebSocket(url);
|
|
235
234
|
Object.assign(ws, {
|
|
236
235
|
onopen: () => {
|
|
237
236
|
log4.info("opened", {
|
|
238
237
|
url
|
|
239
238
|
}, {
|
|
240
239
|
F: __dxlog_file4,
|
|
241
|
-
L:
|
|
240
|
+
L: 39,
|
|
242
241
|
S: void 0,
|
|
243
242
|
C: (f, a) => f(...a)
|
|
244
243
|
});
|
|
@@ -253,7 +252,7 @@ var createWebsocketTrigger = async (ctx, space, spec, callback, options = {
|
|
|
253
252
|
code: event.code
|
|
254
253
|
}, {
|
|
255
254
|
F: __dxlog_file4,
|
|
256
|
-
L:
|
|
255
|
+
L: 48,
|
|
257
256
|
S: void 0,
|
|
258
257
|
C: (f, a) => f(...a)
|
|
259
258
|
});
|
|
@@ -263,7 +262,7 @@ var createWebsocketTrigger = async (ctx, space, spec, callback, options = {
|
|
|
263
262
|
url
|
|
264
263
|
}, {
|
|
265
264
|
F: __dxlog_file4,
|
|
266
|
-
L:
|
|
265
|
+
L: 53,
|
|
267
266
|
S: void 0,
|
|
268
267
|
C: (f, a) => f(...a)
|
|
269
268
|
});
|
|
@@ -273,11 +272,11 @@ var createWebsocketTrigger = async (ctx, space, spec, callback, options = {
|
|
|
273
272
|
open.wake(false);
|
|
274
273
|
},
|
|
275
274
|
onerror: (event) => {
|
|
276
|
-
log4.catch(event.error, {
|
|
275
|
+
log4.catch(event.error ?? new Error("Unspecified ws error."), {
|
|
277
276
|
url
|
|
278
277
|
}, {
|
|
279
278
|
F: __dxlog_file4,
|
|
280
|
-
L:
|
|
279
|
+
L: 61,
|
|
281
280
|
S: void 0,
|
|
282
281
|
C: (f, a) => f(...a)
|
|
283
282
|
});
|
|
@@ -287,20 +286,26 @@ var createWebsocketTrigger = async (ctx, space, spec, callback, options = {
|
|
|
287
286
|
try {
|
|
288
287
|
log4.info("message", void 0, {
|
|
289
288
|
F: __dxlog_file4,
|
|
290
|
-
L:
|
|
289
|
+
L: 67,
|
|
291
290
|
S: void 0,
|
|
292
291
|
C: (f, a) => f(...a)
|
|
293
292
|
});
|
|
294
|
-
|
|
293
|
+
let data;
|
|
294
|
+
if (event.data && "text" in event.data) {
|
|
295
|
+
data = JSON.parse(await event.data.text());
|
|
296
|
+
} else {
|
|
297
|
+
data = JSON.parse(new TextDecoder().decode(event.data));
|
|
298
|
+
}
|
|
295
299
|
await callback({
|
|
296
300
|
data
|
|
297
301
|
});
|
|
298
302
|
} catch (err) {
|
|
299
303
|
log4.catch(err, {
|
|
300
|
-
url
|
|
304
|
+
url,
|
|
305
|
+
data: event.data
|
|
301
306
|
}, {
|
|
302
307
|
F: __dxlog_file4,
|
|
303
|
-
L:
|
|
308
|
+
L: 76,
|
|
304
309
|
S: void 0,
|
|
305
310
|
C: (f, a) => f(...a)
|
|
306
311
|
});
|
|
@@ -321,7 +326,7 @@ var createWebsocketTrigger = async (ctx, space, spec, callback, options = {
|
|
|
321
326
|
attempt
|
|
322
327
|
}, {
|
|
323
328
|
F: __dxlog_file4,
|
|
324
|
-
L:
|
|
329
|
+
L: 91,
|
|
325
330
|
S: void 0,
|
|
326
331
|
C: (f, a) => f(...a)
|
|
327
332
|
});
|
|
@@ -332,6 +337,14 @@ var createWebsocketTrigger = async (ctx, space, spec, callback, options = {
|
|
|
332
337
|
ws?.close();
|
|
333
338
|
});
|
|
334
339
|
};
|
|
340
|
+
var createNodeWebSocket = async (url) => {
|
|
341
|
+
const importESM = Function("path", "return import(path)");
|
|
342
|
+
const { default: { WebSocket: WebSocket1 } } = await importESM("ws");
|
|
343
|
+
return new WebSocket1(url);
|
|
344
|
+
};
|
|
345
|
+
var createWebSocket = async (url) => {
|
|
346
|
+
return typeof globalThis.WebSocket === "undefined" ? await createNodeWebSocket(url) : new WebSocket(url);
|
|
347
|
+
};
|
|
335
348
|
|
|
336
349
|
// packages/core/functions/src/trigger/trigger-registry.ts
|
|
337
350
|
import { Event as Event2 } from "@dxos/async";
|
|
@@ -585,6 +598,7 @@ export {
|
|
|
585
598
|
createSubscriptionTrigger,
|
|
586
599
|
createTimerTrigger,
|
|
587
600
|
createWebsocketTrigger,
|
|
601
|
+
createWebSocket,
|
|
588
602
|
TriggerRegistry
|
|
589
603
|
};
|
|
590
|
-
//# sourceMappingURL=chunk-
|
|
604
|
+
//# sourceMappingURL=chunk-MT5Y7S4J.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/function/function-registry.ts", "../../../src/trigger/type/subscription-trigger.ts", "../../../src/trigger/type/timer-trigger.ts", "../../../src/trigger/type/websocket-trigger.ts", "../../../src/trigger/trigger-registry.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport { Event } from '@dxos/async';\nimport { type Client } from '@dxos/client';\nimport { create, Filter, type Space } from '@dxos/client/echo';\nimport { type Context, Resource } from '@dxos/context';\nimport { PublicKey } from '@dxos/keys';\nimport { log } from '@dxos/log';\nimport { ComplexMap, diff } from '@dxos/util';\n\nimport { FunctionDef, type FunctionManifest } from '../types';\n\nexport type FunctionsRegisteredEvent = {\n space: Space;\n added: FunctionDef[];\n};\n\nexport class FunctionRegistry extends Resource {\n private readonly _functionBySpaceKey = new ComplexMap<PublicKey, FunctionDef[]>(PublicKey.hash);\n\n public readonly registered = new Event<FunctionsRegisteredEvent>();\n\n constructor(private readonly _client: Client) {\n super();\n }\n\n public getFunctions(space: Space): FunctionDef[] {\n return this._functionBySpaceKey.get(space.key) ?? [];\n }\n\n public getUniqueByUri(): FunctionDef[] {\n const uniqueByUri = [...this._functionBySpaceKey.values()]\n .flatMap((defs) => defs)\n .reduce((acc, v) => {\n acc.set(v.uri, v);\n return acc;\n }, new Map<string, FunctionDef>());\n return [...uniqueByUri.values()];\n }\n\n /**\n * Loads function definitions from the manifest into the space.\n * We first load all the definitions from the space to deduplicate by functionId.\n */\n public async register(space: Space, functions: FunctionManifest['functions']): Promise<void> {\n log('register', { space: space.key, functions: functions?.length ?? 0 });\n if (!functions?.length) {\n return;\n }\n if (!space.db.graph.schemaRegistry.hasSchema(FunctionDef)) {\n space.db.graph.schemaRegistry.addSchema([FunctionDef]);\n }\n\n // Sync definitions.\n const { objects: existing } = await space.db.query(Filter.schema(FunctionDef)).run();\n const { added } = diff(existing, functions, (a, b) => a.uri === b.uri);\n // TODO(burdon): Update existing templates.\n added.forEach((def) => space.db.add(create(FunctionDef, def)));\n\n if (added.length > 0) {\n await space.db.flush({ indexes: true, updates: true });\n }\n }\n\n protected override async _open(): Promise<void> {\n log.info('opening...');\n const spacesSubscription = this._client.spaces.subscribe(async (spaces) => {\n for (const space of spaces) {\n if (this._functionBySpaceKey.has(space.key)) {\n continue;\n }\n\n const registered: FunctionDef[] = [];\n this._functionBySpaceKey.set(space.key, registered);\n await space.waitUntilReady();\n if (this._ctx.disposed) {\n break;\n }\n\n // Subscribe to updates.\n this._ctx.onDispose(\n space.db.query(Filter.schema(FunctionDef)).subscribe(({ objects }) => {\n const { added } = diff(registered, objects, (a, b) => a.uri === b.uri);\n // TODO(burdon): Update and remove.\n if (added.length > 0) {\n registered.push(...added);\n this.registered.emit({ space, added });\n }\n }),\n );\n }\n });\n\n // TODO(burdon): API: Normalize unsubscribe methods.\n this._ctx.onDispose(() => spacesSubscription.unsubscribe());\n }\n\n protected override async _close(_: Context): Promise<void> {\n log.info('closing...');\n this._functionBySpaceKey.clear();\n }\n}\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { debounce, UpdateScheduler } from '@dxos/async';\nimport { Filter, type Space } from '@dxos/client/echo';\nimport { type Context } from '@dxos/context';\nimport { createSubscription, type Query } from '@dxos/echo-db';\nimport { log } from '@dxos/log';\n\nimport type { SubscriptionTrigger } from '../../types';\nimport { type TriggerCallback, type TriggerFactory } from '../trigger-registry';\n\nexport const createSubscriptionTrigger: TriggerFactory<SubscriptionTrigger> = async (\n ctx: Context,\n space: Space,\n spec: SubscriptionTrigger,\n callback: TriggerCallback,\n) => {\n const objectIds = new Set<string>();\n const task = new UpdateScheduler(\n ctx,\n async () => {\n if (objectIds.size > 0) {\n const objects = Array.from(objectIds);\n objectIds.clear();\n await callback({ objects });\n }\n },\n { maxFrequency: 4 },\n );\n\n // TODO(burdon): Factor out diff.\n // TODO(burdon): Don't fire initially?\n // TODO(burdon): Create queue. Only allow one invocation per trigger at a time?\n const subscriptions: (() => void)[] = [];\n const subscription = createSubscription(({ added, updated }) => {\n const sizeBefore = objectIds.size;\n for (const object of added) {\n objectIds.add(object.id);\n }\n for (const object of updated) {\n objectIds.add(object.id);\n }\n if (objectIds.size > sizeBefore) {\n log.info('updated', { added: added.length, updated: updated.length });\n task.trigger();\n }\n });\n\n subscriptions.push(() => subscription.unsubscribe());\n\n // TODO(burdon): Disable trigger if keeps failing.\n const { filter, options: { deep, delay } = {} } = spec;\n const update = ({ objects }: Query) => {\n log.info('update', { objects: objects.length });\n subscription.update(objects);\n\n // TODO(burdon): Hack to monitor changes to Document's text object.\n if (deep) {\n // TODO(dmaretskyi): Removed to not have dependency on markdown-plugin.\n // for (const object of objects) {\n // const content = object.content;\n // if (content instanceof TextType) {\n // subscriptions.push(getObjectCore(content).updates.on(debounce(() => subscription.update([object]), 1_000)));\n // }\n // }\n }\n };\n\n // TODO(burdon): OR not working.\n // TODO(burdon): [Bug]: all callbacks are fired on the first mutation.\n // TODO(burdon): [Bug]: not updated when document is deleted (either top or hierarchically).\n log.info('subscription', { filter });\n // const query = triggerCtx.space.db.query(Filter.or(filter.map(({ type, props }) => Filter.typename(type, props))));\n if (filter) {\n const query = space.db.query(Filter.typename(filter[0].type, filter[0].props));\n subscriptions.push(query.subscribe(delay ? debounce(update, delay) : update));\n }\n\n ctx.onDispose(() => {\n subscriptions.forEach((unsubscribe) => unsubscribe());\n });\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { CronJob } from 'cron';\n\nimport { DeferredTask } from '@dxos/async';\nimport { type Space } from '@dxos/client/echo';\nimport { type Context } from '@dxos/context';\nimport { log } from '@dxos/log';\n\nimport type { TimerTrigger } from '../../types';\nimport { type TriggerCallback, type TriggerFactory } from '../trigger-registry';\n\nexport const createTimerTrigger: TriggerFactory<TimerTrigger> = async (\n ctx: Context,\n space: Space,\n spec: TimerTrigger,\n callback: TriggerCallback,\n) => {\n const task = new DeferredTask(ctx, async () => {\n await callback({});\n });\n\n let last = 0;\n let run = 0;\n // https://www.npmjs.com/package/cron#constructor\n const job = CronJob.from({\n cronTime: spec.cron,\n runOnInit: false,\n onTick: () => {\n // TODO(burdon): Check greater than 30s (use cron-parser).\n const now = Date.now();\n const delta = last ? now - last : 0;\n last = now;\n\n run++;\n log.info('tick', { space: space.key.truncate(), count: run, delta });\n task.schedule();\n },\n });\n\n job.start();\n ctx.onDispose(() => job.stop());\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { sleep, Trigger } from '@dxos/async';\nimport { type Space } from '@dxos/client/echo';\nimport { type Context } from '@dxos/context';\nimport { log } from '@dxos/log';\n\nimport { type WebsocketTrigger } from '../../types';\nimport { type TriggerCallback, type TriggerFactory } from '../trigger-registry';\n\ninterface WebsocketTriggerOptions {\n retryDelay: number;\n maxAttempts: number;\n}\n\n/**\n * Websocket.\n * NOTE: The port must be unique, so the same hook cannot be used for multiple spaces.\n */\nexport const createWebsocketTrigger: TriggerFactory<WebsocketTrigger, WebsocketTriggerOptions> = async (\n ctx: Context,\n space: Space,\n spec: WebsocketTrigger,\n callback: TriggerCallback,\n options: WebsocketTriggerOptions = { retryDelay: 2, maxAttempts: 5 },\n) => {\n const { url, init } = spec;\n\n let wasOpen = false;\n let ws: WebSocket;\n for (let attempt = 1; attempt <= options.maxAttempts; attempt++) {\n const open = new Trigger<boolean>();\n\n ws = await createWebSocket(url);\n Object.assign(ws, {\n onopen: () => {\n log.info('opened', { url });\n if (spec.init) {\n ws.send(new TextEncoder().encode(JSON.stringify(init)));\n }\n\n open.wake(true);\n },\n\n onclose: (event) => {\n log.info('closed', { url, code: event.code });\n // Reconnect if server closes (e.g., CF restart).\n // https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent/code\n if (event.code === 1006 && wasOpen && !ctx.disposed) {\n setTimeout(async () => {\n log.info(`reconnecting in ${options.retryDelay}s...`, { url });\n await createWebsocketTrigger(ctx, space, spec, callback, options);\n }, options.retryDelay * 1_000);\n }\n open.wake(false);\n },\n\n onerror: (event) => {\n log.catch((event as any).error ?? new Error('Unspecified ws error.'), { url });\n open.wake(false);\n },\n\n onmessage: async (event) => {\n try {\n log.info('message');\n let data;\n if (event.data && 'text' in event.data) {\n data = JSON.parse(await (event.data as Blob).text());\n } else {\n data = JSON.parse(new TextDecoder().decode(event.data as Uint8Array));\n }\n await callback({ data });\n } catch (err) {\n log.catch(err, { url, data: event.data });\n }\n },\n } satisfies Partial<WebSocket>);\n\n const isOpen = await open.wait();\n if (ctx.disposed) {\n break;\n }\n if (isOpen) {\n wasOpen = true;\n break;\n }\n const wait = Math.pow(attempt, 2) * options.retryDelay;\n if (attempt < options.maxAttempts) {\n log.warn(`failed to connect; trying again in ${wait}s`, { attempt });\n await sleep(wait * 1_000);\n }\n }\n\n ctx.onDispose(() => {\n ws?.close();\n });\n};\n\nconst createNodeWebSocket = async (url: string) => {\n // eslint-disable-next-line no-new-func\n const importESM = Function('path', 'return import(path)');\n const {\n default: { WebSocket },\n } = await importESM('ws');\n return new WebSocket(url);\n};\n\nexport const createWebSocket = async (url: string): Promise<WebSocket> => {\n return typeof (globalThis as any).WebSocket === 'undefined' ? await createNodeWebSocket(url) : new WebSocket(url);\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { Event } from '@dxos/async';\nimport { type Client } from '@dxos/client';\nimport { create, Filter, getMeta, type Space } from '@dxos/client/echo';\nimport { Context, Resource } from '@dxos/context';\nimport { compareForeignKeys, ECHO_ATTR_META, foreignKey } from '@dxos/echo-schema';\nimport { invariant } from '@dxos/invariant';\nimport { PublicKey } from '@dxos/keys';\nimport { log } from '@dxos/log';\nimport { ComplexMap, diff } from '@dxos/util';\n\nimport { createSubscriptionTrigger, createTimerTrigger, createWebsocketTrigger } from './type';\nimport { type FunctionManifest, FunctionTrigger, type FunctionTriggerType, type TriggerSpec } from '../types';\n\ntype ResponseCode = number;\n\nexport type TriggerCallback = (args: object) => Promise<ResponseCode>;\n\n// TODO(burdon): Make object?\nexport type TriggerFactory<Spec extends TriggerSpec, Options = any> = (\n ctx: Context,\n space: Space,\n spec: Spec,\n callback: TriggerCallback,\n options?: Options,\n) => Promise<void>;\n\nexport type TriggerFactoryMap = Record<FunctionTriggerType, TriggerFactory<any>>;\n\nconst triggerFactory: TriggerFactoryMap = {\n subscription: createSubscriptionTrigger,\n timer: createTimerTrigger,\n // TODO(burdon): Cannot use in browser.\n // webhook: createWebhookTrigger,\n webhook: null as any,\n websocket: createWebsocketTrigger,\n};\n\nexport type TriggerEvent = {\n space: Space;\n triggers: FunctionTrigger[];\n};\n\ntype RegisteredTrigger = {\n activationCtx?: Context;\n trigger: FunctionTrigger;\n};\n\nexport class TriggerRegistry extends Resource {\n private readonly _triggersBySpaceKey = new ComplexMap<PublicKey, RegisteredTrigger[]>(PublicKey.hash);\n\n public readonly registered = new Event<TriggerEvent>();\n public readonly removed = new Event<TriggerEvent>();\n\n constructor(\n private readonly _client: Client,\n private readonly _options?: TriggerFactoryMap,\n ) {\n super();\n }\n\n public getActiveTriggers(space: Space): FunctionTrigger[] {\n return this._getTriggers(space, (t) => t.activationCtx != null);\n }\n\n public getInactiveTriggers(space: Space): FunctionTrigger[] {\n return this._getTriggers(space, (t) => t.activationCtx == null);\n }\n\n /**\n * Set callback for trigger.\n */\n public async activate(space: Space, trigger: FunctionTrigger, callback: TriggerCallback): Promise<void> {\n log('activate', { space: space.key, trigger });\n\n const activationCtx = new Context({ name: `FunctionTrigger-${trigger.function}` });\n this._ctx.onDispose(() => activationCtx.dispose());\n const registeredTrigger = this._triggersBySpaceKey.get(space.key)?.find((reg) => reg.trigger.id === trigger.id);\n invariant(registeredTrigger, `Trigger is not registered: ${trigger.function}`);\n registeredTrigger.activationCtx = activationCtx;\n\n try {\n // Create trigger.\n const options = this._options?.[trigger.spec.type];\n const createTrigger = triggerFactory[trigger.spec.type];\n invariant(createTrigger, `Trigger factory not found: ${trigger.spec.type}`);\n await createTrigger(activationCtx, space, trigger.spec, callback, options);\n } catch (err) {\n delete registeredTrigger.activationCtx;\n throw err;\n }\n }\n\n /**\n * Loads triggers from the manifest into the space.\n */\n public async register(space: Space, manifest: FunctionManifest): Promise<void> {\n log('register', { space: space.key });\n if (!manifest.triggers?.length) {\n return;\n }\n\n if (!space.db.graph.schemaRegistry.hasSchema(FunctionTrigger)) {\n space.db.graph.schemaRegistry.addSchema([FunctionTrigger]);\n }\n\n // Create FK to enable syncing if none are set (NOTE: Possible collision).\n const manifestTriggers = manifest.triggers.map((trigger) => {\n let keys = trigger[ECHO_ATTR_META]?.keys;\n delete trigger[ECHO_ATTR_META];\n if (!keys?.length) {\n keys = [foreignKey('manifest', [trigger.function, trigger.spec.type].join(':'))];\n }\n\n return create(FunctionTrigger, trigger, { keys });\n });\n\n // Sync triggers.\n const { objects: existing } = await space.db.query(Filter.schema(FunctionTrigger)).run();\n const { added } = diff(existing, manifestTriggers, compareForeignKeys);\n\n // TODO(burdon): Update existing.\n added.forEach((trigger) => {\n space.db.add(trigger);\n log.info('added', { meta: getMeta(trigger) });\n });\n\n if (added.length > 0) {\n await space.db.flush();\n }\n }\n\n protected override async _open(): Promise<void> {\n log.info('open...');\n const spaceListSubscription = this._client.spaces.subscribe(async (spaces) => {\n for (const space of spaces) {\n if (this._triggersBySpaceKey.has(space.key)) {\n continue;\n }\n\n const registered: RegisteredTrigger[] = [];\n this._triggersBySpaceKey.set(space.key, registered);\n await space.waitUntilReady();\n if (this._ctx.disposed) {\n break;\n }\n\n // Subscribe to updates.\n this._ctx.onDispose(\n space.db.query(Filter.schema(FunctionTrigger)).subscribe(async ({ objects: current }) => {\n log.info('update', { space: space.key, registered: registered.length, current: current.length });\n await this._handleRemovedTriggers(space, current, registered);\n this._handleNewTriggers(space, current, registered);\n }),\n );\n }\n });\n\n this._ctx.onDispose(() => spaceListSubscription.unsubscribe());\n log.info('opened');\n }\n\n protected override async _close(_: Context): Promise<void> {\n log.info('close...');\n this._triggersBySpaceKey.clear();\n log.info('closed');\n }\n\n private _handleNewTriggers(space: Space, current: FunctionTrigger[], registered: RegisteredTrigger[]) {\n const added = current.filter((candidate) => {\n return candidate.enabled && registered.find((reg) => reg.trigger.id === candidate.id) == null;\n });\n\n if (added.length > 0) {\n const newRegisteredTriggers: RegisteredTrigger[] = added.map((trigger) => ({ trigger }));\n registered.push(...newRegisteredTriggers);\n log.info('added', () => ({\n spaceKey: space.key,\n triggers: added.map((trigger) => trigger.function),\n }));\n\n this.registered.emit({ space, triggers: added });\n }\n }\n\n private async _handleRemovedTriggers(\n space: Space,\n current: FunctionTrigger[],\n registered: RegisteredTrigger[],\n ): Promise<void> {\n const removed: FunctionTrigger[] = [];\n for (let i = registered.length - 1; i >= 0; i--) {\n const wasRemoved =\n current.filter((trigger) => trigger.enabled).find((trigger) => trigger.id === registered[i].trigger.id) == null;\n if (wasRemoved) {\n const unregistered = registered.splice(i, 1)[0];\n await unregistered.activationCtx?.dispose();\n removed.push(unregistered.trigger);\n }\n }\n\n if (removed.length > 0) {\n log.info('removed', () => ({\n spaceKey: space.key,\n triggers: removed.map((trigger) => trigger.function),\n }));\n\n this.removed.emit({ space, triggers: removed });\n }\n }\n\n private _getTriggers(space: Space, predicate: (trigger: RegisteredTrigger) => boolean): FunctionTrigger[] {\n const allSpaceTriggers = this._triggersBySpaceKey.get(space.key) ?? [];\n return allSpaceTriggers.fil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nBrE,MAAAA,KAAI+C,KAAK,SAAS,OAAO;QACvBwB,UAAU/E,MAAMS;QAChBoB,UAAUqB,MAAMZ,IAAI,CAAChC,YAAYA,QAAQM,QAAQ;MACnD,IAAA;;;;;;AAEA,WAAKhB,WAAWoF,KAAK;QAAEhF;QAAO6B,UAAUqB;MAAM,CAAA;IAChD;EACF;EAEA,MAAckB,uBACZpE,OACAmE,SACAvE,YACe;AACf,UAAME,UAA6B,CAAA;AACnC,aAASmF,IAAIrF,WAAWkC,SAAS,GAAGmD,KAAK,GAAGA,KAAK;AAC/C,YAAMC,aACJf,QAAQO,OAAO,CAACpE,YAAYA,QAAQsE,OAAO,EAAE1D,KAAK,CAACZ,YAAYA,QAAQc,OAAOxB,WAAWqF,CAAAA,EAAG3E,QAAQc,EAAE,KAAK;AAC7G,UAAI8D,YAAY;AACd,cAAMC,eAAevF,WAAWwF,OAAOH,GAAG,CAAA,EAAG,CAAA;AAC7C,cAAME,aAAahF,eAAeY,QAAAA;AAClCjB,gBAAQgF,KAAKK,aAAa7E,OAAO;MACnC;IACF;AAEA,QAAIR,QAAQgC,SAAS,GAAG;AACtBtB,MAAAA,KAAI+C,KAAK,WAAW,OAAO;QACzBwB,UAAU/E,MAAMS;QAChBoB,UAAU/B,QAAQwC,IAAI,CAAChC,YAAYA,QAAQM,QAAQ;MACrD,IAAA;;;;;;AAEA,WAAKd,QAAQkF,KAAK;QAAEhF;QAAO6B,UAAU/B;MAAQ,CAAA;IAC/C;EACF;EAEQG,aAAaD,OAAcqF,WAAuE;AACxG,UAAMC,mBAAmB,KAAK9F,oBAAoByB,IAAIjB,MAAMS,GAAG,KAAK,CAAA;AACpE,WAAO6E,iBAAiBZ,OAAOW,SAAAA,EAAW/C,IAAI,CAAChC,YAAYA,QAAQA,OAAO;EAC5E;AACF;",
|
|
6
|
+
"names": ["Event", "create", "Filter", "Resource", "PublicKey", "log", "ComplexMap", "diff", "FunctionRegistry", "Resource", "constructor", "_client", "_functionBySpaceKey", "ComplexMap", "PublicKey", "hash", "registered", "Event", "getFunctions", "space", "get", "key", "getUniqueByUri", "uniqueByUri", "values", "flatMap", "defs", "reduce", "acc", "v", "set", "uri", "Map", "register", "functions", "log", "length", "db", "graph", "schemaRegistry", "hasSchema", "FunctionDef", "addSchema", "objects", "existing", "query", "Filter", "schema", "run", "added", "diff", "a", "b", "forEach", "def", "add", "create", "flush", "indexes", "updates", "_open", "info", "spacesSubscription", "spaces", "subscribe", "has", "waitUntilReady", "_ctx", "disposed", "onDispose", "push", "emit", "unsubscribe", "_close", "_", "clear", "debounce", "UpdateScheduler", "Filter", "createSubscription", "log", "createSubscriptionTrigger", "ctx", "space", "spec", "callback", "objectIds", "Set", "task", "size", "objects", "Array", "from", "clear", "maxFrequency", "subscriptions", "subscription", "added", "updated", "sizeBefore", "object", "add", "id", "info", "length", "trigger", "push", "unsubscribe", "filter", "options", "deep", "delay", "update", "query", "db", "typename", "type", "props", "subscribe", "onDispose", "forEach", "CronJob", "DeferredTask", "log", "createTimerTrigger", "ctx", "space", "spec", "callback", "task", "last", "run", "job", "from", "cronTime", "cron", "runOnInit", "onTick", "now", "Date", "delta", "info", "key", "truncate", "count", "schedule", "start", "onDispose", "stop", "sleep", "Trigger", "log", "createWebsocketTrigger", "ctx", "space", "spec", "callback", "options", "retryDelay", "maxAttempts", "url", "init", "wasOpen", "ws", "attempt", "open", "createWebSocket", "Object", "assign", "onopen", "info", "send", "TextEncoder", "encode", "JSON", "stringify", "wake", "onclose", "event", "code", "disposed", "setTimeout", "onerror", "catch", "error", "Error", "onmessage", "data", "parse", "text", "TextDecoder", "decode", "err", "isOpen", "wait", "Math", "pow", "warn", "onDispose", "close", "createNodeWebSocket", "importESM", "Function", "default", "WebSocket", "globalThis", "Event", "create", "Filter", "getMeta", "Context", "Resource", "compareForeignKeys", "ECHO_ATTR_META", "foreignKey", "invariant", "PublicKey", "log", "ComplexMap", "diff", "triggerFactory", "subscription", "createSubscriptionTrigger", "timer", "createTimerTrigger", "webhook", "websocket", "createWebsocketTrigger", "TriggerRegistry", "Resource", "constructor", "_client", "_options", "_triggersBySpaceKey", "ComplexMap", "PublicKey", "hash", "registered", "Event", "removed", "getActiveTriggers", "space", "_getTriggers", "t", "activationCtx", "getInactiveTriggers", "activate", "trigger", "callback", "log", "key", "Context", "name", "function", "_ctx", "onDispose", "dispose", "registeredTrigger", "get", "find", "reg", "id", "invariant", "options", "spec", "type", "createTrigger", "err", "register", "manifest", "triggers", "length", "db", "graph", "schemaRegistry", "hasSchema", "FunctionTrigger", "addSchema", "manifestTriggers", "map", "keys", "ECHO_ATTR_META", "foreignKey", "join", "create", "objects", "existing", "query", "Filter", "schema", "run", "added", "diff", "compareForeignKeys", "forEach", "add", "info", "meta", "getMeta", "flush", "_open", "spaceListSubscription", "spaces", "subscribe", "has", "set", "waitUntilReady", "disposed", "current", "_handleRemovedTriggers", "_handleNewTriggers", "unsubscribe", "_close", "_", "clear", "filter", "candidate", "enabled", "newRegisteredTriggers", "push", "spaceKey", "emit", "i", "wasRemoved", "unregistered", "splice", "predicate", "allSpaceTriggers"]
|
|
7
|
+
}
|
|
@@ -20,7 +20,10 @@ var SubscriptionTriggerSchema = S.mutable(S.Struct({
|
|
|
20
20
|
// TODO(burdon): Define query DSL (from ECHO).
|
|
21
21
|
filter: S.Array(S.Struct({
|
|
22
22
|
type: S.String,
|
|
23
|
-
props: S.optional(S.Record(
|
|
23
|
+
props: S.optional(S.Record({
|
|
24
|
+
key: S.String,
|
|
25
|
+
value: S.Any
|
|
26
|
+
}))
|
|
24
27
|
})),
|
|
25
28
|
options: S.optional(S.Struct({
|
|
26
29
|
// Watch changes to object (not just creation).
|
|
@@ -42,7 +45,10 @@ var WebhookTriggerSchema = S.mutable(S.Struct({
|
|
|
42
45
|
var WebsocketTriggerSchema = S.mutable(S.Struct({
|
|
43
46
|
type: S.Literal("websocket"),
|
|
44
47
|
url: S.String,
|
|
45
|
-
init: S.optional(S.Record(
|
|
48
|
+
init: S.optional(S.Record({
|
|
49
|
+
key: S.String,
|
|
50
|
+
value: S.Any
|
|
51
|
+
}))
|
|
46
52
|
}));
|
|
47
53
|
var TriggerSpecSchema = S.Union(TimerTriggerSchema, WebhookTriggerSchema, WebsocketTriggerSchema, SubscriptionTriggerSchema);
|
|
48
54
|
var FunctionDef = class extends TypedObject({
|
|
@@ -61,9 +67,14 @@ var FunctionTrigger = class extends TypedObject({
|
|
|
61
67
|
})({
|
|
62
68
|
name: S.optional(S.String),
|
|
63
69
|
enabled: S.optional(S.Boolean),
|
|
64
|
-
function: S.String.pipe(S.
|
|
70
|
+
function: S.String.pipe(S.annotations({
|
|
71
|
+
description: "Function URI."
|
|
72
|
+
})),
|
|
65
73
|
// The `meta` property is merged into the event data passed to the function.
|
|
66
|
-
meta: S.optional(S.mutable(S.Record(
|
|
74
|
+
meta: S.optional(S.mutable(S.Record({
|
|
75
|
+
key: S.String,
|
|
76
|
+
value: S.Any
|
|
77
|
+
}))),
|
|
67
78
|
spec: TriggerSpecSchema
|
|
68
79
|
}) {
|
|
69
80
|
};
|
|
@@ -83,4 +94,4 @@ export {
|
|
|
83
94
|
FunctionManifestSchema,
|
|
84
95
|
FUNCTION_SCHEMA
|
|
85
96
|
};
|
|
86
|
-
//# sourceMappingURL=chunk-
|
|
97
|
+
//# sourceMappingURL=chunk-MWJ54RSV.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
|
+
}
|
|
@@ -4,14 +4,15 @@ import {
|
|
|
4
4
|
TriggerRegistry,
|
|
5
5
|
createSubscriptionTrigger,
|
|
6
6
|
createTimerTrigger,
|
|
7
|
+
createWebSocket,
|
|
7
8
|
createWebsocketTrigger
|
|
8
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-MT5Y7S4J.mjs";
|
|
9
10
|
import {
|
|
10
11
|
FUNCTION_SCHEMA,
|
|
11
12
|
FunctionDef,
|
|
12
13
|
FunctionManifestSchema,
|
|
13
14
|
FunctionTrigger
|
|
14
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-MWJ54RSV.mjs";
|
|
15
16
|
|
|
16
17
|
// packages/core/functions/src/handler.ts
|
|
17
18
|
import { PublicKey } from "@dxos/client";
|
|
@@ -25,7 +26,7 @@ var subscriptionHandler = (handler, types) => {
|
|
|
25
26
|
if (!space) {
|
|
26
27
|
log.error("Invalid space", void 0, {
|
|
27
28
|
F: __dxlog_file,
|
|
28
|
-
L:
|
|
29
|
+
L: 132,
|
|
29
30
|
S: void 0,
|
|
30
31
|
C: (f, a) => f(...a)
|
|
31
32
|
});
|
|
@@ -38,7 +39,7 @@ var subscriptionHandler = (handler, types) => {
|
|
|
38
39
|
data
|
|
39
40
|
}, {
|
|
40
41
|
F: __dxlog_file,
|
|
41
|
-
L:
|
|
42
|
+
L: 142,
|
|
42
43
|
S: void 0,
|
|
43
44
|
C: (f, a) => f(...a)
|
|
44
45
|
});
|
|
@@ -48,7 +49,7 @@ var subscriptionHandler = (handler, types) => {
|
|
|
48
49
|
objects: objects?.length
|
|
49
50
|
}, {
|
|
50
51
|
F: __dxlog_file,
|
|
51
|
-
L:
|
|
52
|
+
L: 144,
|
|
52
53
|
S: void 0,
|
|
53
54
|
C: (f, a) => f(...a)
|
|
54
55
|
});
|
|
@@ -86,6 +87,7 @@ export {
|
|
|
86
87
|
TriggerRegistry,
|
|
87
88
|
createSubscriptionTrigger,
|
|
88
89
|
createTimerTrigger,
|
|
90
|
+
createWebSocket,
|
|
89
91
|
createWebsocketTrigger,
|
|
90
92
|
subscriptionHandler
|
|
91
93
|
};
|
|
@@ -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 { type
|
|
5
|
-
"mappings": "
|
|
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
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
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"inputs":{"inject-globals:@inject-globals":{"bytes":384,"imports":[{"path":"@dxos/node-std/inject-globals","kind":"import-statement","external":true}],"format":"esm"},"packages/core/functions/src/types.ts":{"bytes":9947,"imports":[{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@inject-globals","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"},{"path":"@inject-globals","kind":"import-statement","external":true}],"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"},{"path":"@inject-globals","kind":"import-statement","external":true}],"format":"esm"},"packages/core/functions/src/handler.ts":{"bytes":10606,"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},{"path":"@inject-globals","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},{"path":"@inject-globals","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},{"path":"@inject-globals","kind":"import-statement","external":true}],"format":"esm"},"packages/core/functions/src/trigger/type/websocket-trigger.ts":{"bytes":11002,"imports":[{"path":"ws","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@inject-globals","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"},{"path":"@inject-globals","kind":"import-statement","external":true}],"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"},{"path":"@inject-globals","kind":"import-statement","external":true}],"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"},{"path":"@inject-globals","kind":"import-statement","external":true}],"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"},{"path":"@inject-globals","kind":"import-statement","external":true}],"format":"esm"},"packages/core/functions/src/testing/types.ts":{"bytes":1131,"imports":[{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@inject-globals","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":"@dxos/node-std/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":"@inject-globals","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":"@dxos/node-std/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":"@inject-globals","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"},{"path":"@inject-globals","kind":"import-statement","external":true}],"format":"esm"},"packages/core/functions/src/testing/setup.ts":{"bytes":12671,"imports":[{"path":"get-port-please","kind":"import-statement","external":true},{"path":"@dxos/node-std/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"},{"path":"@inject-globals","kind":"import-statement","external":true}],"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"},{"path":"@inject-globals","kind":"import-statement","external":true}],"format":"esm"},"packages/core/functions/src/testing/manifest.ts":{"bytes":1139,"imports":[{"path":"@inject-globals","kind":"import-statement","external":true}],"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"},{"path":"@inject-globals","kind":"import-statement","external":true}],"format":"esm"}},"outputs":{"packages/core/functions/dist/lib/browser/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":5746},"packages/core/functions/dist/lib/browser/index.mjs":{"imports":[{"path":"packages/core/functions/dist/lib/browser/chunk-CRAAIWU6.mjs","kind":"import-statement"},{"path":"packages/core/functions/dist/lib/browser/chunk-2I75VGHZ.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","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":2237},"packages/core/functions/dist/lib/browser/testing/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":32213},"packages/core/functions/dist/lib/browser/testing/index.mjs":{"imports":[{"path":"packages/core/functions/dist/lib/browser/chunk-CRAAIWU6.mjs","kind":"import-statement"},{"path":"packages/core/functions/dist/lib/browser/chunk-2I75VGHZ.mjs","kind":"import-statement"},{"path":"get-port-please","kind":"import-statement","external":true},{"path":"@dxos/node-std/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":"@dxos/node-std/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":"@dxos/node-std/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":2793},"packages/core/functions/src/testing/types.ts":{"bytesInOutput":182},"packages/core/functions/src/runtime/dev-server.ts":{"bytesInOutput":7870},"packages/core/functions/src/runtime/index.ts":{"bytesInOutput":0},"packages/core/functions/src/runtime/scheduler.ts":{"bytesInOutput":5340},"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":18126},"packages/core/functions/dist/lib/browser/chunk-CRAAIWU6.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":31876},"packages/core/functions/dist/lib/browser/chunk-CRAAIWU6.mjs":{"imports":[{"path":"packages/core/functions/dist/lib/browser/chunk-2I75VGHZ.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":"ws","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","createWebsocketTrigger"],"inputs":{"packages/core/functions/src/function/function-registry.ts":{"bytesInOutput":3046},"packages/core/functions/src/function/index.ts":{"bytesInOutput":0},"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":2929},"packages/core/functions/src/trigger/trigger-registry.ts":{"bytesInOutput":7421},"packages/core/functions/src/trigger/type/index.ts":{"bytesInOutput":0},"packages/core/functions/src/trigger/index.ts":{"bytesInOutput":0}},"bytes":16899},"packages/core/functions/dist/lib/browser/types.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":93},"packages/core/functions/dist/lib/browser/types.mjs":{"imports":[{"path":"packages/core/functions/dist/lib/browser/chunk-2I75VGHZ.mjs","kind":"import-statement"}],"exports":["FUNCTION_SCHEMA","FunctionDef","FunctionManifestSchema","FunctionTrigger"],"entryPoint":"packages/core/functions/src/types.ts","inputs":{},"bytes":276},"packages/core/functions/dist/lib/browser/chunk-2I75VGHZ.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":5522},"packages/core/functions/dist/lib/browser/chunk-2I75VGHZ.mjs":{"imports":[{"path":"@dxos/node-std/inject-globals","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true}],"exports":["FUNCTION_SCHEMA","FunctionDef","FunctionManifestSchema","FunctionTrigger","__require"],"inputs":{"inject-globals:@inject-globals":{"bytesInOutput":90},"packages/core/functions/src/types.ts":{"bytesInOutput":1898}},"bytes":2610}}}
|
|
1
|
+
{"inputs":{"inject-globals:@inject-globals":{"bytes":324,"imports":[{"path":"@dxos/node-std/inject-globals","kind":"import-statement","external":true}],"format":"esm"},"packages/core/functions/src/types.ts":{"bytes":10352,"imports":[{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@inject-globals","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"},{"path":"@inject-globals","kind":"import-statement","external":true}],"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"},{"path":"@inject-globals","kind":"import-statement","external":true}],"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},{"path":"@inject-globals","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},{"path":"@inject-globals","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},{"path":"@inject-globals","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},{"path":"@inject-globals","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"},{"path":"@inject-globals","kind":"import-statement","external":true}],"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"},{"path":"@inject-globals","kind":"import-statement","external":true}],"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"},{"path":"@inject-globals","kind":"import-statement","external":true}],"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"},{"path":"@inject-globals","kind":"import-statement","external":true}],"format":"esm"},"packages/core/functions/src/testing/types.ts":{"bytes":1131,"imports":[{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@inject-globals","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":"@dxos/node-std/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":"@inject-globals","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":"@dxos/node-std/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":"@inject-globals","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"},{"path":"@inject-globals","kind":"import-statement","external":true}],"format":"esm"},"packages/core/functions/src/testing/setup.ts":{"bytes":12707,"imports":[{"path":"get-port-please","kind":"import-statement","external":true},{"path":"@dxos/node-std/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"},{"path":"@inject-globals","kind":"import-statement","external":true}],"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"},{"path":"@inject-globals","kind":"import-statement","external":true}],"format":"esm"},"packages/core/functions/src/testing/manifest.ts":{"bytes":1139,"imports":[{"path":"@inject-globals","kind":"import-statement","external":true}],"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"},{"path":"@inject-globals","kind":"import-statement","external":true}],"format":"esm"}},"outputs":{"packages/core/functions/dist/lib/browser/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":5751},"packages/core/functions/dist/lib/browser/index.mjs":{"imports":[{"path":"packages/core/functions/dist/lib/browser/chunk-MT5Y7S4J.mjs","kind":"import-statement"},{"path":"packages/core/functions/dist/lib/browser/chunk-MWJ54RSV.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":2275},"packages/core/functions/dist/lib/browser/testing/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":32237},"packages/core/functions/dist/lib/browser/testing/index.mjs":{"imports":[{"path":"packages/core/functions/dist/lib/browser/chunk-MT5Y7S4J.mjs","kind":"import-statement"},{"path":"packages/core/functions/dist/lib/browser/chunk-MWJ54RSV.mjs","kind":"import-statement"},{"path":"get-port-please","kind":"import-statement","external":true},{"path":"@dxos/node-std/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":"@dxos/node-std/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":"@dxos/node-std/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":2785},"packages/core/functions/src/testing/types.ts":{"bytesInOutput":182},"packages/core/functions/src/runtime/dev-server.ts":{"bytesInOutput":7870},"packages/core/functions/src/runtime/scheduler.ts":{"bytesInOutput":5340},"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":18118},"packages/core/functions/dist/lib/browser/chunk-MT5Y7S4J.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":33089},"packages/core/functions/dist/lib/browser/chunk-MT5Y7S4J.mjs":{"imports":[{"path":"packages/core/functions/dist/lib/browser/chunk-MWJ54RSV.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":17480},"packages/core/functions/dist/lib/browser/types.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":93},"packages/core/functions/dist/lib/browser/types.mjs":{"imports":[{"path":"packages/core/functions/dist/lib/browser/chunk-MWJ54RSV.mjs","kind":"import-statement"}],"exports":["FUNCTION_SCHEMA","FunctionDef","FunctionManifestSchema","FunctionTrigger"],"entryPoint":"packages/core/functions/src/types.ts","inputs":{},"bytes":276},"packages/core/functions/dist/lib/browser/chunk-MWJ54RSV.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":5706},"packages/core/functions/dist/lib/browser/chunk-MWJ54RSV.mjs":{"imports":[{"path":"@dxos/node-std/inject-globals","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true}],"exports":["FUNCTION_SCHEMA","FunctionDef","FunctionManifestSchema","FunctionTrigger","__require"],"inputs":{"inject-globals:@inject-globals":{"bytesInOutput":90},"packages/core/functions/src/types.ts":{"bytesInOutput":2005}},"bytes":2717}}}
|
|
@@ -2,12 +2,12 @@ import "@dxos/node-std/globals";
|
|
|
2
2
|
import {
|
|
3
3
|
FunctionRegistry,
|
|
4
4
|
TriggerRegistry
|
|
5
|
-
} from "../chunk-
|
|
5
|
+
} from "../chunk-MT5Y7S4J.mjs";
|
|
6
6
|
import {
|
|
7
7
|
FunctionDef,
|
|
8
8
|
FunctionTrigger,
|
|
9
9
|
__require
|
|
10
|
-
} from "../chunk-
|
|
10
|
+
} from "../chunk-MWJ54RSV.mjs";
|
|
11
11
|
|
|
12
12
|
// packages/core/functions/src/testing/setup.ts
|
|
13
13
|
import { getRandomPort } from "get-port-please";
|
|
@@ -542,7 +542,12 @@ var createContext2 = () => new Context2({
|
|
|
542
542
|
var createInitializedClients = async (testBuilder, count = 1, config) => {
|
|
543
543
|
const clients = range(count).map(() => new Client({
|
|
544
544
|
config,
|
|
545
|
-
services: testBuilder.createLocalClientServices()
|
|
545
|
+
services: testBuilder.createLocalClientServices(),
|
|
546
|
+
types: [
|
|
547
|
+
FunctionDef,
|
|
548
|
+
FunctionTrigger,
|
|
549
|
+
TestType
|
|
550
|
+
]
|
|
546
551
|
}));
|
|
547
552
|
testBuilder.ctx.onDispose(() => Promise.all(clients.map((client) => client.destroy())));
|
|
548
553
|
return Promise.all(clients.map(async (client, index) => {
|
|
@@ -550,12 +555,7 @@ var createInitializedClients = async (testBuilder, count = 1, config) => {
|
|
|
550
555
|
await client.halo.createIdentity({
|
|
551
556
|
displayName: `Peer ${index}`
|
|
552
557
|
});
|
|
553
|
-
await client.spaces.
|
|
554
|
-
client.addTypes([
|
|
555
|
-
FunctionDef,
|
|
556
|
-
FunctionTrigger,
|
|
557
|
-
TestType
|
|
558
|
-
]);
|
|
558
|
+
await client.spaces.waitUntilReady();
|
|
559
559
|
return client;
|
|
560
560
|
}));
|
|
561
561
|
};
|