@dxos/functions 0.5.3-main.3456876 → 0.5.3-main.3b535c7

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.
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/handler.ts", "../../../src/runtime/dev-server.ts", "../../../src/runtime/scheduler.ts", "../../../src/types.ts"],
4
- "sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { type Client, PublicKey } from '@dxos/client';\nimport { type Space } from '@dxos/client/echo';\nimport { type EchoReactiveObject } from '@dxos/echo-schema';\nimport { log } from '@dxos/log';\nimport { nonNullable } from '@dxos/util';\n\n// Lambda-like function definitions.\n// https://www.serverless.com/framework/docs/providers/aws/guide/serverless.yml/#functions\n// https://www.npmjs.com/package/aws-lambda\n// https://docs.aws.amazon.com/lambda/latest/dg/typescript-handler.html\n\n// TODO(burdon): No response?\nexport interface Response {\n status(code: number): Response;\n}\n\nexport interface FunctionContext {\n // TODO(burdon): Limit access to individual space.\n client: Client;\n // TODO(burdon): Replace with storage service abstraction.\n dataDir?: string;\n // Data passed to function invocation.\n data?: any;\n}\n\n// TODO(burdon): Model after http request. Ref Lambda/OpenFaaS.\nexport type FunctionHandler<T extends {}> = (params: {\n event: T;\n context: FunctionContext;\n response: Response;\n}) => Promise<Response | void>;\n\nexport type RawSubscriptionEvent = {\n spaceKey?: string;\n objects?: string[];\n};\n\nexport type SubscriptionEvent = {\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 */\nexport const subscriptionHandler = (\n handler: FunctionHandler<SubscriptionEvent>,\n): FunctionHandler<RawSubscriptionEvent> => {\n return ({ event, context, ...rest }) => {\n const { client } = context;\n const space = event.spaceKey ? client.spaces.get(PublicKey.from(event.spaceKey)) : undefined;\n const objects =\n space &&\n event.objects?.map<EchoReactiveObject<any> | undefined>((id) => space!.db.getObjectById(id)).filter(nonNullable);\n\n if (!!event.spaceKey && !space) {\n log.warn('invalid space', { event });\n } else {\n log.info('handler', { space: space?.key.truncate(), objects: objects?.length });\n }\n\n return handler({ event: { space, objects }, context, ...rest });\n };\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 { Event, Trigger } from '@dxos/async';\nimport { type Client } from '@dxos/client';\nimport { invariant } from '@dxos/invariant';\nimport { log } from '@dxos/log';\n\nimport { type FunctionContext, type FunctionHandler, type Response } from '../handler';\nimport { type FunctionDef, type FunctionManifest } from '../types';\n\nexport type DevServerOptions = {\n manifest: FunctionManifest;\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 testing functions.\n */\nexport class DevServer {\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 // prettier-ignore\n constructor(\n private readonly _client: Client,\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 initialize() {\n for (const def of this._options.manifest.functions) {\n try {\n await this._load(def);\n } catch (err) {\n log.error('parsing function (check manifest)', err);\n }\n }\n }\n\n async start() {\n invariant(!this._server);\n log.info('starting...');\n\n // TODO(burdon): Move 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 this.invoke('/' + path, req.body);\n res.end();\n } catch (err: any) {\n log.catch(err);\n res.statusCode = 500;\n res.end();\n }\n });\n\n this._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 functions: this.functions.map(({ def: { id, path } }) => ({ id, path })),\n });\n\n log.info('registered', { endpoint });\n this._proxy = endpoint;\n this._functionServiceRegistration = registrationId;\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 invariant(this._server);\n log.info('stopping...');\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 /**\n * Load function.\n */\n private async _load(def: FunctionDef, force = false) {\n const { id, path, handler } = def;\n const filePath = join(this._options.baseDir, handler);\n log.info('loading', { id, 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 // 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: ${id}`);\n }\n\n this._handlers[path] = { def, handler: module.default };\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: any) {\n const { handler } = this._handlers[path] ?? {};\n invariant(handler, `invalid path: ${path}`);\n\n const context: FunctionContext = {\n client: this._client,\n dataDir: this._options.dataDir,\n };\n\n let statusCode = 200;\n const response: Response = {\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", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { CronJob } from 'cron';\nimport { getPort } from 'get-port-please';\nimport http from 'node:http';\nimport path from 'node:path';\nimport WebSocket from 'ws';\n\nimport { TextV0Type } from '@braneframe/types';\nimport { debounce, DeferredTask, sleep, Trigger } from '@dxos/async';\nimport { type Client, type PublicKey } from '@dxos/client';\nimport { createSubscription, Filter, getAutomergeObjectCore, type Query, type Space } from '@dxos/client/echo';\nimport { Context } from '@dxos/context';\nimport { invariant } from '@dxos/invariant';\nimport { log } from '@dxos/log';\nimport { ComplexMap } from '@dxos/util';\n\nimport {\n type FunctionDef,\n type FunctionManifest,\n type FunctionTrigger,\n type SubscriptionTrigger,\n type TimerTrigger,\n type WebhookTrigger,\n type WebsocketTrigger,\n} 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 triggers.\n */\nexport class Scheduler {\n // Map of mounted functions.\n private readonly _mounts = new ComplexMap<\n { spaceKey: PublicKey; id: string },\n { ctx: Context; trigger: FunctionTrigger }\n >(({ spaceKey, id }) => `${spaceKey.toHex()}:${id}`);\n\n constructor(\n private readonly _client: Client,\n private readonly _manifest: FunctionManifest,\n private readonly _options: SchedulerOptions = {},\n ) {}\n\n get mounts() {\n return Array.from(this._mounts.values()).reduce<FunctionTrigger[]>((acc, { trigger }) => {\n acc.push(trigger);\n return acc;\n }, []);\n }\n\n async start() {\n this._client.spaces.subscribe(async (spaces) => {\n for (const space of spaces) {\n await space.waitUntilReady();\n for (const trigger of this._manifest.triggers ?? []) {\n await this.mount(new Context(), space, trigger);\n }\n }\n });\n }\n\n async stop() {\n for (const { id, spaceKey } of this._mounts.keys()) {\n await this.unmount(id, spaceKey);\n }\n }\n\n /**\n * Mount trigger.\n */\n private async mount(ctx: Context, space: Space, trigger: FunctionTrigger) {\n const key = { spaceKey: space.key, id: trigger.function };\n const def = this._manifest.functions.find((config) => config.id === trigger.function);\n invariant(def, `Function not found: ${trigger.function}`);\n\n // TODO(burdon): Currently supports only one trigger declaration per function.\n const exists = this._mounts.get(key);\n if (!exists) {\n this._mounts.set(key, { ctx, trigger });\n log('mount', { space: space.key, trigger });\n if (ctx.disposed) {\n return;\n }\n\n //\n // Triggers types.\n //\n\n if (trigger.timer) {\n await this._createTimer(ctx, space, def, trigger.timer);\n }\n\n if (trigger.webhook) {\n await this._createWebhook(ctx, space, def, trigger.webhook);\n }\n\n if (trigger.websocket) {\n await this._createWebsocket(ctx, space, def, trigger.websocket);\n }\n\n if (trigger.subscription) {\n await this._createSubscription(ctx, space, def, trigger.subscription);\n }\n }\n }\n\n private async unmount(id: string, spaceKey: PublicKey) {\n const key = { id, spaceKey };\n const { ctx } = this._mounts.get(key) ?? {};\n if (ctx) {\n this._mounts.delete(key);\n await ctx.dispose();\n }\n }\n\n // TODO(burdon): Pass in Space key (common context).\n private async _execFunction(def: FunctionDef, data: any): Promise<number> {\n try {\n let status = 0;\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.path);\n log.info('exec', { function: def.id, url });\n const response = await fetch(url, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify(data),\n });\n\n status = response.status;\n } else if (callback) {\n log.info('exec', { function: def.id });\n status = (await callback(data)) ?? 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.id, status });\n return status;\n } catch (err: any) {\n log.error('error', { function: def.id, error: err.message });\n return 500;\n }\n }\n\n //\n // Triggers\n //\n\n /**\n * Cron timer.\n */\n private async _createTimer(ctx: Context, space: Space, def: FunctionDef, trigger: TimerTrigger) {\n log.info('timer', { space: space.key, trigger });\n const { cron } = trigger;\n\n const task = new DeferredTask(ctx, async () => {\n await this._execFunction(def, { spaceKey: space.key });\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: 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 /**\n * Webhook.\n */\n private async _createWebhook(ctx: Context, space: Space, def: FunctionDef, trigger: WebhookTrigger) {\n log.info('webhook', { space: space.key, trigger });\n\n // TODO(burdon): Enable POST hook with payload.\n const server = http.createServer(async (req, res) => {\n if (req.method !== trigger.method) {\n res.statusCode = 405;\n return res.end();\n }\n\n res.statusCode = await this._execFunction(def, { spaceKey: space.key });\n res.end();\n });\n\n // TODO(burdon): Not used.\n // const DEF_PORT_RANGE = { min: 7500, max: 7599 };\n // const portRange = Object.assign({}, trigger.port, DEF_PORT_RANGE) as WebhookTrigger['port'];\n const port = await getPort({\n random: true,\n // portRange: [portRange!.min, portRange!.max],\n });\n\n // TODO(burdon): Update trigger object with actual port.\n server.listen(port, () => {\n log.info('started webhook', { port });\n trigger.port = port;\n });\n\n ctx.onDispose(() => {\n server.close();\n });\n }\n\n /**\n * Websocket.\n * NOTE: The port must be unique, so the same hook cannot be used for multiple spaces.\n */\n private async _createWebsocket(\n ctx: Context,\n space: Space,\n def: FunctionDef,\n trigger: WebsocketTrigger,\n options: {\n retryDelay: number;\n maxAttempts: number;\n } = {\n retryDelay: 2,\n maxAttempts: 5,\n },\n ) {\n log.info('websocket', { space: space.key, trigger });\n const { url } = trigger;\n\n let ws: WebSocket;\n for (let attempt = 1; attempt <= options.maxAttempts; attempt++) {\n const open = new Trigger<boolean>();\n\n ws = new WebSocket(url);\n Object.assign(ws, {\n onopen: () => {\n log.info('opened', { url });\n if (trigger.init) {\n ws.send(new TextEncoder().encode(JSON.stringify(trigger.init)));\n }\n\n open.wake(true);\n },\n\n // TODO(burdon): Config retry if server closes?\n onclose: (event) => {\n log.info('closed', { url, code: event.code });\n open.wake(false);\n },\n\n onerror: (event) => {\n log.catch(event.error, { url });\n },\n\n onmessage: async (event) => {\n try {\n const data = JSON.parse(new TextDecoder().decode(event.data as Uint8Array));\n await this._execFunction(def, { spaceKey: space.key, data });\n } catch (err) {\n log.catch(err, { url });\n }\n },\n } satisfies Partial<WebSocket>);\n\n const isOpen = await open.wait();\n if (isOpen) {\n break;\n } else {\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\n ctx.onDispose(() => {\n ws?.close();\n });\n }\n\n /**\n * ECHO subscription.\n */\n private async _createSubscription(ctx: Context, space: Space, def: FunctionDef, trigger: SubscriptionTrigger) {\n log.info('subscription', { space: space.key, trigger });\n const objectIds = new Set<string>();\n const task = new DeferredTask(ctx, async () => {\n await this._execFunction(def, { spaceKey: space.key, objects: Array.from(objectIds) });\n });\n\n // TODO(burdon): Don't fire initially.\n // TODO(burdon): Subscription is called THREE times.\n const subscriptions: (() => void)[] = [];\n const subscription = createSubscription(({ added, updated }) => {\n log.info('updated', { added: added.length, updated: updated.length });\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\n task.schedule();\n });\n\n subscriptions.push(() => subscription.unsubscribe());\n\n // TODO(burdon): Create queue. Only allow one invocation per trigger at a time?\n // TODO(burdon): Disable trigger if keeps failing.\n const { filter, options: { deep, delay } = {} } = trigger;\n const update = ({ objects }: Query) => {\n subscription.update(objects);\n\n // TODO(burdon): Hack to monitor changes to Document's text object.\n if (deep) {\n log.info('update', { objects: objects.length });\n for (const object of objects) {\n const content = object.content;\n if (content instanceof TextV0Type) {\n subscriptions.push(\n getAutomergeObjectCore(content).updates.on(debounce(() => subscription.update([object]), 1_000)),\n );\n }\n }\n }\n };\n\n // TODO(burdon): Is Filter.or implemented?\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 const query = space.db.query(Filter.or(filter.map(({ type, props }) => Filter.typename(type, props))));\n subscriptions.push(query.subscribe(delay ? debounce(update, delay) : update));\n\n ctx.onDispose(() => {\n subscriptions.forEach((unsubscribe) => unsubscribe());\n });\n }\n}\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport * as S from '@effect/schema/Schema';\n\nconst TimerTriggerSchema = S.struct({\n cron: S.string,\n});\n\nconst WebhookTriggerSchema = S.mutable(\n S.struct({\n method: S.string,\n // Assigned port.\n port: S.optional(S.number),\n }),\n);\n\nconst WebsocketTriggerSchema = S.struct({\n url: S.string,\n init: S.optional(S.record(S.string, S.any)),\n});\n\nconst SubscriptionTriggerSchema = S.struct({\n spaceKey: S.optional(S.string),\n // TODO(burdon): Define query DSL.\n filter: S.array(\n S.struct({\n type: S.string,\n props: S.optional(S.record(S.string, 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\nconst FunctionTriggerSchema = S.struct({\n function: S.string.pipe(S.description('Function ID/URI.')),\n\n // Context passed to function.\n context: S.optional(S.record(S.string, S.any)),\n\n // Triggers.\n timer: S.optional(TimerTriggerSchema),\n webhook: S.optional(WebhookTriggerSchema),\n websocket: S.optional(WebsocketTriggerSchema),\n subscription: S.optional(SubscriptionTriggerSchema),\n});\n\nexport type TimerTrigger = S.Schema.Type<typeof TimerTriggerSchema>;\nexport type WebhookTrigger = S.Schema.Type<typeof WebhookTriggerSchema>;\nexport type WebsocketTrigger = S.Schema.Type<typeof WebsocketTriggerSchema>;\nexport type SubscriptionTrigger = S.Schema.Type<typeof SubscriptionTriggerSchema>;\nexport type FunctionTrigger = S.Schema.Type<typeof FunctionTriggerSchema>;\n\n/**\n * Function definition.\n */\n// TODO(burdon): Name vs. path?\nconst FunctionDefSchema = S.struct({\n id: S.string,\n // name: S.string,\n description: S.optional(S.string),\n path: S.string,\n // TODO(burdon): NPM/GitHub/Docker/CF URL?\n handler: S.string,\n});\n\nexport type FunctionDef = S.Schema.Type<typeof FunctionDefSchema>;\n\n/**\n * Function manifest file.\n */\nexport const FunctionManifestSchema = S.struct({\n functions: S.mutable(S.array(FunctionDefSchema)),\n triggers: S.optional(S.mutable(S.array(FunctionTriggerSchema))),\n});\n\nexport type FunctionManifest = S.Schema.Type<typeof FunctionManifestSchema>;\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,oBAAuC;AAGvC,iBAAoB;AACpB,kBAA4B;ACJ5B,qBAAoB;AACpB,6BAAwB;AAExB,uBAAqB;AAErB,mBAA+B;AAE/B,uBAA0B;AAC1B,IAAAA,cAAoB;ACRpB,kBAAwB;AACxB,IAAAC,0BAAwB;AACxB,uBAAiB;AACjB,IAAAC,oBAAiB;AACjB,gBAAsB;AAEtB,mBAA2B;AAC3B,IAAAC,gBAAuD;AAEvD,kBAA2F;AAC3F,qBAAwB;AACxB,IAAAC,oBAA0B;AAC1B,IAAAJ,cAAoB;AACpB,IAAAK,eAA2B;ACb3B,QAAmB;;;;;;;;;AHoDZ,IAAMC,sBAAsB,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AM;EAC5B,CAAA,CAAA;AAEJ,CAAA;AAEA,IAAMO,wBAA0BZ,EAAAA,OAAO;EACrC1F,UAAY2F,EAAAA,OAAOY,KAAOC,EAAAA,YAAY,kBAAA,CAAA;;EAGtCjO,SAAWuN,EAAAA,SAAWG,EAAAA,OAASN,EAAAA,QAAUO,EAAAA,GAAG,CAAA;;EAG5C5F,OAASwF,EAAAA,SAASL,kBAAAA;EAClBjF,SAAWsF,EAAAA,SAASF,oBAAAA;EACpBlF,WAAaoF,EAAAA,SAASE,sBAAAA;EACtBpF,cAAgBkF,EAAAA,SAASK,yBAAAA;AAC3B,CAAA;AAYA,IAAMM,oBAAsBf,EAAAA,OAAO;EACjCvM,IAAMwM,EAAAA;;EAENa,aAAeV,EAAAA,SAAWH,EAAAA,MAAM;EAChC5J,MAAQ4J,EAAAA;;EAERtN,SAAWsN,EAAAA;AACb,CAAA;AAOO,IAAMe,yBAA2BhB,EAAAA,OAAO;EAC7C7K,WAAagL,EAAAA,QAAUO,EAAAA,MAAMK,iBAAAA,CAAAA;EAC7B9G,UAAYmG,EAAAA,SAAWD,EAAAA,QAAUO,EAAAA,MAAME,qBAAAA,CAAAA,CAAAA;AACzC,CAAA;",
6
- "names": ["import_log", "import_get_port_please", "import_node_path", "import_async", "import_invariant", "import_util", "subscriptionHandler", "handler", "event", "context", "rest", "client", "space", "spaceKey", "spaces", "get", "PublicKey", "from", "undefined", "objects", "map", "id", "db", "getObjectById", "filter", "nonNullable", "log", "warn", "info", "key", "truncate", "length", "DevServer", "constructor", "_client", "_options", "_handlers", "_seq", "update", "Event", "stats", "seq", "endpoint", "invariant", "_port", "proxy", "_proxy", "functions", "Object", "values", "initialize", "def", "manifest", "_load", "err", "error", "start", "_server", "app", "express", "use", "json", "post", "req", "res", "path", "params", "reload", "statusCode", "invoke", "body", "end", "catch", "getPort", "host", "port", "portRange", "listen", "registrationId", "services", "FunctionRegistryService", "register", "_functionServiceRegistration", "stop", "Error", "trigger", "Trigger", "close", "unregister", "wake", "throw", "wait", "force", "filePath", "join", "baseDir", "keys", "require", "cache", "startsWith", "forEach", "module", "default", "data", "now", "Date", "_invoke", "duration", "emit", "dataDir", "response", "status", "code", "Scheduler", "_manifest", "_mounts", "ComplexMap", "toHex", "mounts", "Array", "reduce", "acc", "push", "subscribe", "waitUntilReady", "triggers", "mount", "Context", "unmount", "ctx", "function", "find", "config", "exists", "set", "disposed", "timer", "_createTimer", "webhook", "_createWebhook", "websocket", "_createWebsocket", "subscription", "_createSubscription", "delete", "dispose", "_execFunction", "callback", "url", "fetch", "method", "headers", "JSON", "stringify", "message", "cron", "task", "DeferredTask", "last", "run", "job", "CronJob", "cronTime", "runOnInit", "onTick", "delta", "count", "schedule", "onDispose", "server", "http", "createServer", "random", "options", "retryDelay", "maxAttempts", "ws", "attempt", "open", "WebSocket", "assign", "onopen", "init", "send", "TextEncoder", "encode", "onclose", "onerror", "onmessage", "parse", "TextDecoder", "decode", "isOpen", "Math", "pow", "sleep", "objectIds", "Set", "subscriptions", "createSubscription", "added", "updated", "object", "add", "unsubscribe", "deep", "delay", "content", "TextV0Type", "getAutomergeObjectCore", "updates", "on", "debounce", "query", "Filter", "or", "type", "props", "typename", "TimerTriggerSchema", "struct", "string", "WebhookTriggerSchema", "mutable", "optional", "number", "WebsocketTriggerSchema", "record", "any", "SubscriptionTriggerSchema", "array", "boolean", "FunctionTriggerSchema", "pipe", "description", "FunctionDefSchema", "FunctionManifestSchema"]
4
+ "sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { type Client, PublicKey } from '@dxos/client';\nimport { type Space } from '@dxos/client/echo';\nimport { type EchoReactiveObject } from '@dxos/echo-schema';\nimport { log } from '@dxos/log';\nimport { nonNullable } from '@dxos/util';\n\n// TODO(burdon): Context?\n// Lambda-like function definitions.\n// See: https://www.serverless.com/framework/docs/providers/aws/guide/serverless.yml/#functions\n// https://www.npmjs.com/package/aws-lambda\n// https://docs.aws.amazon.com/lambda/latest/dg/typescript-handler.html\n\n// TODO(burdon): No response?\nexport interface Response {\n status(code: number): Response;\n}\n\n// TODO(burdon): Limit access to individual space?\nexport interface FunctionContext {\n client: Client;\n dataDir?: string;\n}\n\n// TODO(burdon): Model after http request. Ref Lambda/OpenFaaS.\n// https://docs.aws.amazon.com/lambda/latest/dg/typescript-handler.html\nexport type FunctionHandler<T extends {}> = (params: {\n event: T;\n context: FunctionContext;\n response: Response;\n}) => Promise<Response | void>;\n\nexport type FunctionSubscriptionEvent = {\n space?: string; // TODO(burdon): Convert to PublicKey.\n objects?: string[];\n};\n\n// TODO(burdon): ???\nexport type FunctionSubscriptionEvent2 = {\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 */\nexport const subscriptionHandler = (\n handler: FunctionHandler<FunctionSubscriptionEvent2>,\n): FunctionHandler<FunctionSubscriptionEvent> => {\n return ({ event, context, ...rest }) => {\n const { client } = context;\n const space = event.space ? client.spaces.get(PublicKey.from(event.space)) : undefined;\n const objects =\n space &&\n event.objects?.map<EchoReactiveObject<any> | undefined>((id) => space!.db.getObjectById(id)).filter(nonNullable);\n\n if (!!event.space && !space) {\n log.warn('invalid space', { event });\n } else {\n log.info('handler', { space: space?.key.truncate(), objects: objects?.length });\n }\n\n return handler({ event: { space, objects }, context, ...rest });\n };\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 { Trigger } from '@dxos/async';\nimport { type Client } from '@dxos/client';\nimport { invariant } from '@dxos/invariant';\nimport { log } from '@dxos/log';\n\nimport { type FunctionContext, type FunctionHandler, type Response } from '../handler';\nimport { type FunctionDef, type FunctionManifest } from '../types';\n\nexport type DevServerOptions = {\n port?: number;\n directory: string;\n manifest: FunctionManifest;\n reload?: boolean;\n dataDir?: string;\n};\n\n/**\n * Functions dev server provides a local HTTP server for testing functions.\n */\nexport class DevServer {\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 _registrationId?: string;\n private _proxy?: string;\n private _seq = 0;\n\n // prettier-ignore\n constructor(\n private readonly _client: Client,\n private readonly _options: DevServerOptions,\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 initialize() {\n for (const def of this._options.manifest.functions) {\n try {\n await this._load(def);\n } catch (err) {\n log.error('parsing function (check manifest)', err);\n }\n }\n }\n\n async start() {\n const app = express();\n app.use(express.json());\n\n app.post('/:name', async (req, res) => {\n const { name } = req.params;\n try {\n log.info('calling', { name });\n if (this._options.reload) {\n const { def } = this._handlers[name];\n await this._load(def, true);\n }\n\n res.statusCode = await this._invoke(name, req.body);\n res.end();\n } catch (err: any) {\n log.catch(err);\n res.statusCode = 500;\n res.end();\n }\n });\n\n this._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 functions: this.functions.map(({ def: { name } }) => ({ name })),\n });\n\n log.info('registered', { registrationId, endpoint });\n this._registrationId = registrationId;\n this._proxy = endpoint;\n } catch (err: any) {\n await this.stop();\n throw new Error('FunctionRegistryService not available (check plugin is configured).');\n }\n }\n\n async stop() {\n const trigger = new Trigger();\n this._server?.close(async () => {\n if (this._registrationId) {\n await this._client.services.services.FunctionRegistryService!.unregister({\n registrationId: this._registrationId,\n });\n\n log.info('unregistered', { registrationId: this._registrationId });\n this._registrationId = undefined;\n this._proxy = undefined;\n }\n\n trigger.wake();\n });\n\n await trigger.wait();\n this._port = undefined;\n this._server = undefined;\n }\n\n /**\n * Load function.\n */\n private async _load(def: FunctionDef, flush = false) {\n const { id, name, handler } = def;\n const path = join(this._options.directory, handler);\n log.info('loading', { id });\n\n // Remove from cache.\n if (flush) {\n Object.keys(require.cache)\n .filter((key) => key.startsWith(path))\n .forEach((key) => delete require.cache[key]);\n }\n\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n const module = require(path);\n if (typeof module.default !== 'function') {\n throw new Error(`Handler must export default function: ${id}`);\n }\n\n this._handlers[name] = { def, handler: module.default };\n }\n\n /**\n * Invoke function handler.\n */\n private async _invoke(name: string, event: any) {\n const seq = ++this._seq;\n const now = Date.now();\n\n log.info('req', { seq, name });\n const { handler } = this._handlers[name];\n\n const context: FunctionContext = {\n client: this._client,\n dataDir: this._options.dataDir,\n };\n\n let statusCode = 200;\n const response: Response = {\n status: (code: number) => {\n statusCode = code;\n return response;\n },\n };\n\n await handler({ context, event, response });\n log.info('res', { seq, name, statusCode, duration: Date.now() - now });\n\n return statusCode;\n }\n}\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { CronJob } from 'cron';\nimport http from 'node:http';\nimport WebSocket from 'ws';\n\nimport { TextV0Type } from '@braneframe/types';\nimport { debounce, DeferredTask, sleep, Trigger } from '@dxos/async';\nimport { type Client, type PublicKey } from '@dxos/client';\nimport { createSubscription, Filter, getAutomergeObjectCore, type Query, type Space } from '@dxos/client/echo';\nimport { Context } from '@dxos/context';\nimport { invariant } from '@dxos/invariant';\nimport { log } from '@dxos/log';\nimport { ComplexMap } from '@dxos/util';\n\nimport { type FunctionSubscriptionEvent } from '../handler';\nimport {\n type FunctionDef,\n type FunctionManifest,\n type FunctionTrigger,\n type SubscriptionTrigger,\n type TimerTrigger,\n type WebhookTrigger,\n type WebsocketTrigger,\n} from '../types';\n\ntype Callback = (data: FunctionSubscriptionEvent) => Promise<void>;\n\nexport type SchedulerOptions = {\n endpoint?: string;\n callback?: Callback;\n};\n\n/**\n * The scheduler triggers function exectuion based on various triggers.\n */\nexport class Scheduler {\n // Map of mounted functions.\n private readonly _mounts = new ComplexMap<\n { id: string; spaceKey: PublicKey },\n { ctx: Context; trigger: FunctionTrigger }\n >(({ id, spaceKey }) => `${spaceKey.toHex()}:${id}`);\n\n constructor(\n private readonly _client: Client,\n private readonly _manifest: FunctionManifest,\n private readonly _options: SchedulerOptions = {},\n ) {}\n\n async start() {\n this._client.spaces.subscribe(async (spaces) => {\n for (const space of spaces) {\n await space.waitUntilReady();\n for (const trigger of this._manifest.triggers ?? []) {\n await this.mount(new Context(), space, trigger);\n }\n }\n });\n }\n\n async stop() {\n for (const { id, spaceKey } of this._mounts.keys()) {\n await this.unmount(id, spaceKey);\n }\n }\n\n private async mount(ctx: Context, space: Space, trigger: FunctionTrigger) {\n const key = { id: trigger.function, spaceKey: space.key };\n const def = this._manifest.functions.find((config) => config.id === trigger.function);\n invariant(def, `Function not found: ${trigger.function}`);\n\n // TODO(burdon): Currently supports only one trigger declaration per function.\n const exists = this._mounts.get(key);\n if (!exists) {\n this._mounts.set(key, { ctx, trigger });\n log('mount', { space: space.key, trigger });\n if (ctx.disposed) {\n return;\n }\n\n //\n // Triggers types.\n //\n\n if (trigger.timer) {\n await this._createTimer(ctx, space, def, trigger.timer);\n }\n\n if (trigger.webhook) {\n await this._createWebhook(ctx, space, def, trigger.webhook);\n }\n\n if (trigger.websocket) {\n await this._createWebsocket(ctx, space, def, trigger.websocket);\n }\n\n if (trigger.subscription) {\n await this._createSubscription(ctx, space, def, trigger.subscription);\n }\n }\n }\n\n private async unmount(id: string, spaceKey: PublicKey) {\n const key = { id, spaceKey };\n const { ctx } = this._mounts.get(key) ?? {};\n if (ctx) {\n this._mounts.delete(key);\n await ctx.dispose();\n }\n }\n\n // TODO(burdon): Pass in Space key (common context).\n private async _execFunction(def: FunctionDef, data: any) {\n try {\n log.info('exec', { function: def.id });\n const { endpoint, callback } = this._options;\n if (endpoint) {\n // TODO(burdon): Move out of scheduler (generalize as callback).\n await fetch(`${this._options.endpoint}/${def.name}`, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify(data),\n });\n } else if (callback) {\n await callback(data);\n }\n\n // const result = await response.json();\n log.info('done', { function: def.id });\n } catch (err: any) {\n log.error('error', { function: def.id, error: err.message });\n }\n }\n\n //\n // Triggers\n //\n\n /**\n * Cron timer.\n */\n private async _createTimer(ctx: Context, space: Space, def: FunctionDef, trigger: TimerTrigger) {\n log.info('timer', { space: space.key, trigger });\n const { cron } = trigger;\n\n const task = new DeferredTask(ctx, async () => {\n await this._execFunction(def, { space: space.key });\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: 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 /**\n * Webhook.\n */\n private async _createWebhook(ctx: Context, space: Space, def: FunctionDef, trigger: WebhookTrigger) {\n log.info('webhook', { space: space.key, trigger });\n const { port } = trigger;\n\n // TODO(burdon): POST JSON.\n const server = http.createServer(async (req, res) => {\n await this._execFunction(def, { space: space.key });\n });\n\n server.listen(port, () => {\n log.info('started webhook', { port });\n });\n\n ctx.onDispose(() => {\n server.close();\n });\n }\n\n /**\n * Websocket.\n */\n private async _createWebsocket(\n ctx: Context,\n space: Space,\n def: FunctionDef,\n trigger: WebsocketTrigger,\n options: {\n retryDelay: number;\n maxAttempts: number;\n } = {\n retryDelay: 2,\n maxAttempts: 5,\n },\n ) {\n log.info('websocket', { space: space.key, trigger });\n const { url } = trigger;\n\n let ws: WebSocket;\n for (let attempt = 1; attempt <= options.maxAttempts; attempt++) {\n const open = new Trigger<boolean>();\n\n ws = new WebSocket(url);\n Object.assign(ws, {\n onopen: () => {\n log.info('opened', { url });\n if (trigger.init) {\n ws.send(new TextEncoder().encode(JSON.stringify(trigger.init)));\n }\n\n open.wake(true);\n },\n\n onclose: () => {\n log.info('closed', { url });\n open.wake(false);\n },\n\n onerror: (event) => {\n log.catch(event.error, { url });\n },\n\n onmessage: async (event) => {\n try {\n const data = JSON.parse(new TextDecoder().decode(event.data as Uint8Array));\n await this._execFunction(def, { space: space.key, data });\n } catch (err) {\n log.catch(err, { url });\n }\n },\n } satisfies Partial<WebSocket>);\n\n const isOpen = await open.wait();\n if (isOpen) {\n break;\n } else {\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\n ctx.onDispose(() => {\n ws?.close();\n });\n }\n\n /**\n * ECHO subscription.\n */\n private async _createSubscription(ctx: Context, space: Space, def: FunctionDef, trigger: SubscriptionTrigger) {\n log.info('subscription', { space: space.key, trigger });\n const objectIds = new Set<string>();\n const task = new DeferredTask(ctx, async () => {\n await this._execFunction(def, { space: space.key, objects: Array.from(objectIds) });\n });\n\n // TODO(burdon): Don't fire initially.\n // TODO(burdon): Subscription is called THREE times.\n const subscriptions: (() => void)[] = [];\n const subscription = createSubscription(({ added, updated }) => {\n log.info('updated', { added: added.length, updated: updated.length });\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\n task.schedule();\n });\n subscriptions.push(() => subscription.unsubscribe());\n\n // TODO(burdon): Create queue. Only allow one invocation per trigger at a time?\n // TODO(burdon): Disable trigger if keeps failing.\n const { filter, options: { deep, delay } = {} } = trigger;\n const update = ({ objects }: Query) => {\n subscription.update(objects);\n\n // TODO(burdon): Hack to monitor changes to Document's text object.\n if (deep) {\n log.info('update', { objects: objects.length });\n for (const object of objects) {\n const content = object.content;\n if (content instanceof TextV0Type) {\n subscriptions.push(\n getAutomergeObjectCore(content).updates.on(debounce(() => subscription.update([object]), 1_000)),\n );\n }\n }\n }\n };\n\n // TODO(burdon): Is Filter.or implemented?\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 const query = space.db.query(Filter.or(filter.map(({ type, props }) => Filter.typename(type, props))));\n subscriptions.push(query.subscribe(delay ? debounce(update, delay) : update));\n\n ctx.onDispose(() => {\n subscriptions.forEach((unsubscribe) => unsubscribe());\n });\n }\n}\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport * as S from '@effect/schema/Schema';\n\nconst TimerTriggerSchema = S.struct({\n cron: S.string,\n});\n\nconst WebhookTriggerSchema = S.struct({\n port: S.number,\n});\n\nconst WebsocketTriggerSchema = S.struct({\n url: S.string,\n init: S.optional(S.record(S.string, S.any)),\n});\n\nconst SubscriptionTriggerSchema = S.struct({\n spaceKey: S.optional(S.string),\n // TODO(burdon): Define query DSL.\n filter: S.array(\n S.struct({\n type: S.string,\n props: S.optional(S.record(S.string, 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\nconst FunctionTriggerSchema = S.struct({\n function: S.string.pipe(S.description('Function ID/URI.')),\n\n timer: S.optional(TimerTriggerSchema),\n webhook: S.optional(WebhookTriggerSchema),\n websocket: S.optional(WebsocketTriggerSchema),\n subscription: S.optional(SubscriptionTriggerSchema),\n});\n\nexport type TimerTrigger = S.Schema.Type<typeof TimerTriggerSchema>;\nexport type WebhookTrigger = S.Schema.Type<typeof WebhookTriggerSchema>;\nexport type WebsocketTrigger = S.Schema.Type<typeof WebsocketTriggerSchema>;\nexport type SubscriptionTrigger = S.Schema.Type<typeof SubscriptionTriggerSchema>;\nexport type FunctionTrigger = S.Schema.Type<typeof FunctionTriggerSchema>;\n\n/**\n * Function definition.\n */\n// TODO(burdon): Name vs. path?\nconst FunctionDefSchema = S.struct({\n id: S.string,\n description: S.optional(S.string),\n name: S.string,\n // TODO(burdon): NPM/GitHub URL?\n handler: S.string,\n});\n\nexport type FunctionDef = S.Schema.Type<typeof FunctionDefSchema>;\n\n/**\n * Function manifest file.\n */\nexport const FunctionManifestSchema = S.struct({\n functions: S.mutable(S.array(FunctionDefSchema)),\n triggers: S.mutable(S.array(FunctionTriggerSchema)),\n});\n\nexport type FunctionManifest = S.Schema.Type<typeof FunctionManifestSchema>;\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,oBAAuC;AAGvC,iBAAoB;AACpB,kBAA4B;ACJ5B,qBAAoB;AACpB,6BAAwB;AAExB,uBAAqB;AAErB,mBAAwB;AAExB,uBAA0B;AAC1B,IAAAA,cAAoB;ACRpB,kBAAwB;AACxB,uBAAiB;AACjB,gBAAsB;AAEtB,mBAA2B;AAC3B,IAAAC,gBAAuD;AAEvD,kBAA2F;AAC3F,qBAAwB;AACxB,IAAAC,oBAA0B;AAC1B,IAAAF,cAAoB;AACpB,IAAAG,eAA2B;ACX3B,QAAmB;;;;;;;;;AHoDZ,IAAMC,sBAAsB,CACjCC,YAAAA;AAEA,SAAO,CAAC,EAAEC,OAAOC,SAAS,GAAGC,KAAAA,MAAM;AACjC,UAAM,EAAEC,OAAM,IAAKF;AACnB,UAAMG,QAAQJ,MAAMI,QAAQD,OAAOE,OAAOC,IAAIC,wBAAUC,KAAKR,MAAMI,KAAK,CAAA,IAAKK;AAC7E,UAAMC,UACJN,SACAJ,MAAMU,SAASC,IAAyC,CAACC,OAAOR,MAAOS,GAAGC,cAAcF,EAAAA,CAAAA,EAAKG,OAAOC,uBAAAA;AAEtG,QAAI,CAAC,CAAChB,MAAMI,SAAS,CAACA,OAAO;AAC3Ba,qBAAIC,KAAK,iBAAiB;QAAElB;MAAM,GAAA;;;;;;IACpC,OAAO;AACLiB,qBAAIE,KAAK,WAAW;QAAEf,OAAOA,OAAOgB,IAAIC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AA,OAASL,EAAAA,QAAUM,EAAAA,GAAG,CAAA;EAC5C,CAAA,CAAA;EAEF1D,SAAWwD,EAAAA,SACPL,EAAAA,OAAO;;IAEPhB,MAAQqB,EAAAA,SAAWK,EAAAA,OAAO;;IAE1BzB,OAASoB,EAAAA,SAAWF,EAAAA,MAAM;EAC5B,CAAA,CAAA;AAEJ,CAAA;AAEA,IAAMQ,wBAA0BX,EAAAA,OAAO;EACrC7F,UAAY8F,EAAAA,OAAOW,KAAOC,EAAAA,YAAY,kBAAA,CAAA;EAEtCpG,OAAS4F,EAAAA,SAASN,kBAAAA;EAClBpF,SAAW0F,EAAAA,SAASH,oBAAAA;EACpBrF,WAAawF,EAAAA,SAASD,sBAAAA;EACtBrF,cAAgBsF,EAAAA,SAASG,yBAAAA;AAC3B,CAAA;AAYA,IAAMM,oBAAsBd,EAAAA,OAAO;EACjC/L,IAAMgM,EAAAA;EACNY,aAAeR,EAAAA,SAAWJ,EAAAA,MAAM;EAChCzJ,MAAQyJ,EAAAA;;EAER7M,SAAW6M,EAAAA;AACb,CAAA;AAOO,IAAMc,yBAA2Bf,EAAAA,OAAO;EAC7CzK,WAAayL,EAAAA,QAAUP,EAAAA,MAAMK,iBAAAA,CAAAA;EAC7BhH,UAAYkH,EAAAA,QAAUP,EAAAA,MAAME,qBAAAA,CAAAA;AAC9B,CAAA;",
6
+ "names": ["import_log", "import_async", "import_invariant", "import_util", "subscriptionHandler", "handler", "event", "context", "rest", "client", "space", "spaces", "get", "PublicKey", "from", "undefined", "objects", "map", "id", "db", "getObjectById", "filter", "nonNullable", "log", "warn", "info", "key", "truncate", "length", "DevServer", "constructor", "_client", "_options", "_handlers", "_seq", "endpoint", "invariant", "_port", "proxy", "_proxy", "functions", "Object", "values", "initialize", "def", "manifest", "_load", "err", "error", "start", "app", "express", "use", "json", "post", "req", "res", "name", "params", "reload", "statusCode", "_invoke", "body", "end", "catch", "getPort", "host", "port", "portRange", "_server", "listen", "registrationId", "services", "FunctionRegistryService", "register", "_registrationId", "stop", "Error", "trigger", "Trigger", "close", "unregister", "wake", "wait", "flush", "path", "join", "directory", "keys", "require", "cache", "startsWith", "forEach", "module", "default", "seq", "now", "Date", "dataDir", "response", "status", "code", "duration", "Scheduler", "_manifest", "_mounts", "ComplexMap", "spaceKey", "toHex", "subscribe", "waitUntilReady", "triggers", "mount", "Context", "unmount", "ctx", "function", "find", "config", "exists", "set", "disposed", "timer", "_createTimer", "webhook", "_createWebhook", "websocket", "_createWebsocket", "subscription", "_createSubscription", "delete", "dispose", "_execFunction", "data", "callback", "fetch", "method", "headers", "JSON", "stringify", "message", "cron", "task", "DeferredTask", "last", "run", "job", "CronJob", "cronTime", "runOnInit", "onTick", "delta", "count", "schedule", "onDispose", "server", "http", "createServer", "options", "retryDelay", "maxAttempts", "url", "ws", "attempt", "open", "WebSocket", "assign", "onopen", "init", "send", "TextEncoder", "encode", "onclose", "onerror", "onmessage", "parse", "TextDecoder", "decode", "isOpen", "Math", "pow", "sleep", "objectIds", "Set", "Array", "subscriptions", "createSubscription", "added", "updated", "object", "add", "push", "unsubscribe", "deep", "delay", "update", "content", "TextV0Type", "getAutomergeObjectCore", "updates", "on", "debounce", "query", "Filter", "or", "type", "props", "typename", "TimerTriggerSchema", "struct", "string", "WebhookTriggerSchema", "number", "WebsocketTriggerSchema", "optional", "record", "any", "SubscriptionTriggerSchema", "array", "boolean", "FunctionTriggerSchema", "pipe", "description", "FunctionDefSchema", "FunctionManifestSchema", "mutable"]
7
7
  }
@@ -1 +1 @@
1
- {"inputs":{"packages/core/functions/src/handler.ts":{"bytes":6222,"imports":[{"path":"@dxos/client","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"format":"esm"},"packages/core/functions/src/runtime/dev-server.ts":{"bytes":24275,"imports":[{"path":"express","kind":"import-statement","external":true},{"path":"get-port-please","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"packages/core/functions/src/runtime/scheduler.ts":{"bytes":42172,"imports":[{"path":"cron","kind":"import-statement","external":true},{"path":"get-port-please","kind":"import-statement","external":true},{"path":"node:http","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true},{"path":"ws","kind":"import-statement","external":true},{"path":"@braneframe/types","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/invariant","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"format":"esm"},"packages/core/functions/src/runtime/index.ts":{"bytes":566,"imports":[{"path":"packages/core/functions/src/runtime/dev-server.ts","kind":"import-statement","original":"./dev-server"},{"path":"packages/core/functions/src/runtime/scheduler.ts","kind":"import-statement","original":"./scheduler"}],"format":"esm"},"packages/core/functions/src/types.ts":{"bytes":7769,"imports":[{"path":"@effect/schema/Schema","kind":"import-statement","external":true}],"format":"esm"},"packages/core/functions/src/index.ts":{"bytes":630,"imports":[{"path":"packages/core/functions/src/handler.ts","kind":"import-statement","original":"./handler"},{"path":"packages/core/functions/src/runtime/index.ts","kind":"import-statement","original":"./runtime"},{"path":"packages/core/functions/src/types.ts","kind":"import-statement","original":"./types"}],"format":"esm"}},"outputs":{"packages/core/functions/dist/lib/node/index.cjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":37428},"packages/core/functions/dist/lib/node/index.cjs":{"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":"express","kind":"import-statement","external":true},{"path":"get-port-please","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"cron","kind":"import-statement","external":true},{"path":"get-port-please","kind":"import-statement","external":true},{"path":"node:http","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true},{"path":"ws","kind":"import-statement","external":true},{"path":"@braneframe/types","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/invariant","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"@effect/schema/Schema","kind":"import-statement","external":true}],"exports":["DevServer","FunctionManifestSchema","Scheduler","subscriptionHandler"],"entryPoint":"packages/core/functions/src/index.ts","inputs":{"packages/core/functions/src/handler.ts":{"bytesInOutput":1066},"packages/core/functions/src/index.ts":{"bytesInOutput":0},"packages/core/functions/src/runtime/dev-server.ts":{"bytesInOutput":6941},"packages/core/functions/src/runtime/index.ts":{"bytesInOutput":0},"packages/core/functions/src/runtime/scheduler.ts":{"bytesInOutput":10823},"packages/core/functions/src/types.ts":{"bytesInOutput":1498}},"bytes":21009}}}
1
+ {"inputs":{"packages/core/functions/src/handler.ts":{"bytes":6277,"imports":[{"path":"@dxos/client","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"format":"esm"},"packages/core/functions/src/runtime/dev-server.ts":{"bytes":19225,"imports":[{"path":"express","kind":"import-statement","external":true},{"path":"get-port-please","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"packages/core/functions/src/runtime/scheduler.ts":{"bytes":37601,"imports":[{"path":"cron","kind":"import-statement","external":true},{"path":"node:http","kind":"import-statement","external":true},{"path":"ws","kind":"import-statement","external":true},{"path":"@braneframe/types","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/invariant","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"format":"esm"},"packages/core/functions/src/runtime/index.ts":{"bytes":566,"imports":[{"path":"packages/core/functions/src/runtime/dev-server.ts","kind":"import-statement","original":"./dev-server"},{"path":"packages/core/functions/src/runtime/scheduler.ts","kind":"import-statement","original":"./scheduler"}],"format":"esm"},"packages/core/functions/src/types.ts":{"bytes":6957,"imports":[{"path":"@effect/schema/Schema","kind":"import-statement","external":true}],"format":"esm"},"packages/core/functions/src/index.ts":{"bytes":630,"imports":[{"path":"packages/core/functions/src/handler.ts","kind":"import-statement","original":"./handler"},{"path":"packages/core/functions/src/runtime/index.ts","kind":"import-statement","original":"./runtime"},{"path":"packages/core/functions/src/types.ts","kind":"import-statement","original":"./types"}],"format":"esm"}},"outputs":{"packages/core/functions/dist/lib/node/index.cjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":33210},"packages/core/functions/dist/lib/node/index.cjs":{"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":"express","kind":"import-statement","external":true},{"path":"get-port-please","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"cron","kind":"import-statement","external":true},{"path":"node:http","kind":"import-statement","external":true},{"path":"ws","kind":"import-statement","external":true},{"path":"@braneframe/types","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/invariant","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"@effect/schema/Schema","kind":"import-statement","external":true}],"exports":["DevServer","FunctionManifestSchema","Scheduler","subscriptionHandler"],"entryPoint":"packages/core/functions/src/index.ts","inputs":{"packages/core/functions/src/handler.ts":{"bytesInOutput":1057},"packages/core/functions/src/index.ts":{"bytesInOutput":0},"packages/core/functions/src/runtime/dev-server.ts":{"bytesInOutput":4983},"packages/core/functions/src/runtime/index.ts":{"bytesInOutput":0},"packages/core/functions/src/runtime/scheduler.ts":{"bytesInOutput":9707},"packages/core/functions/src/types.ts":{"bytesInOutput":1294}},"bytes":17722}}}
@@ -7,18 +7,17 @@ export interface Response {
7
7
  export interface FunctionContext {
8
8
  client: Client;
9
9
  dataDir?: string;
10
- data?: any;
11
10
  }
12
11
  export type FunctionHandler<T extends {}> = (params: {
13
12
  event: T;
14
13
  context: FunctionContext;
15
14
  response: Response;
16
15
  }) => Promise<Response | void>;
17
- export type RawSubscriptionEvent = {
18
- spaceKey?: string;
16
+ export type FunctionSubscriptionEvent = {
17
+ space?: string;
19
18
  objects?: string[];
20
19
  };
21
- export type SubscriptionEvent = {
20
+ export type FunctionSubscriptionEvent2 = {
22
21
  space?: Space;
23
22
  objects?: EchoReactiveObject<any>[];
24
23
  };
@@ -32,5 +31,5 @@ export type SubscriptionEvent = {
32
31
  *
33
32
  * NOTE: Get space key from devtools or `dx space list --json`
34
33
  */
35
- export declare const subscriptionHandler: (handler: FunctionHandler<SubscriptionEvent>) => FunctionHandler<RawSubscriptionEvent>;
34
+ export declare const subscriptionHandler: (handler: FunctionHandler<FunctionSubscriptionEvent2>) => FunctionHandler<FunctionSubscriptionEvent>;
36
35
  //# sourceMappingURL=handler.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["../../../src/handler.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,MAAM,EAAa,MAAM,cAAc,CAAC;AACtD,OAAO,EAAE,KAAK,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,KAAK,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAU5D,MAAM,WAAW,QAAQ;IACvB,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ,CAAC;CAChC;AAED,MAAM,WAAW,eAAe;IAE9B,MAAM,EAAE,MAAM,CAAC;IAEf,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB,IAAI,CAAC,EAAE,GAAG,CAAC;CACZ;AAGD,MAAM,MAAM,eAAe,CAAC,CAAC,SAAS,EAAE,IAAI,CAAC,MAAM,EAAE;IACnD,KAAK,EAAE,CAAC,CAAC;IACT,OAAO,EAAE,eAAe,CAAC;IACzB,QAAQ,EAAE,QAAQ,CAAC;CACpB,KAAK,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,CAAC;AAE/B,MAAM,MAAM,oBAAoB,GAAG;IACjC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,OAAO,CAAC,EAAE,kBAAkB,CAAC,GAAG,CAAC,EAAE,CAAC;CACrC,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,mBAAmB,YACrB,gBAAgB,iBAAiB,CAAC,KAC1C,gBAAgB,oBAAoB,CAgBtC,CAAC"}
1
+ {"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["../../../src/handler.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,MAAM,EAAa,MAAM,cAAc,CAAC;AACtD,OAAO,EAAE,KAAK,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,KAAK,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAW5D,MAAM,WAAW,QAAQ;IACvB,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ,CAAC;CAChC;AAGD,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAID,MAAM,MAAM,eAAe,CAAC,CAAC,SAAS,EAAE,IAAI,CAAC,MAAM,EAAE;IACnD,KAAK,EAAE,CAAC,CAAC;IACT,OAAO,EAAE,eAAe,CAAC;IACzB,QAAQ,EAAE,QAAQ,CAAC;CACpB,KAAK,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,CAAC;AAE/B,MAAM,MAAM,yBAAyB,GAAG;IACtC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;CACpB,CAAC;AAGF,MAAM,MAAM,0BAA0B,GAAG;IACvC,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,OAAO,CAAC,EAAE,kBAAkB,CAAC,GAAG,CAAC,EAAE,CAAC;CACrC,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,mBAAmB,YACrB,gBAAgB,0BAA0B,CAAC,KACnD,gBAAgB,yBAAyB,CAgB3C,CAAC"}
@@ -1,11 +1,10 @@
1
- import { Event } from '@dxos/async';
2
1
  import { type Client } from '@dxos/client';
3
2
  import { type FunctionHandler } from '../handler';
4
3
  import { type FunctionManifest } from '../types';
5
4
  export type DevServerOptions = {
6
- manifest: FunctionManifest;
7
- baseDir: string;
8
5
  port?: number;
6
+ directory: string;
7
+ manifest: FunctionManifest;
9
8
  reload?: boolean;
10
9
  dataDir?: string;
11
10
  };
@@ -18,22 +17,18 @@ export declare class DevServer {
18
17
  private readonly _handlers;
19
18
  private _server?;
20
19
  private _port?;
21
- private _functionServiceRegistration?;
20
+ private _registrationId?;
22
21
  private _proxy?;
23
22
  private _seq;
24
- readonly update: Event<number>;
25
23
  constructor(_client: Client, _options: DevServerOptions);
26
- get stats(): {
27
- seq: number;
28
- };
29
24
  get endpoint(): string;
30
25
  get proxy(): string | undefined;
31
26
  get functions(): {
32
27
  def: {
33
28
  readonly id: string;
34
29
  readonly handler: string;
30
+ readonly name: string;
35
31
  readonly description?: string | undefined;
36
- readonly path: string;
37
32
  };
38
33
  handler: FunctionHandler<any>;
39
34
  }[];
@@ -45,9 +40,8 @@ export declare class DevServer {
45
40
  */
46
41
  private _load;
47
42
  /**
48
- * Invoke function.
43
+ * Invoke function handler.
49
44
  */
50
- invoke(path: string, data: any): Promise<number>;
51
45
  private _invoke;
52
46
  }
53
47
  //# sourceMappingURL=dev-server.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"dev-server.d.ts","sourceRoot":"","sources":["../../../../src/runtime/dev-server.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,KAAK,EAAW,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,cAAc,CAAC;AAI3C,OAAO,EAAwB,KAAK,eAAe,EAAiB,MAAM,YAAY,CAAC;AACvF,OAAO,EAAoB,KAAK,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAEnE,MAAM,MAAM,gBAAgB,GAAG;IAC7B,QAAQ,EAAE,gBAAgB,CAAC;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF;;GAEG;AACH,qBAAa,SAAS;IAclB,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,QAAQ;IAb3B,OAAO,CAAC,QAAQ,CAAC,SAAS,CAA2E;IAErG,OAAO,CAAC,OAAO,CAAC,CAAc;IAC9B,OAAO,CAAC,KAAK,CAAC,CAAS;IACv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MAAM,CAAC,CAAS;IACxB,OAAO,CAAC,IAAI,CAAK;gBAIE,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,gBAAgB;IAG7C,IAAI,QAAQ,WAGX;IAED,IAAI,KAAK,uBAER;IAED,IAAI,SAAS;;;;;;;;QAEZ;IAEK,UAAU;IAUV,KAAK;IAyCL,IAAI;IAqBV;;OAEG;YACW,KAAK;IAqBnB;;OAEG;YACW,OAAO;CAyBtB"}
@@ -1,12 +1,13 @@
1
1
  import { type Client } from '@dxos/client';
2
+ import { type FunctionSubscriptionEvent } from '../handler';
2
3
  import { type FunctionManifest } from '../types';
3
- export type Callback = (data: any) => Promise<void | number>;
4
+ type Callback = (data: FunctionSubscriptionEvent) => Promise<void>;
4
5
  export type SchedulerOptions = {
5
6
  endpoint?: string;
6
7
  callback?: Callback;
7
8
  };
8
9
  /**
9
- * The scheduler triggers function execution based on various triggers.
10
+ * The scheduler triggers function exectuion based on various triggers.
10
11
  */
11
12
  export declare class Scheduler {
12
13
  private readonly _client;
@@ -14,43 +15,8 @@ export declare class Scheduler {
14
15
  private readonly _options;
15
16
  private readonly _mounts;
16
17
  constructor(_client: Client, _manifest: FunctionManifest, _options?: SchedulerOptions);
17
- get mounts(): {
18
- readonly function: string;
19
- readonly context?: {
20
- readonly [x: string]: any;
21
- } | undefined;
22
- readonly timer?: {
23
- readonly cron: string;
24
- } | undefined;
25
- readonly webhook?: {
26
- port?: number | undefined;
27
- method: string;
28
- } | undefined;
29
- readonly websocket?: {
30
- readonly url: string;
31
- readonly init?: {
32
- readonly [x: string]: any;
33
- } | undefined;
34
- } | undefined;
35
- readonly subscription?: {
36
- readonly filter: readonly {
37
- readonly type: string;
38
- readonly props?: {
39
- readonly [x: string]: any;
40
- } | undefined;
41
- }[];
42
- readonly spaceKey?: string | undefined;
43
- readonly options?: {
44
- readonly deep?: boolean | undefined;
45
- readonly delay?: number | undefined;
46
- } | undefined;
47
- } | undefined;
48
- }[];
49
18
  start(): Promise<void>;
50
19
  stop(): Promise<void>;
51
- /**
52
- * Mount trigger.
53
- */
54
20
  private mount;
55
21
  private unmount;
56
22
  private _execFunction;
@@ -64,7 +30,6 @@ export declare class Scheduler {
64
30
  private _createWebhook;
65
31
  /**
66
32
  * Websocket.
67
- * NOTE: The port must be unique, so the same hook cannot be used for multiple spaces.
68
33
  */
69
34
  private _createWebsocket;
70
35
  /**
@@ -72,4 +37,5 @@ export declare class Scheduler {
72
37
  */
73
38
  private _createSubscription;
74
39
  }
40
+ export {};
75
41
  //# sourceMappingURL=scheduler.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"scheduler.d.ts","sourceRoot":"","sources":["../../../../src/runtime/scheduler.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,KAAK,MAAM,EAAkB,MAAM,cAAc,CAAC;AAO3D,OAAO,EAEL,KAAK,gBAAgB,EAMtB,MAAM,UAAU,CAAC;AAElB,MAAM,MAAM,QAAQ,GAAG,CAAC,IAAI,EAAE,GAAG,KAAK,OAAO,CAAC,IAAI,GAAG,MAAM,CAAC,CAAC;AAE7D,MAAM,MAAM,gBAAgB,GAAG;IAC7B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,QAAQ,CAAC;CACrB,CAAC;AAEF;;GAEG;AACH,qBAAa,SAAS;IAQlB,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,QAAQ;IAR3B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAG6B;gBAGlC,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,gBAAgB,EAC3B,QAAQ,GAAE,gBAAqB;IAGlD,IAAI,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;QAKT;IAEK,KAAK;IAWL,IAAI;IAMV;;OAEG;YACW,KAAK;YAoCL,OAAO;YAUP,aAAa;IAwC3B;;OAEG;YACW,YAAY;IA8B1B;;OAEG;YACW,cAAc;IAiC5B;;;OAGG;YACW,gBAAgB;IAoE9B;;OAEG;YACW,mBAAmB;CAsDlC"}
1
+ {"version":3,"file":"scheduler.d.ts","sourceRoot":"","sources":["../../../../src/runtime/scheduler.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,KAAK,MAAM,EAAkB,MAAM,cAAc,CAAC;AAO3D,OAAO,EAAE,KAAK,yBAAyB,EAAE,MAAM,YAAY,CAAC;AAC5D,OAAO,EAEL,KAAK,gBAAgB,EAMtB,MAAM,UAAU,CAAC;AAElB,KAAK,QAAQ,GAAG,CAAC,IAAI,EAAE,yBAAyB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;AAEnE,MAAM,MAAM,gBAAgB,GAAG;IAC7B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,QAAQ,CAAC;CACrB,CAAC;AAEF;;GAEG;AACH,qBAAa,SAAS;IAQlB,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,QAAQ;IAR3B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAG6B;gBAGlC,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,gBAAgB,EAC3B,QAAQ,GAAE,gBAAqB;IAG5C,KAAK;IAWL,IAAI;YAMI,KAAK;YAoCL,OAAO;YAUP,aAAa;IA4B3B;;OAEG;YACW,YAAY;IA8B1B;;OAEG;YACW,cAAc;IAkB5B;;OAEG;YACW,gBAAgB;IAmE9B;;OAEG;YACW,mBAAmB;CAqDlC"}
@@ -2,10 +2,9 @@ import * as S from '@effect/schema/Schema';
2
2
  declare const TimerTriggerSchema: S.struct<{
3
3
  cron: S.$string;
4
4
  }>;
5
- declare const WebhookTriggerSchema: S.mutable<S.struct<{
6
- method: S.$string;
7
- port: S.PropertySignature<"?:", number | undefined, never, "?:", number | undefined, never>;
8
- }>>;
5
+ declare const WebhookTriggerSchema: S.struct<{
6
+ port: S.$number;
7
+ }>;
9
8
  declare const WebsocketTriggerSchema: S.struct<{
10
9
  url: S.$string;
11
10
  init: S.PropertySignature<"?:", {
@@ -34,22 +33,15 @@ declare const SubscriptionTriggerSchema: S.struct<{
34
33
  }>;
35
34
  declare const FunctionTriggerSchema: S.struct<{
36
35
  function: S.$string;
37
- context: S.PropertySignature<"?:", {
38
- readonly [x: string]: any;
39
- } | undefined, never, "?:", {
40
- readonly [x: string]: any;
41
- } | undefined, never>;
42
36
  timer: S.PropertySignature<"?:", {
43
37
  readonly cron: string;
44
38
  } | undefined, never, "?:", {
45
39
  readonly cron: string;
46
40
  } | undefined, never>;
47
41
  webhook: S.PropertySignature<"?:", {
48
- port?: number | undefined;
49
- method: string;
42
+ readonly port: number;
50
43
  } | undefined, never, "?:", {
51
- method: string;
52
- port?: number | undefined;
44
+ readonly port: number;
53
45
  } | undefined, never>;
54
46
  websocket: S.PropertySignature<"?:", {
55
47
  readonly url: string;
@@ -99,7 +91,7 @@ export type FunctionTrigger = S.Schema.Type<typeof FunctionTriggerSchema>;
99
91
  declare const FunctionDefSchema: S.struct<{
100
92
  id: S.$string;
101
93
  description: S.PropertySignature<"?:", string | undefined, never, "?:", string | undefined, never>;
102
- path: S.$string;
94
+ name: S.$string;
103
95
  handler: S.$string;
104
96
  }>;
105
97
  export type FunctionDef = S.Schema.Type<typeof FunctionDefSchema>;
@@ -110,28 +102,33 @@ export declare const FunctionManifestSchema: S.struct<{
110
102
  functions: S.mutable<S.array<S.struct<{
111
103
  id: S.$string;
112
104
  description: S.PropertySignature<"?:", string | undefined, never, "?:", string | undefined, never>;
113
- path: S.$string;
105
+ name: S.$string;
114
106
  handler: S.$string;
115
107
  }>>>;
116
- triggers: S.PropertySignature<"?:", {
117
- readonly function: string;
118
- readonly context?: {
119
- readonly [x: string]: any;
120
- } | undefined;
121
- readonly timer?: {
108
+ triggers: S.mutable<S.array<S.struct<{
109
+ function: S.$string;
110
+ timer: S.PropertySignature<"?:", {
122
111
  readonly cron: string;
123
- } | undefined;
124
- readonly webhook?: {
125
- port?: number | undefined;
126
- method: string;
127
- } | undefined;
128
- readonly websocket?: {
112
+ } | undefined, never, "?:", {
113
+ readonly cron: string;
114
+ } | undefined, never>;
115
+ webhook: S.PropertySignature<"?:", {
116
+ readonly port: number;
117
+ } | undefined, never, "?:", {
118
+ readonly port: number;
119
+ } | undefined, never>;
120
+ websocket: S.PropertySignature<"?:", {
129
121
  readonly url: string;
130
122
  readonly init?: {
131
123
  readonly [x: string]: any;
132
124
  } | undefined;
133
- } | undefined;
134
- readonly subscription?: {
125
+ } | undefined, never, "?:", {
126
+ readonly url: string;
127
+ readonly init?: {
128
+ readonly [x: string]: any;
129
+ } | undefined;
130
+ } | undefined, never>;
131
+ subscription: S.PropertySignature<"?:", {
135
132
  readonly filter: readonly {
136
133
  readonly type: string;
137
134
  readonly props?: {
@@ -143,26 +140,7 @@ export declare const FunctionManifestSchema: S.struct<{
143
140
  readonly deep?: boolean | undefined;
144
141
  readonly delay?: number | undefined;
145
142
  } | undefined;
146
- } | undefined;
147
- }[] | undefined, never, "?:", {
148
- readonly function: string;
149
- readonly context?: {
150
- readonly [x: string]: any;
151
- } | undefined;
152
- readonly timer?: {
153
- readonly cron: string;
154
- } | undefined;
155
- readonly webhook?: {
156
- method: string;
157
- port?: number | undefined;
158
- } | undefined;
159
- readonly websocket?: {
160
- readonly url: string;
161
- readonly init?: {
162
- readonly [x: string]: any;
163
- } | undefined;
164
- } | undefined;
165
- readonly subscription?: {
143
+ } | undefined, never, "?:", {
166
144
  readonly filter: readonly {
167
145
  readonly type: string;
168
146
  readonly props?: {
@@ -174,8 +152,8 @@ export declare const FunctionManifestSchema: S.struct<{
174
152
  readonly deep?: boolean | undefined;
175
153
  readonly delay?: number | undefined;
176
154
  } | undefined;
177
- } | undefined;
178
- }[] | undefined, never>;
155
+ } | undefined, never>;
156
+ }>>>;
179
157
  }>;
180
158
  export type FunctionManifest = S.Schema.Type<typeof FunctionMan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AAC,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,sBAAsB,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dxos/functions",
3
- "version": "0.5.3-main.3456876",
3
+ "version": "0.5.3-main.3b535c7",
4
4
  "description": "Functions SDK and runtime.",
5
5
  "homepage": "https://dxos.org",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
@@ -20,32 +20,30 @@
20
20
  "src"
21
21
  ],
22
22
  "dependencies": {
23
- "@effect/schema": "^0.64.20",
23
+ "@effect/schema": "0.64.7",
24
24
  "@preact/signals-core": "^1.6.0",
25
25
  "cron": "^3.1.6",
26
- "effect": "^2.4.19",
27
26
  "express": "^4.19.2",
28
27
  "get-port-please": "^3.1.1",
29
28
  "ws": "^8.14.2",
30
- "@braneframe/types": "0.5.3-main.3456876",
31
- "@dxos/async": "0.5.3-main.3456876",
32
- "@dxos/client": "0.5.3-main.3456876",
33
- "@dxos/context": "0.5.3-main.3456876",
34
- "@dxos/echo-schema": "0.5.3-main.3456876",
35
- "@dxos/invariant": "0.5.3-main.3456876",
36
- "@dxos/log": "0.5.3-main.3456876",
37
- "@dxos/node-std": "0.5.3-main.3456876",
38
- "@dxos/util": "0.5.3-main.3456876"
29
+ "@braneframe/types": "0.5.3-main.3b535c7",
30
+ "@dxos/async": "0.5.3-main.3b535c7",
31
+ "@dxos/context": "0.5.3-main.3b535c7",
32
+ "@dxos/client": "0.5.3-main.3b535c7",
33
+ "@dxos/invariant": "0.5.3-main.3b535c7",
34
+ "@dxos/echo-schema": "0.5.3-main.3b535c7",
35
+ "@dxos/log": "0.5.3-main.3b535c7",
36
+ "@dxos/node-std": "0.5.3-main.3b535c7",
37
+ "@dxos/util": "0.5.3-main.3b535c7"
39
38
  },
40
39
  "devDependencies": {
41
40
  "@types/express": "^4.17.17",
42
- "@types/ws": "^7.4.0",
43
- "@dxos/agent": "0.5.3-main.3456876"
41
+ "@types/ws": "^7.4.0"
44
42
  },
45
43
  "publishConfig": {
46
44
  "access": "public"
47
45
  },
48
46
  "scripts": {
49
- "gen-schema": "ts-node ./tools/schema.ts"
47
+ "schema": "ts-node ./tools/schema.ts"
50
48
  }
51
49
  }