@dxos/functions 0.7.0 → 0.7.1-staging.7f6f91c

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.
Files changed (51) hide show
  1. package/dist/lib/browser/{chunk-7QJNOQ6N.mjs → chunk-FWIFI2MH.mjs} +57 -32
  2. package/dist/lib/browser/chunk-FWIFI2MH.mjs.map +7 -0
  3. package/dist/lib/browser/{chunk-L7H5DE53.mjs → chunk-QX2SGAWR.mjs} +28 -21
  4. package/dist/lib/browser/chunk-QX2SGAWR.mjs.map +7 -0
  5. package/dist/lib/browser/index.mjs +9 -5
  6. package/dist/lib/browser/index.mjs.map +1 -1
  7. package/dist/lib/browser/meta.json +1 -1
  8. package/dist/lib/browser/testing/index.mjs +6 -6
  9. package/dist/lib/browser/testing/index.mjs.map +3 -3
  10. package/dist/lib/browser/types.mjs +9 -5
  11. package/dist/lib/node/{chunk-TNG3Z74V.cjs → chunk-GKDHAWCP.cjs} +61 -34
  12. package/dist/lib/node/chunk-GKDHAWCP.cjs.map +7 -0
  13. package/dist/lib/node/{chunk-3KJEM5VR.cjs → chunk-OKV7IWWB.cjs} +41 -34
  14. package/dist/lib/node/chunk-OKV7IWWB.cjs.map +7 -0
  15. package/dist/lib/node/index.cjs +17 -13
  16. package/dist/lib/node/index.cjs.map +1 -1
  17. package/dist/lib/node/meta.json +1 -1
  18. package/dist/lib/node/testing/index.cjs +13 -13
  19. package/dist/lib/node/testing/index.cjs.map +2 -2
  20. package/dist/lib/node/types.cjs +11 -7
  21. package/dist/lib/node/types.cjs.map +2 -2
  22. package/dist/lib/node-esm/{chunk-DMTGUST2.mjs → chunk-SPHZ5SOR.mjs} +28 -21
  23. package/dist/lib/node-esm/chunk-SPHZ5SOR.mjs.map +7 -0
  24. package/dist/lib/node-esm/{chunk-SLC6ICH2.mjs → chunk-YSKH6PBN.mjs} +57 -32
  25. package/dist/lib/node-esm/chunk-YSKH6PBN.mjs.map +7 -0
  26. package/dist/lib/node-esm/index.mjs +9 -5
  27. package/dist/lib/node-esm/index.mjs.map +1 -1
  28. package/dist/lib/node-esm/meta.json +1 -1
  29. package/dist/lib/node-esm/testing/index.mjs +6 -6
  30. package/dist/lib/node-esm/testing/index.mjs.map +3 -3
  31. package/dist/lib/node-esm/types.mjs +9 -5
  32. package/dist/types/src/trigger/trigger-registry.d.ts +3 -3
  33. package/dist/types/src/trigger/trigger-registry.d.ts.map +1 -1
  34. package/dist/types/src/types.d.ts +137 -72
  35. package/dist/types/src/types.d.ts.map +1 -1
  36. package/package.json +17 -16
  37. package/schema/functions.json +2 -2
  38. package/src/runtime/scheduler.test.ts +1 -1
  39. package/src/runtime/scheduler.ts +1 -1
  40. package/src/testing/functions-integration.test.ts +1 -1
  41. package/src/testing/util.ts +2 -2
  42. package/src/trigger/trigger-registry.test.ts +7 -9
  43. package/src/trigger/trigger-registry.ts +7 -8
  44. package/src/trigger/type/subscription-trigger.ts +2 -2
  45. package/src/types.ts +70 -36
  46. package/dist/lib/browser/chunk-7QJNOQ6N.mjs.map +0 -7
  47. package/dist/lib/browser/chunk-L7H5DE53.mjs.map +0 -7
  48. package/dist/lib/node/chunk-3KJEM5VR.cjs.map +0 -7
  49. package/dist/lib/node/chunk-TNG3Z74V.cjs.map +0 -7
  50. package/dist/lib/node-esm/chunk-DMTGUST2.mjs.map +0 -7
  51. package/dist/lib/node-esm/chunk-SLC6ICH2.mjs.map +0 -7
@@ -2,12 +2,12 @@ import "@dxos/node-std/globals";
2
2
  import {
3
3
  FunctionRegistry,
4
4
  TriggerRegistry
5
- } from "../chunk-L7H5DE53.mjs";
5
+ } from "../chunk-QX2SGAWR.mjs";
6
6
  import {
7
7
  FunctionDef,
8
8
  FunctionTrigger,
9
9
  __require
10
- } from "../chunk-7QJNOQ6N.mjs";
10
+ } from "../chunk-FWIFI2MH.mjs";
11
11
 
12
12
  // packages/core/functions/src/testing/setup.ts
13
13
  import { getRandomPort } from "get-port-please";
@@ -478,7 +478,7 @@ var Scheduler = class {
478
478
  log2.info("exec", {
479
479
  function: def.uri,
480
480
  url,
481
- triggerType: trigger.spec.type
481
+ triggerType: trigger.spec?.type
482
482
  }, {
483
483
  F: __dxlog_file2,
484
484
  L: 139,
@@ -622,13 +622,13 @@ import { invariant as invariant2 } from "@dxos/invariant";
622
622
  import { Invitation } from "@dxos/protocols/proto/dxos/client/services";
623
623
  var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/functions/src/testing/util.ts";
624
624
  var triggerWebhook = async (space, uri) => {
625
- const trigger = (await space.db.query(Filter.schema(FunctionTrigger, (t) => t.function === uri)).run()).objects[0];
626
- invariant2(trigger.spec.type === "webhook", void 0, {
625
+ const trigger = (await space.db.query(Filter.schema(FunctionTrigger, (trigger2) => trigger2.function === uri)).run()).objects[0];
626
+ invariant2(trigger.spec?.type === "webhook", void 0, {
627
627
  F: __dxlog_file3,
628
628
  L: 17,
629
629
  S: void 0,
630
630
  A: [
631
- "trigger.spec.type === 'webhook'",
631
+ "trigger.spec?.type === 'webhook'",
632
632
  ""
633
633
  ]
634
634
  });
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/testing/setup.ts", "../../../../src/testing/types.ts", "../../../../src/runtime/dev-server.ts", "../../../../src/runtime/scheduler.ts", "../../../../src/testing/util.ts", "../../../../src/testing/manifest.ts"],
4
- "sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport { getRandomPort } from 'get-port-please';\nimport path from 'node:path';\n\nimport { waitForCondition } from '@dxos/async';\nimport { Client, Config } from '@dxos/client';\nimport { type Space } from '@dxos/client/echo';\nimport { type TestBuilder } from '@dxos/client/testing';\nimport { range } from '@dxos/util';\n\nimport { TestType } from './types';\nimport { FunctionRegistry } from '../function';\nimport { DevServer, type DevServerOptions, Scheduler } from '../runtime';\nimport { TriggerRegistry } from '../trigger';\nimport { FunctionDef, FunctionTrigger } from '../types';\n\nexport type FunctionsPluginInitializer = (client: Client) => Promise<{ close: () => Promise<void> }>;\n\n// TODO(burdon): Extend/wrap TestBuilder.\n\nexport const createInitializedClients = async (testBuilder: TestBuilder, count: number = 1, config?: Config) => {\n const clients = range(count).map(\n () =>\n new Client({\n config,\n services: testBuilder.createLocalClientServices(),\n types: [FunctionDef, FunctionTrigger, TestType],\n }),\n );\n\n testBuilder.ctx.onDispose(() => Promise.all(clients.map((client) => client.destroy())));\n return Promise.all(\n clients.map(async (client, index) => {\n await client.initialize();\n await client.halo.createIdentity({ displayName: `Peer ${index}` });\n await client.spaces.waitUntilReady();\n return client;\n }),\n );\n};\n\nexport const createFunctionRuntime = async (\n testBuilder: TestBuilder,\n pluginInitializer: FunctionsPluginInitializer,\n): Promise<Client> => {\n const functionsPort = await getRandomPort('127.0.0.1');\n const config = new Config({\n runtime: {\n agent: {\n plugins: [{ id: 'dxos.org/agent/plugin/functions', config: { port: functionsPort } }],\n },\n },\n });\n\n const [client] = await createInitializedClients(testBuilder, 1, config);\n const plugin = await pluginInitializer(client);\n testBuilder.ctx.onDispose(() => plugin.close());\n return client;\n};\n\nexport const startFunctionsHost = async (\n testBuilder: TestBuilder,\n pluginInitializer: FunctionsPluginInitializer,\n options?: DevServerOptions,\n) => {\n const functionRuntime = await createFunctionRuntime(testBuilder, pluginInitializer);\n const functionsRegistry = new FunctionRegistry(functionRuntime);\n const devServer = await startDevServer(testBuilder, functionRuntime, functionsRegistry, options);\n const scheduler = await startScheduler(testBuilder, functionRuntime, devServer, functionsRegistry);\n return {\n scheduler,\n client: functionRuntime,\n waitForActiveTriggers: async (space: Space) => {\n await waitForCondition({ condition: () => scheduler.triggers.getActiveTriggers(space).length > 0 });\n },\n };\n};\n\nconst startScheduler = async (\n testBuilder: TestBuilder,\n client: Client,\n devServer: DevServer,\n functionRegistry: FunctionRegistry,\n) => {\n const triggerRegistry = new TriggerRegistry(client);\n const scheduler = new Scheduler(functionRegistry, triggerRegistry, { endpoint: devServer.endpoint });\n await scheduler.start();\n testBuilder.ctx.onDispose(() => scheduler.stop());\n return scheduler;\n};\n\nconst startDevServer = async (\n testBuilder: TestBuilder,\n client: Client,\n functionRegistry: FunctionRegistry,\n options?: { baseDir?: string },\n) => {\n const server = new DevServer(client, functionRegistry, {\n baseDir: path.join(__dirname, '../testing'),\n port: await getRandomPort('127.0.0.1'),\n ...options,\n });\n await server.start();\n testBuilder.ctx.onDispose(() => server.stop());\n return server;\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { S, TypedObject } from '@dxos/echo-schema';\n\nexport class TestType extends TypedObject({ typename: 'example.com/type/Test', version: '0.1.0' })({\n title: S.String,\n}) {}\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport express from 'express';\nimport { getPort } from 'get-port-please';\nimport type http from 'http';\nimport { join } from 'node:path';\n\nimport { asyncTimeout, Event, Trigger } from '@dxos/async';\nimport { type Client } from '@dxos/client';\nimport { Context } from '@dxos/context';\nimport { invariant } from '@dxos/invariant';\nimport { log } from '@dxos/log';\n\nimport { type FunctionRegistry } from '../function';\nimport { type FunctionContext, type FunctionEvent, type FunctionHandler, type FunctionResponse } from '../handler';\nimport { type FunctionDef } from '../types';\n\nconst FN_TIMEOUT = 20_000;\n\nexport type DevServerOptions = {\n baseDir: string;\n port?: number;\n reload?: boolean;\n dataDir?: string;\n};\n\n/**\n * Functions dev server provides a local HTTP server for loading and invoking functions.\n * Functions are executed in the context of an authenticated client.\n */\nexport class DevServer {\n private _ctx = createContext();\n\n // Function handlers indexed by name (URL path).\n private readonly _handlers: Record<string, { def: FunctionDef; handler: FunctionHandler<any> }> = {};\n\n private _server?: http.Server;\n private _port?: number;\n private _functionServiceRegistration?: string;\n private _proxy?: string;\n private _seq = 0;\n\n public readonly update = new Event<number>();\n\n constructor(\n private readonly _client: Client,\n private readonly _functionsRegistry: FunctionRegistry,\n private readonly _options: DevServerOptions,\n ) {}\n\n get stats() {\n return {\n seq: this._seq,\n };\n }\n\n get endpoint() {\n invariant(this._port);\n return `http://localhost:${this._port}`;\n }\n\n get proxy() {\n return this._proxy;\n }\n\n get functions() {\n return Object.values(this._handlers);\n }\n\n async start() {\n invariant(!this._server);\n log.info('starting...');\n this._ctx = createContext();\n\n // TODO(burdon): Change to hono.\n const app = express();\n app.use(express.json());\n\n app.post('/:path', async (req, res) => {\n const { path } = req.params;\n try {\n log.info('calling', { path });\n if (this._options.reload) {\n const { def } = this._handlers['/' + path];\n await this._load(def, true);\n }\n\n // TODO(burdon): Get function context.\n res.statusCode = await asyncTimeout(this.invoke('/' + path, req.body), FN_TIMEOUT);\n res.end();\n } catch (err: any) {\n log.catch(err);\n res.statusCode = 500;\n res.end();\n }\n });\n\n this._port = this._options.port ?? (await getPort({ host: 'localhost', port: 7200, portRange: [7200, 7299] }));\n this._server = app.listen(this._port);\n\n try {\n // Register functions.\n const { registrationId, endpoint } = await this._client.services.services.FunctionRegistryService!.register({\n endpoint: this.endpoint,\n });\n\n log.info('registered', { endpoint });\n this._proxy = endpoint;\n this._functionServiceRegistration = registrationId;\n\n // Open after registration, so that it can be updated with the list of function definitions.\n await this._handleNewFunctions(this._functionsRegistry.getUniqueByUri());\n this._ctx.onDispose(this._functionsRegistry.registered.on(({ added }) => this._handleNewFunctions(added)));\n } catch (err: any) {\n await this.stop();\n throw new Error('FunctionRegistryService not available (check plugin is configured).');\n }\n\n log.info('started', { port: this._port });\n }\n\n async stop() {\n if (!this._server) {\n return;\n }\n\n log.info('stopping...');\n await this._ctx.dispose();\n\n const trigger = new Trigger();\n this._server.close(async () => {\n log.info('server stopped');\n try {\n if (this._functionServiceRegistration) {\n invariant(this._client.services.services.FunctionRegistryService);\n await this._client.services.services.FunctionRegistryService.unregister({\n registrationId: this._functionServiceRegistration,\n });\n\n log.info('unregistered', { registrationId: this._functionServiceRegistration });\n this._functionServiceRegistration = undefined;\n this._proxy = undefined;\n }\n\n trigger.wake();\n } catch (err) {\n trigger.throw(err as Error);\n }\n });\n\n await trigger.wait();\n this._port = undefined;\n this._server = undefined;\n log.info('stopped');\n }\n\n private async _handleNewFunctions(newFunctions: FunctionDef[]) {\n newFunctions.forEach((def) => this._load(def));\n await this._safeUpdateRegistration();\n log('new functions loaded', { newFunctions });\n }\n\n /**\n * Load function.\n */\n private async _load(def: FunctionDef, force?: boolean | undefined) {\n const { uri, route, handler } = def;\n const filePath = join(this._options.baseDir, handler);\n log.info('loading', { uri, force });\n\n // Remove from cache.\n if (force) {\n Object.keys(require.cache)\n .filter((key) => key.startsWith(filePath))\n .forEach((key) => {\n delete require.cache[key];\n });\n }\n\n // TODO(burdon): Import types.\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n const module = require(filePath);\n if (typeof module.default !== 'function') {\n throw new Error(`Handler must export default function: ${uri}`);\n }\n\n this._handlers[route] = { def, handler: module.default };\n }\n\n private async _safeUpdateRegistration(): Promise<void> {\n invariant(this._functionServiceRegistration);\n try {\n await this._client.services.services.FunctionRegistryService!.updateRegistration({\n registrationId: this._functionServiceRegistration,\n functions: this.functions.map(({ def: { id, route } }) => ({ id, route })),\n });\n } catch (err) {\n log.catch(err);\n }\n }\n\n /**\n * Invoke function.\n */\n public async invoke(path: string, data: any): Promise<number> {\n const seq = ++this._seq;\n const now = Date.now();\n\n log.info('req', { seq, path });\n const statusCode = await this._invoke(path, { data });\n\n log.info('res', { seq, path, statusCode, duration: Date.now() - now });\n this.update.emit(statusCode);\n return statusCode;\n }\n\n private async _invoke(path: string, event: FunctionEvent) {\n const { handler } = this._handlers[path] ?? {};\n invariant(handler, `invalid path: ${path}`);\n const context: FunctionContext = {\n client: this._client,\n dataDir: this._options.dataDir,\n } as any;\n\n let statusCode = 200;\n const response: FunctionResponse = {\n status: (code: number) => {\n statusCode = code;\n return response;\n },\n };\n\n await handler({ context, event, response });\n return statusCode;\n }\n}\n\nconst createContext = () => new Context({ name: 'DevServer' });\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport path from 'node:path';\n\nimport { Mutex } from '@dxos/async';\nimport { loadObjectReferences, type Space } from '@dxos/client/echo';\nimport { Context } from '@dxos/context';\nimport { Reference } from '@dxos/echo-protocol';\nimport { log } from '@dxos/log';\n\nimport { type FunctionRegistry } from '../function';\nimport { type FunctionEventMeta } from '../handler';\nimport { type TriggerCallback, type TriggerRegistry } from '../trigger';\nimport { type FunctionDef, type FunctionManifest, type FunctionTrigger } from '../types';\n\nexport type Callback = (data: any) => Promise<void | number>;\n\nexport type SchedulerOptions = {\n endpoint?: string;\n callback?: Callback;\n};\n\n/**\n * The scheduler triggers function execution based on various trigger configurations.\n * Functions are scheduled within the context of a specific space.\n */\nexport class Scheduler {\n private _ctx = createContext();\n\n private readonly _functionUriToCallMutex = new Map<string, Mutex>();\n\n constructor(\n public readonly functions: FunctionRegistry,\n public readonly triggers: TriggerRegistry,\n private readonly _options: SchedulerOptions = {},\n ) {\n this.functions.registered.on(async ({ space, added }) => {\n await this._safeActivateTriggers(space, this.triggers.getInactiveTriggers(space), added);\n });\n this.triggers.registered.on(async ({ space, triggers }) => {\n await this._safeActivateTriggers(space, triggers, this.functions.getFunctions(space));\n });\n }\n\n async start() {\n await this._ctx.dispose();\n this._ctx = createContext();\n await this.functions.open(this._ctx);\n await this.triggers.open(this._ctx);\n }\n\n async stop() {\n await this._ctx.dispose();\n await this.functions.close();\n await this.triggers.close();\n }\n\n // TODO(burdon): Remove and update registries directly?\n public async register(space: Space, manifest: FunctionManifest) {\n await this.functions.register(space, manifest.functions);\n await this.triggers.register(space, manifest);\n }\n\n private async _safeActivateTriggers(\n space: Space,\n triggers: FunctionTrigger[],\n functions: FunctionDef[],\n ): Promise<void> {\n const mountTasks = triggers.map((trigger) => {\n return this.activate(space, functions, trigger);\n });\n\n await Promise.all(mountTasks).catch(log.catch);\n }\n\n /**\n * Activate trigger.\n */\n // TODO(burdon): How are triggers deactivated?\n private async activate(space: Space, functions: FunctionDef[], trigger: FunctionTrigger) {\n const definition = functions.find((def) => def.uri === trigger.function);\n if (!definition) {\n log.info('function is not found for trigger', { trigger });\n return;\n }\n\n const execFunction: TriggerCallback = async (args) => {\n const mutex = this._functionUriToCallMutex.get(definition.uri) ?? new Mutex();\n this._functionUriToCallMutex.set(definition.uri, mutex);\n\n log.info('function triggered, waiting for mutex', { uri: definition.uri });\n return mutex.executeSynchronized(async () => {\n log.info('mutex acquired', { uri: definition.uri });\n\n // Load potential references in meta properties to serialize.\n await loadObjectReferences(trigger, (t) => Object.values(t.meta ?? {}));\n const meta: FunctionTrigger['meta'] = {};\n for (const [key, value] of Object.entries(trigger.meta ?? {})) {\n if (value instanceof Reference) {\n const object = await space.db.loadObjectById(value.objectId);\n if (object) {\n meta[key] = object;\n }\n } else {\n meta[key] = value;\n }\n }\n\n return this._execFunction(definition, trigger, {\n meta,\n data: { ...args, spaceKey: space.key },\n });\n });\n };\n\n await this.triggers.activate(space, trigger, execFunction);\n log('activated trigger', { space: space.key, trigger });\n }\n\n /**\n * Invoke function RPC.\n */\n private async _execFunction<TData, TMeta>(\n def: FunctionDef,\n trigger: FunctionTrigger,\n { meta, data }: { meta?: TMeta; data: TData },\n ): Promise<number> {\n let status = 0;\n try {\n // TODO(burdon): Pass in Space key (common context)?\n const payload = Object.assign({}, meta && ({ meta } satisfies FunctionEventMeta<TMeta>), data);\n\n const { endpoint, callback } = this._options;\n if (endpoint) {\n // TODO(burdon): Move out of scheduler (generalize as callback).\n const url = path.join(endpoint, def.route);\n log.info('exec', { function: def.uri, url, triggerType: trigger.spec.type });\n const response = await fetch(url, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify(payload),\n });\n\n status = response.status;\n } else if (callback) {\n log.info('exec', { function: def.uri });\n status = (await callback(payload)) ?? 200;\n }\n\n // Check errors.\n if (status && status >= 400) {\n throw new Error(`Response: ${status}`);\n }\n\n // const result = await response.json();\n log.info('done', { function: def.uri, status });\n } catch (err: any) {\n log.error('error', { function: def.uri, error: err.message });\n status = 500;\n }\n\n return status;\n }\n}\n\nconst createContext = () => new Context({ name: 'FunctionScheduler' });\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport type { Client } from '@dxos/client';\nimport { Filter, type Space } from '@dxos/client/echo';\nimport { performInvitation } from '@dxos/client/testing';\nimport { invariant } from '@dxos/invariant';\nimport { Invitation } from '@dxos/protocols/proto/dxos/client/services';\n\nimport { FunctionTrigger } from '../types';\n\nexport const triggerWebhook = async (space: Space, uri: string) => {\n const trigger = (\n await space.db.query(Filter.schema(FunctionTrigger, (t: FunctionTrigger) => t.function === uri)).run()\n ).objects[0];\n invariant(trigger.spec.type === 'webhook');\n void fetch(`http://localhost:${trigger.spec.port}`);\n};\n\nexport const inviteMember = async (host: Space, guest: Client) => {\n const [{ invitation: hostInvitation }] = await Promise.all(performInvitation({ host, guest: guest.spaces }));\n if (hostInvitation?.state !== Invitation.State.SUCCESS) {\n throw new Error(`Expected ${hostInvitation?.state} to be ${Invitation.State.SUCCESS}.`);\n }\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport type { FunctionManifest } from '../types';\n\nexport const testFunctionManifest: FunctionManifest = {\n functions: [\n {\n uri: 'example.com/function/test',\n route: 'test',\n handler: 'test',\n },\n ],\n};\n"],
5
- "mappings": ";;;;;;;;;;;;AAIA,SAASA,qBAAqB;AAC9B,OAAOC,WAAU;AAEjB,SAASC,wBAAwB;AACjC,SAASC,QAAQC,cAAc;AAG/B,SAASC,aAAa;;;ACPtB,SAASC,GAAGC,mBAAmB;AAExB,IAAMC,WAAN,cAAuBC,YAAY;EAAEC,UAAU;EAAyBC,SAAS;AAAQ,CAAA,EAAG;EACjGC,OAAOC,EAAEC;AACX,CAAA,EAAA;AAAI;;;ACJJ,OAAOC,aAAa;AACpB,SAASC,eAAe;AAExB,SAASC,YAAY;AAErB,SAASC,cAAcC,OAAOC,eAAe;AAE7C,SAASC,eAAe;AACxB,SAASC,iBAAiB;AAC1B,SAASC,WAAW;;AAMpB,IAAMC,aAAa;AAaZ,IAAMC,YAAN,MAAMA;EAcXC,YACmBC,SACAC,oBACAC,UACjB;SAHiBF,UAAAA;SACAC,qBAAAA;SACAC,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OAAOA,MAAMM;EAAO,CAAA,CAAA;AACzG,MAAIJ,gBAAgBK,UAAUC,WAAWC,MAAMC,SAAS;AACtD,UAAM,IAAIC,MAAM,YAAYT,gBAAgBK,KAAAA,UAAeC,WAAWC,MAAMC,OAAO,GAAG;EACxF;AACF;;;ACnBO,IAAME,uBAAyC;EACpDC,WAAW;IACT;MACEC,KAAK;MACLC,OAAO;MACPC,SAAS;IACX;;AAEJ;",
6
- "names": ["getRandomPort", "path", "waitForCondition", "Client", "Config", "range", "S", "TypedObject", "TestType", "TypedObject", "typename", "version", "title", "S", "String", "express", "getPort", "join", "asyncTimeout", "Event", "Trigger", "Context", "invariant", "log", "FN_TIMEOUT", "DevServer", "constructor", "_client", "_functionsRegistry", "_options", "_ctx", "createContext", "_handlers", "_seq", "update", "Event", "stats", "seq", "endpoint", "invariant", "_port", "proxy", "_proxy", "functions", "Object", "values", "start", "_server", "log", "info", "app", "express", "use", "json", "post", "req", "res", "path", "params", "reload", "def", "_load", "statusCode", "asyncTimeout", "invoke", "body", "end", "err", "catch", "port", "getPort", "host", "portRange", "listen", "registrationId", "services", "FunctionRegistryService", "register", "_functionServiceRegistration", "_handleNewFunctions", "getUniqueByUri", "onDispose", "registered", "on", "added", "stop", "Error", "dispose", "trigger", "Trigger", "close", "unregister", "undefined", "wake", "throw", "wait", "newFunctions", "forEach", "_safeUpdateRegistration", "force", "uri", "route", "handler", "filePath", "join", "baseDir", "keys", "require", "cache", "filter", "key", "startsWith", "module", "default", "updateRegistration", "map", "id", "data", "now", "Date", "_invoke", "duration", "emit", "event", "context", "client", "dataDir", "response", "status", "code", "Context", "name", "path", "Mutex", "loadObjectReferences", "Context", "Reference", "log", "Scheduler", "constructor", "functions", "triggers", "_options", "_ctx", "createContext", "_functionUriToCallMutex", "Map", "registered", "on", "space", "added", "_safeActivateTriggers", "getInactiveTriggers", "getFunctions", "start", "dispose", "open", "stop", "close", "register", "manifest", "mountTasks", "map", "trigger", "activate", "Promise", "all", "catch", "definition", "find", "def", "uri", "function", "info", "execFunction", "args", "mutex", "get", "set", "executeSynchronized", "t", "Object", "values", "meta", "key", "value", "entries", "object", "db", "loadObjectById", "objectId", "_execFunction", "data", "spaceKey", "status", "payload", "assign", "endpoint", "callback", "url", "join", "route", "triggerType", "spec", "type", "response", "fetch", "method", "headers", "body", "JSON", "stringify", "Error", "err", "error", "message", "name", "createInitializedClients", "testBuilder", "count", "config", "clients", "range", "map", "Client", "services", "createLocalClientServices", "types", "FunctionDef", "FunctionTrigger", "TestType", "ctx", "onDispose", "Promise", "all", "client", "destroy", "index", "initialize", "halo", "createIdentity", "displayName", "spaces", "waitUntilReady", "createFunctionRuntime", "pluginInitializer", "functionsPort", "getRandomPort", "Config", "runtime", "agent", "plugins", "id", "port", "plugin", "close", "startFunctionsHost", "options", "functionRuntime", "functionsRegistry", "FunctionRegistry", "devServer", "startDevServer", "scheduler", "startScheduler", "waitForActiveTriggers", "space", "waitForCondition", "condition", "triggers", "getActiveTriggers", "length", "functionRegistry", "triggerRegistry", "TriggerRegistry", "Scheduler", "endpoint", "start", "stop", "server", "DevServer", "baseDir", "path", "join", "__dirname", "Filter", "performInvitation", "invariant", "Invitation", "triggerWebhook", "space", "uri", "trigger", "db", "query", "Filter", "schema", "FunctionTrigger", "t", "function", "run", "objects", "invariant", "spec", "type", "fetch", "port", "inviteMember", "host", "guest", "invitation", "hostInvitation", "Promise", "all", "performInvitation", "spaces", "state", "Invitation", "State", "SUCCESS", "Error", "testFunctionManifest", "functions", "uri", "route", "handler"]
4
+ "sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport { getRandomPort } from 'get-port-please';\nimport path from 'node:path';\n\nimport { waitForCondition } from '@dxos/async';\nimport { Client, Config } from '@dxos/client';\nimport { type Space } from '@dxos/client/echo';\nimport { type TestBuilder } from '@dxos/client/testing';\nimport { range } from '@dxos/util';\n\nimport { TestType } from './types';\nimport { FunctionRegistry } from '../function';\nimport { DevServer, type DevServerOptions, Scheduler } from '../runtime';\nimport { TriggerRegistry } from '../trigger';\nimport { FunctionDef, FunctionTrigger } from '../types';\n\nexport type FunctionsPluginInitializer = (client: Client) => Promise<{ close: () => Promise<void> }>;\n\n// TODO(burdon): Extend/wrap TestBuilder.\n\nexport const createInitializedClients = async (testBuilder: TestBuilder, count: number = 1, config?: Config) => {\n const clients = range(count).map(\n () =>\n new Client({\n config,\n services: testBuilder.createLocalClientServices(),\n types: [FunctionDef, FunctionTrigger, TestType],\n }),\n );\n\n testBuilder.ctx.onDispose(() => Promise.all(clients.map((client) => client.destroy())));\n return Promise.all(\n clients.map(async (client, index) => {\n await client.initialize();\n await client.halo.createIdentity({ displayName: `Peer ${index}` });\n await client.spaces.waitUntilReady();\n return client;\n }),\n );\n};\n\nexport const createFunctionRuntime = async (\n testBuilder: TestBuilder,\n pluginInitializer: FunctionsPluginInitializer,\n): Promise<Client> => {\n const functionsPort = await getRandomPort('127.0.0.1');\n const config = new Config({\n runtime: {\n agent: {\n plugins: [{ id: 'dxos.org/agent/plugin/functions', config: { port: functionsPort } }],\n },\n },\n });\n\n const [client] = await createInitializedClients(testBuilder, 1, config);\n const plugin = await pluginInitializer(client);\n testBuilder.ctx.onDispose(() => plugin.close());\n return client;\n};\n\nexport const startFunctionsHost = async (\n testBuilder: TestBuilder,\n pluginInitializer: FunctionsPluginInitializer,\n options?: DevServerOptions,\n) => {\n const functionRuntime = await createFunctionRuntime(testBuilder, pluginInitializer);\n const functionsRegistry = new FunctionRegistry(functionRuntime);\n const devServer = await startDevServer(testBuilder, functionRuntime, functionsRegistry, options);\n const scheduler = await startScheduler(testBuilder, functionRuntime, devServer, functionsRegistry);\n return {\n scheduler,\n client: functionRuntime,\n waitForActiveTriggers: async (space: Space) => {\n await waitForCondition({ condition: () => scheduler.triggers.getActiveTriggers(space).length > 0 });\n },\n };\n};\n\nconst startScheduler = async (\n testBuilder: TestBuilder,\n client: Client,\n devServer: DevServer,\n functionRegistry: FunctionRegistry,\n) => {\n const triggerRegistry = new TriggerRegistry(client);\n const scheduler = new Scheduler(functionRegistry, triggerRegistry, { endpoint: devServer.endpoint });\n await scheduler.start();\n testBuilder.ctx.onDispose(() => scheduler.stop());\n return scheduler;\n};\n\nconst startDevServer = async (\n testBuilder: TestBuilder,\n client: Client,\n functionRegistry: FunctionRegistry,\n options?: { baseDir?: string },\n) => {\n const server = new DevServer(client, functionRegistry, {\n baseDir: path.join(__dirname, '../testing'),\n port: await getRandomPort('127.0.0.1'),\n ...options,\n });\n await server.start();\n testBuilder.ctx.onDispose(() => server.stop());\n return server;\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { S, TypedObject } from '@dxos/echo-schema';\n\nexport class TestType extends TypedObject({ typename: 'example.com/type/Test', version: '0.1.0' })({\n title: S.String,\n}) {}\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport express from 'express';\nimport { getPort } from 'get-port-please';\nimport type http from 'http';\nimport { join } from 'node:path';\n\nimport { asyncTimeout, Event, Trigger } from '@dxos/async';\nimport { type Client } from '@dxos/client';\nimport { Context } from '@dxos/context';\nimport { invariant } from '@dxos/invariant';\nimport { log } from '@dxos/log';\n\nimport { type FunctionRegistry } from '../function';\nimport { type FunctionContext, type FunctionEvent, type FunctionHandler, type FunctionResponse } from '../handler';\nimport { type FunctionDef } from '../types';\n\nconst FN_TIMEOUT = 20_000;\n\nexport type DevServerOptions = {\n baseDir: string;\n port?: number;\n reload?: boolean;\n dataDir?: string;\n};\n\n/**\n * Functions dev server provides a local HTTP server for loading and invoking functions.\n * Functions are executed in the context of an authenticated client.\n */\nexport class DevServer {\n private _ctx = createContext();\n\n // Function handlers indexed by name (URL path).\n private readonly _handlers: Record<string, { def: FunctionDef; handler: FunctionHandler<any> }> = {};\n\n private _server?: http.Server;\n private _port?: number;\n private _functionServiceRegistration?: string;\n private _proxy?: string;\n private _seq = 0;\n\n public readonly update = new Event<number>();\n\n constructor(\n private readonly _client: Client,\n private readonly _functionsRegistry: FunctionRegistry,\n private readonly _options: DevServerOptions,\n ) {}\n\n get stats() {\n return {\n seq: this._seq,\n };\n }\n\n get endpoint() {\n invariant(this._port);\n return `http://localhost:${this._port}`;\n }\n\n get proxy() {\n return this._proxy;\n }\n\n get functions() {\n return Object.values(this._handlers);\n }\n\n async start() {\n invariant(!this._server);\n log.info('starting...');\n this._ctx = createContext();\n\n // TODO(burdon): Change to hono.\n const app = express();\n app.use(express.json());\n\n app.post('/:path', async (req, res) => {\n const { path } = req.params;\n try {\n log.info('calling', { path });\n if (this._options.reload) {\n const { def } = this._handlers['/' + path];\n await this._load(def, true);\n }\n\n // TODO(burdon): Get function context.\n res.statusCode = await asyncTimeout(this.invoke('/' + path, req.body), FN_TIMEOUT);\n res.end();\n } catch (err: any) {\n log.catch(err);\n res.statusCode = 500;\n res.end();\n }\n });\n\n this._port = this._options.port ?? (await getPort({ host: 'localhost', port: 7200, portRange: [7200, 7299] }));\n this._server = app.listen(this._port);\n\n try {\n // Register functions.\n const { registrationId, endpoint } = await this._client.services.services.FunctionRegistryService!.register({\n endpoint: this.endpoint,\n });\n\n log.info('registered', { endpoint });\n this._proxy = endpoint;\n this._functionServiceRegistration = registrationId;\n\n // Open after registration, so that it can be updated with the list of function definitions.\n await this._handleNewFunctions(this._functionsRegistry.getUniqueByUri());\n this._ctx.onDispose(this._functionsRegistry.registered.on(({ added }) => this._handleNewFunctions(added)));\n } catch (err: any) {\n await this.stop();\n throw new Error('FunctionRegistryService not available (check plugin is configured).');\n }\n\n log.info('started', { port: this._port });\n }\n\n async stop() {\n if (!this._server) {\n return;\n }\n\n log.info('stopping...');\n await this._ctx.dispose();\n\n const trigger = new Trigger();\n this._server.close(async () => {\n log.info('server stopped');\n try {\n if (this._functionServiceRegistration) {\n invariant(this._client.services.services.FunctionRegistryService);\n await this._client.services.services.FunctionRegistryService.unregister({\n registrationId: this._functionServiceRegistration,\n });\n\n log.info('unregistered', { registrationId: this._functionServiceRegistration });\n this._functionServiceRegistration = undefined;\n this._proxy = undefined;\n }\n\n trigger.wake();\n } catch (err) {\n trigger.throw(err as Error);\n }\n });\n\n await trigger.wait();\n this._port = undefined;\n this._server = undefined;\n log.info('stopped');\n }\n\n private async _handleNewFunctions(newFunctions: FunctionDef[]) {\n newFunctions.forEach((def) => this._load(def));\n await this._safeUpdateRegistration();\n log('new functions loaded', { newFunctions });\n }\n\n /**\n * Load function.\n */\n private async _load(def: FunctionDef, force?: boolean | undefined) {\n const { uri, route, handler } = def;\n const filePath = join(this._options.baseDir, handler);\n log.info('loading', { uri, force });\n\n // Remove from cache.\n if (force) {\n Object.keys(require.cache)\n .filter((key) => key.startsWith(filePath))\n .forEach((key) => {\n delete require.cache[key];\n });\n }\n\n // TODO(burdon): Import types.\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n const module = require(filePath);\n if (typeof module.default !== 'function') {\n throw new Error(`Handler must export default function: ${uri}`);\n }\n\n this._handlers[route] = { def, handler: module.default };\n }\n\n private async _safeUpdateRegistration(): Promise<void> {\n invariant(this._functionServiceRegistration);\n try {\n await this._client.services.services.FunctionRegistryService!.updateRegistration({\n registrationId: this._functionServiceRegistration,\n functions: this.functions.map(({ def: { id, route } }) => ({ id, route })),\n });\n } catch (err) {\n log.catch(err);\n }\n }\n\n /**\n * Invoke function.\n */\n public async invoke(path: string, data: any): Promise<number> {\n const seq = ++this._seq;\n const now = Date.now();\n\n log.info('req', { seq, path });\n const statusCode = await this._invoke(path, { data });\n\n log.info('res', { seq, path, statusCode, duration: Date.now() - now });\n this.update.emit(statusCode);\n return statusCode;\n }\n\n private async _invoke(path: string, event: FunctionEvent) {\n const { handler } = this._handlers[path] ?? {};\n invariant(handler, `invalid path: ${path}`);\n const context: FunctionContext = {\n client: this._client,\n dataDir: this._options.dataDir,\n } as any;\n\n let statusCode = 200;\n const response: FunctionResponse = {\n status: (code: number) => {\n statusCode = code;\n return response;\n },\n };\n\n await handler({ context, event, response });\n return statusCode;\n }\n}\n\nconst createContext = () => new Context({ name: 'DevServer' });\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport path from 'node:path';\n\nimport { Mutex } from '@dxos/async';\nimport { loadObjectReferences, type Space } from '@dxos/client/echo';\nimport { Context } from '@dxos/context';\nimport { Reference } from '@dxos/echo-protocol';\nimport { log } from '@dxos/log';\n\nimport { type FunctionRegistry } from '../function';\nimport { type FunctionEventMeta } from '../handler';\nimport { type TriggerCallback, type TriggerRegistry } from '../trigger';\nimport { type FunctionDef, type FunctionManifest, type FunctionTrigger } from '../types';\n\nexport type Callback = (data: any) => Promise<void | number>;\n\nexport type SchedulerOptions = {\n endpoint?: string;\n callback?: Callback;\n};\n\n/**\n * The scheduler triggers function execution based on various trigger configurations.\n * Functions are scheduled within the context of a specific space.\n */\nexport class Scheduler {\n private _ctx = createContext();\n\n private readonly _functionUriToCallMutex = new Map<string, Mutex>();\n\n constructor(\n public readonly functions: FunctionRegistry,\n public readonly triggers: TriggerRegistry,\n private readonly _options: SchedulerOptions = {},\n ) {\n this.functions.registered.on(async ({ space, added }) => {\n await this._safeActivateTriggers(space, this.triggers.getInactiveTriggers(space), added);\n });\n this.triggers.registered.on(async ({ space, triggers }) => {\n await this._safeActivateTriggers(space, triggers, this.functions.getFunctions(space));\n });\n }\n\n async start() {\n await this._ctx.dispose();\n this._ctx = createContext();\n await this.functions.open(this._ctx);\n await this.triggers.open(this._ctx);\n }\n\n async stop() {\n await this._ctx.dispose();\n await this.functions.close();\n await this.triggers.close();\n }\n\n // TODO(burdon): Remove and update registries directly?\n public async register(space: Space, manifest: FunctionManifest) {\n await this.functions.register(space, manifest.functions);\n await this.triggers.register(space, manifest);\n }\n\n private async _safeActivateTriggers(\n space: Space,\n triggers: FunctionTrigger[],\n functions: FunctionDef[],\n ): Promise<void> {\n const mountTasks = triggers.map((trigger) => {\n return this.activate(space, functions, trigger);\n });\n\n await Promise.all(mountTasks).catch(log.catch);\n }\n\n /**\n * Activate trigger.\n */\n // TODO(burdon): How are triggers deactivated?\n private async activate(space: Space, functions: FunctionDef[], trigger: FunctionTrigger) {\n const definition = functions.find((def) => def.uri === trigger.function);\n if (!definition) {\n log.info('function is not found for trigger', { trigger });\n return;\n }\n\n const execFunction: TriggerCallback = async (args) => {\n const mutex = this._functionUriToCallMutex.get(definition.uri) ?? new Mutex();\n this._functionUriToCallMutex.set(definition.uri, mutex);\n\n log.info('function triggered, waiting for mutex', { uri: definition.uri });\n return mutex.executeSynchronized(async () => {\n log.info('mutex acquired', { uri: definition.uri });\n\n // Load potential references in meta properties to serialize.\n await loadObjectReferences(trigger, (t) => Object.values(t.meta ?? {}));\n const meta: FunctionTrigger['meta'] = {};\n for (const [key, value] of Object.entries(trigger.meta ?? {})) {\n if (value instanceof Reference) {\n const object = await space.db.loadObjectById(value.objectId);\n if (object) {\n meta[key] = object;\n }\n } else {\n meta[key] = value;\n }\n }\n\n return this._execFunction(definition, trigger, {\n meta,\n data: { ...args, spaceKey: space.key },\n });\n });\n };\n\n await this.triggers.activate(space, trigger, execFunction);\n log('activated trigger', { space: space.key, trigger });\n }\n\n /**\n * Invoke function RPC.\n */\n private async _execFunction<TData, TMeta>(\n def: FunctionDef,\n trigger: FunctionTrigger,\n { meta, data }: { meta?: TMeta; data: TData },\n ): Promise<number> {\n let status = 0;\n try {\n // TODO(burdon): Pass in Space key (common context)?\n const payload = Object.assign({}, meta && ({ meta } satisfies FunctionEventMeta<TMeta>), data);\n\n const { endpoint, callback } = this._options;\n if (endpoint) {\n // TODO(burdon): Move out of scheduler (generalize as callback).\n const url = path.join(endpoint, def.route);\n log.info('exec', { function: def.uri, url, triggerType: trigger.spec?.type });\n const response = await fetch(url, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify(payload),\n });\n\n status = response.status;\n } else if (callback) {\n log.info('exec', { function: def.uri });\n status = (await callback(payload)) ?? 200;\n }\n\n // Check errors.\n if (status && status >= 400) {\n throw new Error(`Response: ${status}`);\n }\n\n // const result = await response.json();\n log.info('done', { function: def.uri, status });\n } catch (err: any) {\n log.error('error', { function: def.uri, error: err.message });\n status = 500;\n }\n\n return status;\n }\n}\n\nconst createContext = () => new Context({ name: 'FunctionScheduler' });\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport type { Client } from '@dxos/client';\nimport { Filter, type Space } from '@dxos/client/echo';\nimport { performInvitation } from '@dxos/client/testing';\nimport { invariant } from '@dxos/invariant';\nimport { Invitation } from '@dxos/protocols/proto/dxos/client/services';\n\nimport { FunctionTrigger } from '../types';\n\nexport const triggerWebhook = async (space: Space, uri: string) => {\n const trigger = (\n await space.db.query(Filter.schema(FunctionTrigger, (trigger: FunctionTrigger) => trigger.function === uri)).run()\n ).objects[0];\n invariant(trigger.spec?.type === 'webhook');\n void fetch(`http://localhost:${trigger.spec.port}`);\n};\n\nexport const inviteMember = async (host: Space, guest: Client) => {\n const [{ invitation: hostInvitation }] = await Promise.all(performInvitation({ host, guest: guest.spaces }));\n if (hostInvitation?.state !== Invitation.State.SUCCESS) {\n throw new Error(`Expected ${hostInvitation?.state} to be ${Invitation.State.SUCCESS}.`);\n }\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport type { FunctionManifest } from '../types';\n\nexport const testFunctionManifest: FunctionManifest = {\n functions: [\n {\n uri: 'example.com/function/test',\n route: 'test',\n handler: 'test',\n },\n ],\n};\n"],
5
+ "mappings": ";;;;;;;;;;;;AAIA,SAASA,qBAAqB;AAC9B,OAAOC,WAAU;AAEjB,SAASC,wBAAwB;AACjC,SAASC,QAAQC,cAAc;AAG/B,SAASC,aAAa;;;ACPtB,SAASC,GAAGC,mBAAmB;AAExB,IAAMC,WAAN,cAAuBC,YAAY;EAAEC,UAAU;EAAyBC,SAAS;AAAQ,CAAA,EAAG;EACjGC,OAAOC,EAAEC;AACX,CAAA,EAAA;AAAI;;;ACJJ,OAAOC,aAAa;AACpB,SAASC,eAAe;AAExB,SAASC,YAAY;AAErB,SAASC,cAAcC,OAAOC,eAAe;AAE7C,SAASC,eAAe;AACxB,SAASC,iBAAiB;AAC1B,SAASC,WAAW;;AAMpB,IA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MAAaC,UAAAA;AAC9C,QAAM,CAAC,EAAEC,YAAYC,eAAc,CAAE,IAAI,MAAMC,QAAQC,IAAIC,kBAAkB;IAAEN;IAAMC,OAAOA,MAAMM;EAAO,CAAA,CAAA;AACzG,MAAIJ,gBAAgBK,UAAUC,WAAWC,MAAMC,SAAS;AACtD,UAAM,IAAIC,MAAM,YAAYT,gBAAgBK,KAAAA,UAAeC,WAAWC,MAAMC,OAAO,GAAG;EACxF;AACF;;;ACnBO,IAAME,uBAAyC;EACpDC,WAAW;IACT;MACEC,KAAK;MACLC,OAAO;MACPC,SAAS;IACX;;AAEJ;",
6
+ "names": ["getRandomPort", "path", "waitForCondition", "Client", "Config", "range", "S", "TypedObject", "TestType", "TypedObject", "typename", "version", "title", "S", "String", "express", "getPort", "join", "asyncTimeout", "Event", "Trigger", "Context", "invariant", "log", "FN_TIMEOUT", "DevServer", "constructor", "_client", "_functionsRegistry", "_options", "_ctx", "createContext", "_handlers", "_seq", "update", "Event", "stats", "seq", "endpoint", "invariant", "_port", "proxy", "_proxy", "functions", "Object", "values", "start", "_server", "log", "info", "app", "express", "use", "json", "post", "req", "res", "path", "params", "reload", "def", "_load", "statusCode", "asyncTimeout", "invoke", "body", "end", "err", "catch", "port", "getPort", "host", "portRange", "listen", "registrationId", "services", "FunctionRegistryService", "register", "_functionServiceRegistration", "_handleNewFunctions", "getUniqueByUri", "onDispose", "registered", "on", "added", "stop", "Error", "dispose", "trigger", "Trigger", "close", "unregister", "undefined", "wake", "throw", "wait", "newFunctions", "forEach", "_safeUpdateRegistration", "force", "uri", "route", "handler", "filePath", "join", "baseDir", "keys", "require", "cache", "filter", "key", "startsWith", "module", "default", "updateRegistration", "map", "id", "data", "now", "Date", "_invoke", "duration", "emit", "event", "context", "client", "dataDir", "response", "status", "code", "Context", "name", "path", "Mutex", "loadObjectReferences", "Context", "Reference", "log", "Scheduler", "constructor", "functions", "triggers", "_options", "_ctx", "createContext", "_functionUriToCallMutex", "Map", "registered", "on", "space", "added", "_safeActivateTriggers", "getInactiveTriggers", "getFunctions", "start", "dispose", "open", "stop", "close", "register", "manifest", "mountTasks", "map", "trigger", "activate", "Promise", "all", "catch", "definition", "find", "def", "uri", "function", "info", "execFunction", "args", "mutex", "get", "set", "executeSynchronized", "t", "Object", "values", "meta", "key", "value", "entries", "object", "db", "loadObjectById", "objectId", "_execFunction", "data", "spaceKey", "status", "payload", "assign", "endpoint", "callback", "url", "join", "route", "triggerType", "spec", "type", "response", "fetch", "method", "headers", "body", "JSON", "stringify", "Error", "err", "error", "message", "name", "createInitializedClients", "testBuilder", "count", "config", "clients", "range", "map", "Client", "services", "createLocalClientServices", "types", "FunctionDef", "FunctionTrigger", "TestType", "ctx", "onDispose", "Promise", "all", "client", "destroy", "index", "initialize", "halo", "createIdentity", "displayName", "spaces", "waitUntilReady", "createFunctionRuntime", "pluginInitializer", "functionsPort", "getRandomPort", "Config", "runtime", "agent", "plugins", "id", "port", "plugin", "close", "startFunctionsHost", "options", "functionRuntime", "functionsRegistry", "FunctionRegistry", "devServer", "startDevServer", "scheduler", "startScheduler", "waitForActiveTriggers", "space", "waitForCondition", "condition", "triggers", "getActiveTriggers", "length", "functionRegistry", "triggerRegistry", "TriggerRegistry", "Scheduler", "endpoint", "start", "stop", "server", "DevServer", "baseDir", "path", "join", "__dirname", "Filter", "performInvitation", "invariant", "Invitation", "triggerWebhook", "space", "uri", "trigger", "db", "query", "Filter", "schema", "FunctionTrigger", "function", "run", "objects", "invariant", "spec", "type", "fetch", "port", "inviteMember", "host", "guest", "invitation", "hostInvitation", "Promise", "all", "performInvitation", "spaces", "state", "Invitation", "State", "SUCCESS", "Error", "testFunctionManifest", "functions", "uri", "route", "handler"]
7
7
  }
@@ -1,14 +1,18 @@
1
1
  import "@dxos/node-std/globals";
2
2
  import {
3
- FUNCTION_SCHEMA,
3
+ FUNCTION_TYPES,
4
4
  FunctionDef,
5
5
  FunctionManifestSchema,
6
- FunctionTrigger
7
- } from "./chunk-7QJNOQ6N.mjs";
6
+ FunctionTrigger,
7
+ FunctionTriggerSchema,
8
+ TriggerSchema
9
+ } from "./chunk-FWIFI2MH.mjs";
8
10
  export {
9
- FUNCTION_SCHEMA,
11
+ FUNCTION_TYPES,
10
12
  FunctionDef,
11
13
  FunctionManifestSchema,
12
- FunctionTrigger
14
+ FunctionTrigger,
15
+ FunctionTriggerSchema,
16
+ TriggerSchema
13
17
  };
14
18
  //# sourceMappingURL=types.mjs.map
@@ -16,15 +16,17 @@ var __copyProps = (to, from, except, desc) => {
16
16
  return to;
17
17
  };
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var chunk_TNG3Z74V_exports = {};
20
- __export(chunk_TNG3Z74V_exports, {
21
- FUNCTION_SCHEMA: () => FUNCTION_SCHEMA,
19
+ var chunk_GKDHAWCP_exports = {};
20
+ __export(chunk_GKDHAWCP_exports, {
21
+ FUNCTION_TYPES: () => FUNCTION_TYPES,
22
22
  FunctionDef: () => FunctionDef,
23
23
  FunctionManifestSchema: () => FunctionManifestSchema,
24
24
  FunctionTrigger: () => FunctionTrigger,
25
+ FunctionTriggerSchema: () => FunctionTriggerSchema,
26
+ TriggerSchema: () => TriggerSchema,
25
27
  __require: () => __require
26
28
  });
27
- module.exports = __toCommonJS(chunk_TNG3Z74V_exports);
29
+ module.exports = __toCommonJS(chunk_GKDHAWCP_exports);
28
30
  var import_echo_schema = require("@dxos/echo-schema");
29
31
  var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
30
32
  get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
@@ -32,18 +34,24 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
32
34
  if (typeof require !== "undefined") return require.apply(this, arguments);
33
35
  throw Error('Dynamic require of "' + x + '" is not supported');
34
36
  });
37
+ var typeLiteralAnnotations = {
38
+ [import_echo_schema.AST.TitleAnnotationId]: "Type"
39
+ };
35
40
  var TimerTriggerSchema = import_echo_schema.S.Struct({
36
- type: import_echo_schema.S.Literal("timer"),
37
- cron: import_echo_schema.S.String
41
+ type: import_echo_schema.S.Literal("timer").annotations(typeLiteralAnnotations),
42
+ cron: import_echo_schema.S.NonEmptyString.annotations({
43
+ [import_echo_schema.AST.TitleAnnotationId]: "Cron",
44
+ [import_echo_schema.AST.ExamplesAnnotationId]: "0 0 * * *"
45
+ })
38
46
  }).pipe(import_echo_schema.S.mutable);
39
47
  var WebhookTriggerSchema = import_echo_schema.S.Struct({
40
- type: import_echo_schema.S.Literal("webhook"),
48
+ type: import_echo_schema.S.Literal("webhook").annotations(typeLiteralAnnotations),
41
49
  method: import_echo_schema.S.String,
42
50
  // Assigned port.
43
51
  port: import_echo_schema.S.optional(import_echo_schema.S.Number)
44
52
  }).pipe(import_echo_schema.S.mutable);
45
53
  var WebsocketTriggerSchema = import_echo_schema.S.Struct({
46
- type: import_echo_schema.S.Literal("websocket"),
54
+ type: import_echo_schema.S.Literal("websocket").annotations(typeLiteralAnnotations),
47
55
  url: import_echo_schema.S.String,
48
56
  init: import_echo_schema.S.optional(import_echo_schema.S.Record({
49
57
  key: import_echo_schema.S.String,
@@ -51,24 +59,58 @@ var WebsocketTriggerSchema = import_echo_schema.S.Struct({
51
59
  }))
52
60
  }).pipe(import_echo_schema.S.mutable);
53
61
  var QuerySchema = import_echo_schema.S.Struct({
54
- type: import_echo_schema.S.String,
62
+ type: import_echo_schema.S.optional(import_echo_schema.S.String.annotations({
63
+ [import_echo_schema.AST.TitleAnnotationId]: "Type"
64
+ })),
55
65
  props: import_echo_schema.S.optional(import_echo_schema.S.Record({
56
66
  key: import_echo_schema.S.String,
57
67
  value: import_echo_schema.S.Any
58
68
  }))
69
+ }).annotations({
70
+ [import_echo_schema.AST.TitleAnnotationId]: "Query"
59
71
  });
60
72
  var SubscriptionTriggerSchema = import_echo_schema.S.Struct({
61
- type: import_echo_schema.S.Literal("subscription"),
73
+ type: import_echo_schema.S.Literal("subscription").annotations(typeLiteralAnnotations),
62
74
  // TODO(burdon): Define query DSL (from ECHO). Reconcile with Table.Query.
63
- filter: import_echo_schema.S.Array(QuerySchema),
75
+ filter: QuerySchema,
64
76
  options: import_echo_schema.S.optional(import_echo_schema.S.Struct({
65
77
  // Watch changes to object (not just creation).
66
- deep: import_echo_schema.S.optional(import_echo_schema.S.Boolean),
78
+ deep: import_echo_schema.S.optional(import_echo_schema.S.Boolean.annotations({
79
+ [import_echo_schema.AST.TitleAnnotationId]: "Nested"
80
+ })),
67
81
  // Debounce changes (delay in ms).
68
- delay: import_echo_schema.S.optional(import_echo_schema.S.Number)
82
+ delay: import_echo_schema.S.optional(import_echo_schema.S.Number.annotations({
83
+ [import_echo_schema.AST.TitleAnnotationId]: "Delay"
84
+ }))
85
+ }).annotations({
86
+ [import_echo_schema.AST.TitleAnnotationId]: "Options"
69
87
  }))
70
88
  }).pipe(import_echo_schema.S.mutable);
71
- var TriggerSpecSchema = import_echo_schema.S.Union(TimerTriggerSchema, WebhookTriggerSchema, WebsocketTriggerSchema, SubscriptionTriggerSchema);
89
+ var TriggerSchema = import_echo_schema.S.Union(TimerTriggerSchema, WebhookTriggerSchema, WebsocketTriggerSchema, SubscriptionTriggerSchema).annotations({
90
+ [import_echo_schema.AST.TitleAnnotationId]: "Trigger"
91
+ });
92
+ var FunctionTriggerSchema = import_echo_schema.S.Struct({
93
+ // TODO(burdon): What type does this reference.
94
+ function: import_echo_schema.S.optional(import_echo_schema.S.String.annotations({
95
+ [import_echo_schema.AST.TitleAnnotationId]: "Function"
96
+ })),
97
+ enabled: import_echo_schema.S.optional(import_echo_schema.S.Boolean.annotations({
98
+ [import_echo_schema.AST.TitleAnnotationId]: "Enabled"
99
+ })),
100
+ // TODO(burdon): Flatten?
101
+ spec: import_echo_schema.S.optional(TriggerSchema),
102
+ // TODO(burdon): Get meta from function.
103
+ // The `meta` property is merged into the event data passed to the function.
104
+ meta: import_echo_schema.S.optional(import_echo_schema.S.mutable(import_echo_schema.S.Record({
105
+ key: import_echo_schema.S.String,
106
+ value: import_echo_schema.S.Any
107
+ })))
108
+ });
109
+ var FunctionTrigger = class extends (0, import_echo_schema.TypedObject)({
110
+ typename: "dxos.org/type/FunctionTrigger",
111
+ version: "0.1.0"
112
+ })(FunctionTriggerSchema.fields) {
113
+ };
72
114
  var FunctionDef = class extends (0, import_echo_schema.TypedObject)({
73
115
  typename: "dxos.org/type/FunctionDef",
74
116
  version: "0.1.0"
@@ -79,37 +121,22 @@ var FunctionDef = class extends (0, import_echo_schema.TypedObject)({
79
121
  handler: import_echo_schema.S.String
80
122
  }) {
81
123
  };
82
- var FunctionTrigger = class extends (0, import_echo_schema.TypedObject)({
83
- typename: "dxos.org/type/FunctionTrigger",
84
- version: "0.1.0"
85
- })({
86
- name: import_echo_schema.S.optional(import_echo_schema.S.String),
87
- enabled: import_echo_schema.S.optional(import_echo_schema.S.Boolean),
88
- function: import_echo_schema.S.String.pipe(import_echo_schema.S.annotations({
89
- description: "Function URI."
90
- })),
91
- // The `meta` property is merged into the event data passed to the function.
92
- meta: import_echo_schema.S.optional(import_echo_schema.S.mutable(import_echo_schema.S.Record({
93
- key: import_echo_schema.S.String,
94
- value: import_echo_schema.S.Any
95
- }))),
96
- spec: TriggerSpecSchema
97
- }) {
98
- };
99
124
  var FunctionManifestSchema = import_echo_schema.S.Struct({
100
125
  functions: import_echo_schema.S.optional(import_echo_schema.S.mutable(import_echo_schema.S.Array((0, import_echo_schema.RawObject)(FunctionDef)))),
101
126
  triggers: import_echo_schema.S.optional(import_echo_schema.S.mutable(import_echo_schema.S.Array((0, import_echo_schema.RawObject)(FunctionTrigger))))
102
127
  });
103
- var FUNCTION_SCHEMA = [
128
+ var FUNCTION_TYPES = [
104
129
  FunctionDef,
105
130
  FunctionTrigger
106
131
  ];
107
132
  // Annotate the CommonJS export names for ESM import in node:
108
133
  0 && (module.exports = {
109
- FUNCTION_SCHEMA,
134
+ FUNCTION_TYPES,
110
135
  FunctionDef,
111
136
  FunctionManifestSchema,
112
137
  FunctionTrigger,
138
+ FunctionTriggerSchema,
139
+ TriggerSchema,
113
140
  __require
114
141
  });
115
- //# sourceMappingURL=chunk-TNG3Z74V.cjs.map
142
+ //# sourceMappingURL=chunk-GKDHAWCP.cjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/types.ts"],
4
+ "sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { AST, RawObject, S, TypedObject } from '@dxos/echo-schema';\n\n/**\n * Type discriminator for TriggerType.\n * Every spec has a type field of type TriggerKind that we can use to understand which type we're working with.\n * https://www.typescriptlang.org/docs/handbook/2/narrowing.html#discriminated-unions\n */\nexport type TriggerKind = 'timer' | 'webhook' | 'websocket' | 'subscription';\n\n// TODO(burdon): Rename prop kind.\nconst typeLiteralAnnotations = { [AST.TitleAnnotationId]: 'Type' };\n\n/**\n * Cron timer.\n */\nconst TimerTriggerSchema = S.Struct({\n type: S.Literal('timer').annotations(typeLiteralAnnotations),\n cron: S.NonEmptyString.annotations({\n [AST.TitleAnnotationId]: 'Cron',\n [AST.ExamplesAnnotationId]: '0 0 * * *',\n }),\n}).pipe(S.mutable);\n\nexport type TimerTrigger = S.Schema.Type<typeof TimerTriggerSchema>;\n\n/**\n * Webhook.\n */\nconst WebhookTriggerSchema = S.Struct({\n type: S.Literal('webhook').annotations(typeLiteralAnnotations),\n method: S.String,\n // Assigned port.\n port: S.optional(S.Number),\n}).pipe(S.mutable);\n\nexport type WebhookTrigger = S.Schema.Type<typeof WebhookTriggerSchema>;\n\n/**\n * Websocket.\n * @deprecated\n */\nconst WebsocketTriggerSchema = S.Struct({\n type: S.Literal('websocket').annotations(typeLiteralAnnotations),\n url: S.String,\n init: S.optional(S.Record({ key: S.String, value: S.Any })),\n}).pipe(S.mutable);\n\nexport type WebsocketTrigger = S.Schema.Type<typeof WebsocketTriggerSchema>;\n\n// TODO(burdon): Use ECHO definition (from https://github.com/dxos/dxos/pull/8233).\nconst QuerySchema = S.Struct({\n type: S.optional(S.String.annotations({ [AST.TitleAnnotationId]: 'Type' })),\n props: S.optional(S.Record({ key: S.String, value: S.Any })),\n}).annotations({ [AST.TitleAnnotationId]: 'Query' });\n\n/**\n * Subscription.\n */\nconst SubscriptionTriggerSchema = S.Struct({\n type: S.Literal('subscription').annotations(typeLiteralAnnotations),\n // TODO(burdon): Define query DSL (from ECHO). Reconcile with Table.Query.\n filter: QuerySchema,\n options: S.optional(\n S.Struct({\n // Watch changes to object (not just creation).\n deep: S.optional(S.Boolean.annotations({ [AST.TitleAnnotationId]: 'Nested' })),\n // Debounce changes (delay in ms).\n delay: S.optional(S.Number.annotations({ [AST.TitleAnnotationId]: 'Delay' })),\n }).annotations({ [AST.TitleAnnotationId]: 'Options' }),\n ),\n}).pipe(S.mutable);\n\nexport type SubscriptionTrigger = S.Schema.Type<typeof SubscriptionTriggerSchema>;\n\n/**\n * Trigger schema (discriminated union).\n */\nexport const TriggerSchema = S.Union(\n TimerTriggerSchema,\n WebhookTriggerSchema,\n WebsocketTriggerSchema,\n SubscriptionTriggerSchema,\n).annotations({ [AST.TitleAnnotationId]: 'Trigger' });\n\nexport type TriggerType = S.Schema.Type<typeof TriggerSchema>;\n\n/**\n * Function trigger.\n */\nexport const FunctionTriggerSchema = S.Struct({\n // TODO(burdon): What type does this reference.\n function: S.optional(S.String.annotations({ [AST.TitleAnnotationId]: 'Function' })),\n enabled: S.optional(S.Boolean.annotations({ [AST.TitleAnnotationId]: 'Enabled' })),\n\n // TODO(burdon): Flatten?\n spec: S.optional(TriggerSchema),\n\n // TODO(burdon): Get meta from function.\n // The `meta` property is merged into the event data passed to the function.\n meta: S.optional(S.mutable(S.Record({ key: S.String, value: S.Any }))),\n});\n\nexport type FunctionTriggerType = S.Schema.Type<typeof FunctionTriggerSchema>;\n\n/**\n * Function trigger.\n */\nexport class FunctionTrigger extends TypedObject({\n typename: 'dxos.org/type/FunctionTrigger',\n version: '0.1.0',\n})(FunctionTriggerSchema.fields) {}\n\n/**\n * Function definition.\n * @deprecated (Use dxos.org/type/Function)\n */\n// TODO(burdon): Reconcile with FunctionType.\nexport class FunctionDef extends TypedObject({\n typename: 'dxos.org/type/FunctionDef',\n version: '0.1.0',\n})({\n uri: S.String,\n description: S.optional(S.String),\n route: S.String,\n handler: S.String,\n}) {}\n\n/**\n * Function manifest file.\n */\nexport const FunctionManifestSchema = S.Struct({\n functions: S.optional(S.mutable(S.Array(RawObject(FunctionDef)))),\n triggers: S.optional(S.mutable(S.Array(RawObject(FunctionTrigger)))),\n});\n\nexport type FunctionManifest = S.Schema.Type<typeof FunctionManifestSchema>;\n\nexport const FUNCTION_TYPES = [FunctionDef, FunctionTrigger];\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,yBAA+C;;;;;;;AAU/C,IAAMA,yBAAyB;EAAE,CAACC,uBAAIC,iBAAiB,GAAG;AAAO;AAKjE,IAAMC,qBAAqBC,qBAAEC,OAAO;EAClCC,MAAMF,qBAAEG,QAAQ,OAAA,EAASC,YAAYR,sBAAAA;EACrCS,MAAML,qBAAEM,eAAeF,YAAY;IACjC,CAACP,uBAAIC,iBAAiB,GAAG;IACzB,CAACD,uBAAIU,oBAAoB,GAAG;EAC9B,CAAA;AACF,CAAA,EAAGC,KAAKR,qBAAES,OAAO;AAOjB,IAAMC,uBAAuBV,qBAAEC,OAAO;EACpCC,MAAMF,qBAAEG,QAAQ,SAAA,EAAWC,YAAYR,sBAAAA;EACvCe,QAAQX,qBAAEY;;EAEVC,MAAMb,qBAAEc,SAASd,qBAAEe,MAAM;AAC3B,CAAA,EAAGP,KAAKR,qBAAES,OAAO;AAQjB,IAAMO,yBAAyBhB,qBAAEC,OAAO;EACtCC,MAAMF,qBAAEG,QAAQ,WAAA,EAAaC,YAAYR,sBAAAA;EACzCqB,KAAKjB,qBAAEY;EACPM,MAAMlB,qBAAEc,SAASd,qBAAEmB,OAAO;IAAEC,KAAKpB,qBAAEY;IAAQS,OAAOr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B,YAAY;IAAE,CAACP,uBAAIC,iBAAiB,GAAG;EAAU,CAAA,CAAA;;EAG/EsC,MAAMpC,qBAAEc,SAASiB,aAAAA;;;EAIjBM,MAAMrC,qBAAEc,SAASd,qBAAES,QAAQT,qBAAEmB,OAAO;IAAEC,KAAKpB,qBAAEY;IAAQS,OAAOrB,qBAAEsB;EAAI,CAAA,CAAA,CAAA;AACpE,CAAA;AAOO,IAAMgB,kBAAN,kBAA8BC,gCAAY;EAC/CC,UAAU;EACVC,SAAS;AACX,CAAA,EAAGR,sBAAsBS,MAAM,EAAA;AAAG;AAO3B,IAAMC,cAAN,kBAA0BJ,gCAAY;EAC3CC,UAAU;EACVC,SAAS;AACX,CAAA,EAAG;EACDG,KAAK5C,qBAAEY;EACPiC,aAAa7C,qBAAEc,SAASd,qBAAEY,MAAM;EAChCkC,OAAO9C,qBAAEY;EACTmC,SAAS/C,qBAAEY;AACb,CAAA,EAAA;AAAI;AAKG,IAAMoC,yBAAyBhD,qBAAEC,OAAO;EAC7CgD,WAAWjD,qBAAEc,SAASd,qBAAES,QAAQT,qBAAEkD,UAAMC,8BAAUR,WAAAA,CAAAA,CAAAA,CAAAA;EAClDS,UAAUpD,qBAAEc,SAASd,qBAAES,QAAQT,qBAAEkD,UAAMC,8BAAUb,eAAAA,CAAAA,CAAAA,CAAAA;AACnD,CAAA;AAIO,IAAMe,iBAAiB;EAACV;EAAaL;;",
6
+ "names": ["typeLiteralAnnotations", "AST", "TitleAnnotationId", "TimerTriggerSchema", "S", "Struct", "type", "Literal", "annotations", "cron", "NonEmptyString", "ExamplesAnnotationId", "pipe", "mutable", "WebhookTriggerSchema", "method", "String", "port", "optional", "Number", "WebsocketTriggerSchema", "url", "init", "Record", "key", "value", "Any", "QuerySchema", "props", "SubscriptionTriggerSchema", "filter", "options", "deep", "Boolean", "delay", "TriggerSchema", "Union", "FunctionTriggerSchema", "function", "enabled", "spec", "meta", "FunctionTrigger", "TypedObject", "typename", "version", "fields", "FunctionDef", "uri", "description", "route", "handler", "FunctionManifestSchema", "functions", "Array", "RawObject", "triggers", "FUNCTION_TYPES"]
7
+ }