@dxos/functions 0.7.5-labs.f5080a1 → 0.7.5-labs.ff2ff30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/browser/bundler/index.mjs +239 -0
- package/dist/lib/browser/bundler/index.mjs.map +7 -0
- package/dist/lib/browser/{chunk-FTGUA7ZJ.mjs → chunk-JNWHUD6Z.mjs} +2 -2
- package/dist/lib/browser/{chunk-R4ERZ4GX.mjs → chunk-PI2DP37S.mjs} +10 -3
- package/dist/lib/browser/chunk-PI2DP37S.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +2 -2
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +2 -2
- package/dist/lib/browser/types/index.mjs +1 -1
- package/dist/lib/node/bundler/index.cjs +261 -0
- package/dist/lib/node/bundler/index.cjs.map +7 -0
- package/dist/lib/node/{chunk-NC6L7H5C.cjs → chunk-2ASAZ4AS.cjs} +15 -15
- package/dist/lib/node/{chunk-4WNFTPH7.cjs → chunk-PGFJYL6Q.cjs} +12 -5
- package/dist/lib/node/chunk-PGFJYL6Q.cjs.map +7 -0
- package/dist/lib/node/index.cjs +15 -15
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +7 -7
- package/dist/lib/node/types/index.cjs +10 -10
- package/dist/lib/node/types/index.cjs.map +1 -1
- package/dist/lib/node-esm/bundler/index.mjs +239 -0
- package/dist/lib/node-esm/bundler/index.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-UOQLFLOW.mjs → chunk-IOAKDIT3.mjs} +10 -3
- package/dist/lib/node-esm/chunk-IOAKDIT3.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-FK2RGYVS.mjs → chunk-LNBGGB6Z.mjs} +2 -2
- package/dist/lib/node-esm/index.mjs +2 -2
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/testing/index.mjs +2 -2
- package/dist/lib/node-esm/types/index.mjs +1 -1
- package/dist/types/src/bundler/bundler.d.ts +51 -0
- package/dist/types/src/bundler/bundler.d.ts.map +1 -0
- package/dist/types/src/bundler/bundler.test.d.ts +2 -0
- package/dist/types/src/bundler/bundler.test.d.ts.map +1 -0
- package/dist/types/src/bundler/index.d.ts +2 -0
- package/dist/types/src/bundler/index.d.ts.map +1 -0
- package/dist/types/src/types/schema.d.ts +2 -0
- package/dist/types/src/types/schema.d.ts.map +1 -1
- package/dist/types/src/types/types.d.ts +25 -1
- package/dist/types/src/types/types.d.ts.map +1 -1
- package/package.json +30 -17
- package/src/bundler/bundler.test.ts +59 -0
- package/src/bundler/bundler.ts +264 -0
- package/src/bundler/index.ts +5 -0
- package/src/types/schema.ts +1 -0
- package/src/types/types.ts +10 -1
- package/dist/lib/browser/chunk-R4ERZ4GX.mjs.map +0 -7
- package/dist/lib/node/chunk-4WNFTPH7.cjs.map +0 -7
- package/dist/lib/node-esm/chunk-UOQLFLOW.mjs.map +0 -7
- /package/dist/lib/browser/{chunk-FTGUA7ZJ.mjs.map → chunk-JNWHUD6Z.mjs.map} +0 -0
- /package/dist/lib/node/{chunk-NC6L7H5C.cjs.map → chunk-2ASAZ4AS.cjs.map} +0 -0
- /package/dist/lib/node-esm/{chunk-FK2RGYVS.mjs.map → chunk-LNBGGB6Z.mjs.map} +0 -0
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var bundler_exports = {};
|
|
20
|
+
__export(bundler_exports, {
|
|
21
|
+
Bundler: () => Bundler,
|
|
22
|
+
initializeBundler: () => initializeBundler
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(bundler_exports);
|
|
25
|
+
var import_chunk_JEQ2X3Z6 = require("../chunk-JEQ2X3Z6.cjs");
|
|
26
|
+
var import_esbuild_wasm = require("esbuild-wasm");
|
|
27
|
+
var import_crypto = require("@dxos/crypto");
|
|
28
|
+
var import_invariant = require("@dxos/invariant");
|
|
29
|
+
var import_log = require("@dxos/log");
|
|
30
|
+
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/core/functions/src/bundler/bundler.ts";
|
|
31
|
+
var initialized;
|
|
32
|
+
var initializeBundler = async (options) => {
|
|
33
|
+
await (initialized ??= (0, import_esbuild_wasm.initialize)({
|
|
34
|
+
wasmURL: options.wasmUrl
|
|
35
|
+
}));
|
|
36
|
+
};
|
|
37
|
+
var Bundler = class {
|
|
38
|
+
constructor(_options) {
|
|
39
|
+
this._options = _options;
|
|
40
|
+
}
|
|
41
|
+
async bundle({ path, source }) {
|
|
42
|
+
const { sandboxedModules: providedModules, ...options } = this._options;
|
|
43
|
+
const createResult = async (result) => {
|
|
44
|
+
return {
|
|
45
|
+
timestamp: Date.now(),
|
|
46
|
+
sourceHash: source ? Buffer.from(await import_crypto.subtleCrypto.digest("SHA-256", Buffer.from(source))) : void 0,
|
|
47
|
+
...result
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
if (this._options.platform === "browser") {
|
|
51
|
+
(0, import_invariant.invariant)(initialized, "Compiler not initialized.", {
|
|
52
|
+
F: __dxlog_file,
|
|
53
|
+
L: 71,
|
|
54
|
+
S: this,
|
|
55
|
+
A: [
|
|
56
|
+
"initialized",
|
|
57
|
+
"'Compiler not initialized.'"
|
|
58
|
+
]
|
|
59
|
+
});
|
|
60
|
+
await initialized;
|
|
61
|
+
}
|
|
62
|
+
const imports = source ? analyzeSourceFileImports(source) : [];
|
|
63
|
+
try {
|
|
64
|
+
const result = await (0, import_esbuild_wasm.build)({
|
|
65
|
+
platform: options.platform,
|
|
66
|
+
conditions: [
|
|
67
|
+
"workerd",
|
|
68
|
+
"browser"
|
|
69
|
+
],
|
|
70
|
+
metafile: true,
|
|
71
|
+
write: false,
|
|
72
|
+
entryPoints: [
|
|
73
|
+
path ?? "memory:main.tsx"
|
|
74
|
+
],
|
|
75
|
+
bundle: true,
|
|
76
|
+
format: "esm",
|
|
77
|
+
plugins: [
|
|
78
|
+
{
|
|
79
|
+
name: "memory",
|
|
80
|
+
setup: (build2) => {
|
|
81
|
+
build2.onResolve({
|
|
82
|
+
filter: /^\.\/runtime\.js$/
|
|
83
|
+
}, ({ path: path2 }) => {
|
|
84
|
+
return {
|
|
85
|
+
path: path2,
|
|
86
|
+
external: true
|
|
87
|
+
};
|
|
88
|
+
});
|
|
89
|
+
build2.onResolve({
|
|
90
|
+
filter: /^dxos:functions$/
|
|
91
|
+
}, ({ path: path2 }) => {
|
|
92
|
+
return {
|
|
93
|
+
path: "./runtime.js",
|
|
94
|
+
external: true
|
|
95
|
+
};
|
|
96
|
+
});
|
|
97
|
+
build2.onResolve({
|
|
98
|
+
filter: /^memory:/
|
|
99
|
+
}, ({ path: path2 }) => {
|
|
100
|
+
return {
|
|
101
|
+
path: path2.split(":")[1],
|
|
102
|
+
namespace: "memory"
|
|
103
|
+
};
|
|
104
|
+
});
|
|
105
|
+
build2.onLoad({
|
|
106
|
+
filter: /.*/,
|
|
107
|
+
namespace: "memory"
|
|
108
|
+
}, ({ path: path2 }) => {
|
|
109
|
+
if (path2 === "main.tsx") {
|
|
110
|
+
return {
|
|
111
|
+
contents: source,
|
|
112
|
+
loader: "tsx"
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
for (const module2 of providedModules) {
|
|
117
|
+
build2.onResolve({
|
|
118
|
+
filter: new RegExp(`^${module2}$`)
|
|
119
|
+
}, ({ path: path2 }) => {
|
|
120
|
+
return {
|
|
121
|
+
path: path2,
|
|
122
|
+
namespace: "injected-module"
|
|
123
|
+
};
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
build2.onLoad({
|
|
127
|
+
filter: /.*/,
|
|
128
|
+
namespace: "injected-module"
|
|
129
|
+
}, ({ path: path2 }) => {
|
|
130
|
+
const namedImports = imports.find((entry) => entry.moduleIdentifier === path2)?.namedImports ?? [];
|
|
131
|
+
return {
|
|
132
|
+
contents: `
|
|
133
|
+
const { ${namedImports.join(",")} } = window.__DXOS_SANDBOX_MODULES__[${JSON.stringify(path2)}];
|
|
134
|
+
export { ${namedImports.join(",")} };
|
|
135
|
+
export default window.__DXOS_SANDBOX_MODULES__[${JSON.stringify(path2)}].default;
|
|
136
|
+
`,
|
|
137
|
+
loader: "tsx"
|
|
138
|
+
};
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
},
|
|
142
|
+
httpPlugin
|
|
143
|
+
]
|
|
144
|
+
});
|
|
145
|
+
(0, import_log.log)("compile complete", result.metafile, {
|
|
146
|
+
F: __dxlog_file,
|
|
147
|
+
L: 135,
|
|
148
|
+
S: this,
|
|
149
|
+
C: (f, a) => f(...a)
|
|
150
|
+
});
|
|
151
|
+
return await createResult({
|
|
152
|
+
imports: this.analyzeImports(result),
|
|
153
|
+
bundle: result.outputFiles[0].text
|
|
154
|
+
});
|
|
155
|
+
} catch (err) {
|
|
156
|
+
return await createResult({
|
|
157
|
+
error: err
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
// TODO(dmaretskyi): In the future we can replace the compiler with SWC with plugins running in WASM.
|
|
162
|
+
analyzeImports(result) {
|
|
163
|
+
(0, import_invariant.invariant)(result.outputFiles, void 0, {
|
|
164
|
+
F: __dxlog_file,
|
|
165
|
+
L: 148,
|
|
166
|
+
S: this,
|
|
167
|
+
A: [
|
|
168
|
+
"result.outputFiles",
|
|
169
|
+
""
|
|
170
|
+
]
|
|
171
|
+
});
|
|
172
|
+
const parsedImports = allMatches(IMPORT_REGEX, result.outputFiles[0].text);
|
|
173
|
+
return Object.values(result.metafile.outputs)[0].imports.map((entry) => {
|
|
174
|
+
const namedImports = [];
|
|
175
|
+
const parsedImport = parsedImports.find((capture) => capture?.[4] === entry.path);
|
|
176
|
+
if (parsedImport?.[2]) {
|
|
177
|
+
NAMED_IMPORTS_REGEX.lastIndex = 0;
|
|
178
|
+
const namedImportsMatch = NAMED_IMPORTS_REGEX.exec(parsedImport[2]);
|
|
179
|
+
if (namedImportsMatch) {
|
|
180
|
+
namedImportsMatch[1].split(",").forEach((importName) => {
|
|
181
|
+
namedImports.push(importName.trim());
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
return {
|
|
186
|
+
moduleUrl: entry.path,
|
|
187
|
+
defaultImport: !!parsedImport?.[1],
|
|
188
|
+
namedImports
|
|
189
|
+
};
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
analyzeSourceFileImports(code) {
|
|
193
|
+
const parsedImports = allMatches(IMPORT_REGEX, code);
|
|
194
|
+
return parsedImports.map((capture) => {
|
|
195
|
+
return {
|
|
196
|
+
defaultImportName: capture[1],
|
|
197
|
+
namedImports: capture[2]?.split(",").map((importName) => importName.trim()),
|
|
198
|
+
wildcardImportName: capture[3],
|
|
199
|
+
moduleIdentifier: capture[4],
|
|
200
|
+
quotes: capture[5]
|
|
201
|
+
};
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
var IMPORT_REGEX = /import(?:(?:(?:[ \n\t]+([^ *\n\t{},]+)[ \n\t]*(?:,|[ \n\t]+))?([ \n\t]*{(?:[ \n\t]*[^ \n\t"'{}]+[ \n\t]*,?)+})?[ \n\t]*)|[ \n\t]*\*[ \n\t]*as[ \n\t]+([^ \n\t{}]+)[ \n\t]+)from[ \n\t]*(?:['"])([^'"\n]+)(['"])/gm;
|
|
206
|
+
var NAMED_IMPORTS_REGEX = /[ \n\t]*{((?:[ \n\t]*[^ \n\t"'{}]+[ \n\t]*,?)+)}[ \n\t]*/gm;
|
|
207
|
+
var allMatches = (regex, str) => {
|
|
208
|
+
regex.lastIndex = 0;
|
|
209
|
+
let match;
|
|
210
|
+
const matches = [];
|
|
211
|
+
while (match = regex.exec(str)) {
|
|
212
|
+
matches.push(match);
|
|
213
|
+
}
|
|
214
|
+
return matches;
|
|
215
|
+
};
|
|
216
|
+
var analyzeSourceFileImports = (code) => {
|
|
217
|
+
const parsedImports = allMatches(IMPORT_REGEX, code);
|
|
218
|
+
return parsedImports.map((capture) => {
|
|
219
|
+
return {
|
|
220
|
+
defaultImportName: capture[1],
|
|
221
|
+
namedImports: capture[2]?.trim().slice(1, -1).split(",").map((importName) => importName.trim()),
|
|
222
|
+
wildcardImportName: capture[3],
|
|
223
|
+
moduleIdentifier: capture[4],
|
|
224
|
+
quotes: capture[5]
|
|
225
|
+
};
|
|
226
|
+
});
|
|
227
|
+
};
|
|
228
|
+
var httpPlugin = {
|
|
229
|
+
name: "http",
|
|
230
|
+
setup: (build2) => {
|
|
231
|
+
build2.onResolve({
|
|
232
|
+
filter: /^https?:\/\//
|
|
233
|
+
}, (args) => ({
|
|
234
|
+
path: args.path,
|
|
235
|
+
namespace: "http-url"
|
|
236
|
+
}));
|
|
237
|
+
build2.onResolve({
|
|
238
|
+
filter: /.*/,
|
|
239
|
+
namespace: "http-url"
|
|
240
|
+
}, (args) => ({
|
|
241
|
+
path: new URL(args.path, args.importer).toString(),
|
|
242
|
+
namespace: "http-url"
|
|
243
|
+
}));
|
|
244
|
+
build2.onLoad({
|
|
245
|
+
filter: /.*/,
|
|
246
|
+
namespace: "http-url"
|
|
247
|
+
}, async (args) => {
|
|
248
|
+
const response = await fetch(args.path);
|
|
249
|
+
return {
|
|
250
|
+
contents: await response.text(),
|
|
251
|
+
loader: "jsx"
|
|
252
|
+
};
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
};
|
|
256
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
257
|
+
0 && (module.exports = {
|
|
258
|
+
Bundler,
|
|
259
|
+
initializeBundler
|
|
260
|
+
});
|
|
261
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/bundler/bundler.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { type BuildOptions } from 'esbuild';\nimport { build, initialize, type BuildResult, type Plugin } from 'esbuild-wasm';\n\nimport { subtleCrypto } from '@dxos/crypto';\nimport { invariant } from '@dxos/invariant';\nimport { log } from '@dxos/log';\n\nexport type Import = {\n moduleUrl: string;\n defaultImport: boolean;\n namedImports: string[];\n};\n\nexport type BundleOptions = {\n /**\n * Path to the source file on the local file system.\n * If provided, the path will be used instead of the `source` code.\n */\n path?: string;\n\n /**\n * Source code to bundle.\n * Required if `path` is not provided.\n */\n source?: string;\n};\n\nexport type BundleResult = {\n timestamp: number;\n sourceHash?: Buffer;\n imports?: Import[];\n bundle?: string;\n error?: any;\n};\n\nexport type BundlerOptions = {\n platform: BuildOptions['platform'];\n sandboxedModules: string[];\n remoteModules: Record<string, string>;\n};\n\nlet initialized: Promise<void>;\nexport const initializeBundler = async (options: { wasmUrl: string }) => {\n await (initialized ??= initialize({\n wasmURL: options.wasmUrl,\n }));\n};\n\n/**\n * ESBuild bundler.\n */\nexport class Bundler {\n constructor(private readonly _options: BundlerOptions) {}\n\n async bundle({ path, source }: BundleOptions): Promise<BundleResult> {\n const { sandboxedModules: providedModules, ...options } = this._options;\n\n const createResult = async (result?: Partial<BundleResult>) => {\n return {\n timestamp: Date.now(),\n sourceHash: source ? Buffer.from(await subtleCrypto.digest('SHA-256', Buffer.from(source))) : undefined,\n ...result,\n };\n };\n\n if (this._options.platform === 'browser') {\n invariant(initialized, 'Compiler not initialized.');\n await initialized;\n }\n\n const imports = source ? analyzeSourceFileImports(source) : [];\n\n // https://esbuild.github.io/api/#build\n try {\n const result = await build({\n platform: options.platform,\n conditions: ['workerd', 'browser'],\n metafile: true,\n write: false,\n entryPoints: [path ?? 'memory:main.tsx'],\n bundle: true,\n format: 'esm',\n plugins: [\n {\n name: 'memory',\n setup: (build) => {\n build.onResolve({ filter: /^\\.\\/runtime\\.js$/ }, ({ path }) => {\n return { path, external: true };\n });\n\n build.onResolve({ filter: /^dxos:functions$/ }, ({ path }) => {\n return { path: './runtime.js', external: true };\n });\n\n build.onResolve({ filter: /^memory:/ }, ({ path }) => {\n return { path: path.split(':')[1], namespace: 'memory' };\n });\n\n build.onLoad({ filter: /.*/, namespace: 'memory' }, ({ path }) => {\n if (path === 'main.tsx') {\n return {\n contents: source,\n loader: 'tsx',\n };\n }\n });\n\n for (const module of providedModules) {\n build.onResolve({ filter: new RegExp(`^${module}$`) }, ({ path }) => {\n return { path, namespace: 'injected-module' };\n });\n }\n\n build.onLoad({ filter: /.*/, namespace: 'injected-module' }, ({ path }) => {\n const namedImports = imports.find((entry) => entry.moduleIdentifier === path)?.namedImports ?? [];\n return {\n contents: `\n const { ${namedImports.join(',')} } = window.__DXOS_SANDBOX_MODULES__[${JSON.stringify(path)}];\n export { ${namedImports.join(',')} };\n export default window.__DXOS_SANDBOX_MODULES__[${JSON.stringify(path)}].default;\n `,\n loader: 'tsx',\n };\n });\n },\n },\n httpPlugin,\n ],\n });\n\n log('compile complete', result.metafile);\n\n return await createResult({\n imports: this.analyzeImports(result),\n bundle: result.outputFiles![0].text,\n });\n } catch (err) {\n return await createResult({ error: err });\n }\n }\n\n // TODO(dmaretskyi): In the future we can replace the compiler with SWC with plugins running in WASM.\n analyzeImports(result: BuildResult): Import[] {\n invariant(result.outputFiles);\n\n // TODO(dmaretskyi): Support import aliases and wildcard imports.\n const parsedImports = allMatches(IMPORT_REGEX, result.outputFiles[0].text);\n return Object.values(result.metafile!.outputs)[0].imports.map((entry): Import => {\n const namedImports: string[] = [];\n\n const parsedImport = parsedImports.find((capture) => capture?.[4] === entry.path);\n if (parsedImport?.[2]) {\n NAMED_IMPORTS_REGEX.lastIndex = 0;\n const namedImportsMatch = NAMED_IMPORTS_REGEX.exec(parsedImport[2]);\n if (namedImportsMatch) {\n namedImportsMatch[1].split(',').forEach((importName) => {\n namedImports.push(importName.trim());\n });\n }\n }\n\n return {\n moduleUrl: entry.path,\n defaultImport: !!parsedImport?.[1],\n namedImports,\n };\n });\n }\n\n analyzeSourceFileImports(code: string) {\n // TODO(dmaretskyi): Support import aliases and wildcard imports.\n const parsedImports = allMatches(IMPORT_REGEX, code);\n return parsedImports.map((capture) => {\n return {\n defaultImportName: capture[1],\n namedImports: capture[2]?.split(',').map((importName) => importName.trim()),\n wildcardImportName: capture[3],\n moduleIdentifier: capture[4],\n quotes: capture[5],\n };\n });\n }\n}\n\n// https://regex101.com/r/FEN5ks/1\n// https://stackoverflow.com/a/73265022\n// $1 = default import name (can be non-existent)\n// $2 = destructured exports (can be non-existent)\n// $3 = wildcard import name (can be non-existent)\n// $4 = module identifier\n// $5 = quotes used (either ' or \")\nconst IMPORT_REGEX =\n /import(?:(?:(?:[ \\n\\t]+([^ *\\n\\t{},]+)[ \\n\\t]*(?:,|[ \\n\\t]+))?([ \\n\\t]*{(?:[ \\n\\t]*[^ \\n\\t\"'{}]+[ \\n\\t]*,?)+})?[ \\n\\t]*)|[ \\n\\t]*\\*[ \\n\\t]*as[ \\n\\t]+([^ \\n\\t{}]+)[ \\n\\t]+)from[ \\n\\t]*(?:['\"])([^'\"\\n]+)(['\"])/gm;\n\nconst NAMED_IMPORTS_REGEX = /[ \\n\\t]*{((?:[ \\n\\t]*[^ \\n\\t\"'{}]+[ \\n\\t]*,?)+)}[ \\n\\t]*/gm;\n\nconst allMatches = (regex: RegExp, str: string) => {\n regex.lastIndex = 0;\n\n let match;\n const matches = [];\n while ((match = regex.exec(str))) {\n matches.push(match);\n }\n\n return matches;\n};\n\ntype ParsedImport = {\n defaultImportName?: string;\n namedImports: string[];\n wildcardImportName?: string;\n moduleIdentifier: string;\n quotes: string;\n};\n\nconst analyzeSourceFileImports = (code: string): ParsedImport[] => {\n // TODO(dmaretskyi): Support import aliases and wildcard imports.\n const parsedImports = allMatches(IMPORT_REGEX, code);\n return parsedImports.map((capture) => {\n return {\n defaultImportName: capture[1],\n namedImports: capture[2]\n ?.trim()\n .slice(1, -1)\n .split(',')\n .map((importName) => importName.trim()),\n wildcardImportName: capture[3],\n moduleIdentifier: capture[4],\n quotes: capture[5],\n };\n });\n};\n\nconst httpPlugin: Plugin = {\n name: 'http',\n setup: (build) => {\n // Intercept import paths starting with \"http:\" and \"https:\" so esbuild doesn't attempt to map them to a file system location.\n // Tag them with the \"http-url\" namespace to associate them with this plugin.\n build.onResolve({ filter: /^https?:\\/\\// }, (args) => ({\n path: args.path,\n namespace: 'http-url',\n }));\n\n // We also want to intercept all import paths inside downloaded files and resolve them against the original URL.\n // All of these files will be in the \"http-url\" namespace.\n // Make sure to keep the newly resolved URL in the \"http-url\" namespace so imports inside it will also be resolved as URLs recursively.\n build.onResolve({ filter: /.*/, namespace: 'http-url' }, (args) => ({\n path: new URL(args.path, args.importer).toString(),\n namespace: 'http-url',\n }));\n\n // When a URL is loaded, we want to actually download the content from the internet.\n // This has just enough logic to be able to handle the example import from unpkg.com but in reality this would probably need to be more complex.\n build.onLoad({ filter: /.*/, namespace: 'http-url' }, async (args) => {\n const response = await fetch(args.path);\n return { contents: await response.text(), loader: 'jsx' };\n });\n },\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;AAKA,0BA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ructor", "_options", "bundle", "path", "source", "sandboxedModules", "providedModules", "createResult", "result", "timestamp", "Date", "now", "sourceHash", "Buffer", "from", "subtleCrypto", "digest", "undefined", "platform", "invariant", "imports", "analyzeSourceFileImports", "build", "conditions", "metafile", "write", "entryPoints", "format", "plugins", "name", "setup", "onResolve", "filter", "external", "split", "namespace", "onLoad", "contents", "loader", "module", "RegExp", "namedImports", "find", "entry", "moduleIdentifier", "join", "JSON", "stringify", "httpPlugin", "log", "analyzeImports", "outputFiles", "text", "err", "error", "parsedImports", "allMatches", "IMPORT_REGEX", "Object", "values", "outputs", "map", "parsedImport", "capture", "NAMED_IMPORTS_REGEX", "lastIndex", "namedImportsMatch", "exec", "forEach", "importName", "push", "trim", "moduleUrl", "defaultImport", "code", "defaultImportName", "wildcardImportName", "quotes", "regex", "str", "match", "matches", "slice", "args", "URL", "importer", "toString", "response", "fetch"]
|
|
7
|
+
}
|
|
@@ -16,15 +16,15 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var
|
|
20
|
-
__export(
|
|
19
|
+
var chunk_2ASAZ4AS_exports = {};
|
|
20
|
+
__export(chunk_2ASAZ4AS_exports, {
|
|
21
21
|
FunctionRegistry: () => FunctionRegistry,
|
|
22
22
|
TriggerRegistry: () => TriggerRegistry,
|
|
23
23
|
createSubscriptionTrigger: () => createSubscriptionTrigger,
|
|
24
24
|
createTimerTrigger: () => createTimerTrigger
|
|
25
25
|
});
|
|
26
|
-
module.exports = __toCommonJS(
|
|
27
|
-
var
|
|
26
|
+
module.exports = __toCommonJS(chunk_2ASAZ4AS_exports);
|
|
27
|
+
var import_chunk_PGFJYL6Q = require("./chunk-PGFJYL6Q.cjs");
|
|
28
28
|
var import_async = require("@dxos/async");
|
|
29
29
|
var import_echo = require("@dxos/client/echo");
|
|
30
30
|
var import_context = require("@dxos/context");
|
|
@@ -85,14 +85,14 @@ var FunctionRegistry = class extends import_context.Resource {
|
|
|
85
85
|
if (!functions?.length) {
|
|
86
86
|
return;
|
|
87
87
|
}
|
|
88
|
-
if (!space.db.graph.schemaRegistry.hasSchema(
|
|
88
|
+
if (!space.db.graph.schemaRegistry.hasSchema(import_chunk_PGFJYL6Q.FunctionDef)) {
|
|
89
89
|
space.db.graph.schemaRegistry.addSchema([
|
|
90
|
-
|
|
90
|
+
import_chunk_PGFJYL6Q.FunctionDef
|
|
91
91
|
]);
|
|
92
92
|
}
|
|
93
|
-
const { objects: existing } = await space.db.query(import_echo.Filter.schema(
|
|
93
|
+
const { objects: existing } = await space.db.query(import_echo.Filter.schema(import_chunk_PGFJYL6Q.FunctionDef)).run();
|
|
94
94
|
const { added } = (0, import_util.diff)(existing, functions, (a, b) => a.uri === b.uri);
|
|
95
|
-
added.forEach((def) => space.db.add((0, import_echo.create)(
|
|
95
|
+
added.forEach((def) => space.db.add((0, import_echo.create)(import_chunk_PGFJYL6Q.FunctionDef, def)));
|
|
96
96
|
if (added.length > 0) {
|
|
97
97
|
await space.db.flush({
|
|
98
98
|
indexes: true,
|
|
@@ -118,7 +118,7 @@ var FunctionRegistry = class extends import_context.Resource {
|
|
|
118
118
|
if (this._ctx.disposed) {
|
|
119
119
|
break;
|
|
120
120
|
}
|
|
121
|
-
this._ctx.onDispose(space.db.query(import_echo.Filter.schema(
|
|
121
|
+
this._ctx.onDispose(space.db.query(import_echo.Filter.schema(import_chunk_PGFJYL6Q.FunctionDef)).subscribe(({ objects }) => {
|
|
122
122
|
const { added } = (0, import_util.diff)(registered, objects, (a, b) => a.uri === b.uri);
|
|
123
123
|
if (added.length > 0) {
|
|
124
124
|
registered.push(...added);
|
|
@@ -335,9 +335,9 @@ var TriggerRegistry = class extends import_context2.Resource {
|
|
|
335
335
|
if (!manifest.triggers?.length) {
|
|
336
336
|
return;
|
|
337
337
|
}
|
|
338
|
-
if (!space.db.graph.schemaRegistry.hasSchema(
|
|
338
|
+
if (!space.db.graph.schemaRegistry.hasSchema(import_chunk_PGFJYL6Q.FunctionTrigger)) {
|
|
339
339
|
space.db.graph.schemaRegistry.addSchema([
|
|
340
|
-
|
|
340
|
+
import_chunk_PGFJYL6Q.FunctionTrigger
|
|
341
341
|
]);
|
|
342
342
|
}
|
|
343
343
|
const manifestTriggers = manifest.triggers.map((trigger) => {
|
|
@@ -351,11 +351,11 @@ var TriggerRegistry = class extends import_context2.Resource {
|
|
|
351
351
|
].join(":"))
|
|
352
352
|
];
|
|
353
353
|
}
|
|
354
|
-
return (0, import_echo3.create)(
|
|
354
|
+
return (0, import_echo3.create)(import_chunk_PGFJYL6Q.FunctionTrigger, trigger, {
|
|
355
355
|
keys
|
|
356
356
|
});
|
|
357
357
|
});
|
|
358
|
-
const { objects: existing } = await space.db.query(import_echo3.Filter.schema(
|
|
358
|
+
const { objects: existing } = await space.db.query(import_echo3.Filter.schema(import_chunk_PGFJYL6Q.FunctionTrigger)).run();
|
|
359
359
|
const { added } = (0, import_util2.diff)(existing, manifestTriggers, import_echo3.compareForeignKeys);
|
|
360
360
|
added.forEach((trigger) => {
|
|
361
361
|
space.db.add(trigger);
|
|
@@ -390,7 +390,7 @@ var TriggerRegistry = class extends import_context2.Resource {
|
|
|
390
390
|
if (this._ctx.disposed) {
|
|
391
391
|
break;
|
|
392
392
|
}
|
|
393
|
-
this._ctx.onDispose(space.db.query(import_echo3.Filter.schema(
|
|
393
|
+
this._ctx.onDispose(space.db.query(import_echo3.Filter.schema(import_chunk_PGFJYL6Q.FunctionTrigger)).subscribe(async ({ objects: current }) => {
|
|
394
394
|
import_log4.log.info("update", {
|
|
395
395
|
space: space.key,
|
|
396
396
|
registered: registered.length,
|
|
@@ -491,4 +491,4 @@ var TriggerRegistry = class extends import_context2.Resource {
|
|
|
491
491
|
createSubscriptionTrigger,
|
|
492
492
|
createTimerTrigger
|
|
493
493
|
});
|
|
494
|
-
//# sourceMappingURL=chunk-
|
|
494
|
+
//# sourceMappingURL=chunk-2ASAZ4AS.cjs.map
|
|
@@ -16,8 +16,8 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var
|
|
20
|
-
__export(
|
|
19
|
+
var chunk_PGFJYL6Q_exports = {};
|
|
20
|
+
__export(chunk_PGFJYL6Q_exports, {
|
|
21
21
|
FUNCTION_TYPES: () => FUNCTION_TYPES,
|
|
22
22
|
FunctionDef: () => FunctionDef,
|
|
23
23
|
FunctionManifestSchema: () => FunctionManifestSchema,
|
|
@@ -28,7 +28,7 @@ __export(chunk_4WNFTPH7_exports, {
|
|
|
28
28
|
TriggerKind: () => TriggerKind,
|
|
29
29
|
TriggerSchema: () => TriggerSchema
|
|
30
30
|
});
|
|
31
|
-
module.exports = __toCommonJS(
|
|
31
|
+
module.exports = __toCommonJS(chunk_PGFJYL6Q_exports);
|
|
32
32
|
var import_echo_schema = require("@dxos/echo-schema");
|
|
33
33
|
var import_schema = require("@dxos/schema");
|
|
34
34
|
var import_echo_schema2 = require("@dxos/echo-schema");
|
|
@@ -57,6 +57,7 @@ var FunctionType = class extends (0, import_echo_schema.TypedObject)({
|
|
|
57
57
|
// TODO(burdon): Don't ref ScriptType directly (core).
|
|
58
58
|
source: import_echo_schema.S.optional((0, import_echo_schema.Ref)(ScriptType)),
|
|
59
59
|
inputSchema: import_echo_schema.S.optional(import_echo_schema.JsonSchemaType),
|
|
60
|
+
outputSchema: import_echo_schema.S.optional(import_echo_schema.JsonSchemaType),
|
|
60
61
|
// Local binding to a function name.
|
|
61
62
|
binding: import_echo_schema.S.optional(import_echo_schema.S.String)
|
|
62
63
|
}) {
|
|
@@ -67,6 +68,7 @@ var TriggerKind;
|
|
|
67
68
|
TriggerKind2["Webhook"] = "webhook";
|
|
68
69
|
TriggerKind2["Subscription"] = "subscription";
|
|
69
70
|
TriggerKind2["Email"] = "email";
|
|
71
|
+
TriggerKind2["Queue"] = "queue";
|
|
70
72
|
})(TriggerKind || (TriggerKind = {}));
|
|
71
73
|
var typeLiteralAnnotations = {
|
|
72
74
|
[import_echo_schema2.AST.TitleAnnotationId]: "Type"
|
|
@@ -83,6 +85,10 @@ var TimerTriggerSchema = import_echo_schema2.S.Struct({
|
|
|
83
85
|
var EmailTriggerSchema = import_echo_schema2.S.Struct({
|
|
84
86
|
type: import_echo_schema2.S.Literal("email").annotations(typeLiteralAnnotations)
|
|
85
87
|
}).pipe(import_echo_schema2.S.mutable);
|
|
88
|
+
var QueueTriggerSchema = import_echo_schema2.S.Struct({
|
|
89
|
+
type: import_echo_schema2.S.Literal("queue").annotations(typeLiteralAnnotations),
|
|
90
|
+
queue: import_echo_schema2.DXN
|
|
91
|
+
}).pipe(import_echo_schema2.S.mutable);
|
|
86
92
|
var WebhookTriggerSchema = import_echo_schema2.S.Struct({
|
|
87
93
|
type: import_echo_schema2.S.Literal("webhook").annotations(typeLiteralAnnotations),
|
|
88
94
|
method: import_echo_schema2.S.optional(import_echo_schema2.S.String.annotations({
|
|
@@ -129,7 +135,8 @@ var TriggerSchema = import_echo_schema2.S.Union(
|
|
|
129
135
|
TimerTriggerSchema,
|
|
130
136
|
WebhookTriggerSchema,
|
|
131
137
|
SubscriptionTriggerSchema,
|
|
132
|
-
EmailTriggerSchema
|
|
138
|
+
EmailTriggerSchema,
|
|
139
|
+
QueueTriggerSchema
|
|
133
140
|
).annotations({
|
|
134
141
|
[import_echo_schema2.AST.TitleAnnotationId]: "Trigger"
|
|
135
142
|
});
|
|
@@ -185,4 +192,4 @@ var FUNCTION_TYPES = [
|
|
|
185
192
|
TriggerKind,
|
|
186
193
|
TriggerSchema
|
|
187
194
|
});
|
|
188
|
-
//# sourceMappingURL=chunk-
|
|
195
|
+
//# sourceMappingURL=chunk-PGFJYL6Q.cjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/types/schema.ts", "../../../src/types/types.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport { JsonSchemaType, Ref, S, TypedObject } from '@dxos/echo-schema';\nimport { TextType } from '@dxos/schema';\n\n/**\n * Source script.\n */\nexport class ScriptType extends TypedObject({\n typename: 'dxos.org/type/Script',\n version: '0.1.0',\n})({\n // TODO(burdon): Change to URI?\n name: S.optional(S.String),\n description: S.optional(S.String),\n // TODO(burdon): Change to hash of deployed content.\n // Whether source has changed since last deploy.\n changed: S.optional(S.Boolean),\n source: Ref(TextType),\n}) {}\n\n/**\n * Function deployment.\n */\n// TODO(burdon): Move to core/functions.\nexport class FunctionType extends TypedObject({\n typename: 'dxos.org/type/Function',\n version: '0.1.0',\n})({\n // TODO(burdon): Rename to id/uri?\n name: S.NonEmptyString,\n version: S.String,\n\n description: S.optional(S.String),\n\n // Reference to a source script if it exists within ECHO.\n // TODO(burdon): Don't ref ScriptType directly (core).\n source: S.optional(Ref(ScriptType)),\n\n inputSchema: S.optional(JsonSchemaType),\n outputSchema: S.optional(JsonSchemaType),\n\n // Local binding to a function name.\n binding: S.optional(S.String),\n}) {}\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { AST, OptionsAnnotationId, RawObject, S, TypedObject, DXN } from '@dxos/echo-schema';\n\n/**\n * Type discriminator for TriggerType.\n * Every spec has a type field of type TriggerKind that we can use to understand which type we're working with.\n * https://www.typescriptlang.org/docs/handbook/2/narrowing.html#discriminated-unions\n */\nexport enum TriggerKind {\n Timer = 'timer',\n Webhook = 'webhook',\n Subscription = 'subscription',\n Email = 'email',\n Queue = 'queue',\n}\n\n// TODO(burdon): Rename prop kind.\nconst typeLiteralAnnotations = { [AST.TitleAnnotationId]: 'Type' };\n\n/**\n * Cron timer.\n */\nconst TimerTriggerSchema = S.Struct({\n type: S.Literal(TriggerKind.Timer).annotations(typeLiteralAnnotations),\n cron: S.String.annotations({\n [AST.TitleAnnotationId]: 'Cron',\n [AST.ExamplesAnnotationId]: ['0 0 * * *'],\n }),\n}).pipe(S.mutable);\n\nexport type TimerTrigger = S.Schema.Type<typeof TimerTriggerSchema>;\n\nconst EmailTriggerSchema = S.Struct({\n type: S.Literal(TriggerKind.Email).annotations(typeLiteralAnnotations),\n}).pipe(S.mutable);\n\nexport type EmailTrigger = S.Schema.Type<typeof EmailTriggerSchema>;\n\nconst QueueTriggerSchema = S.Struct({\n type: S.Literal(TriggerKind.Queue).annotations(typeLiteralAnnotations),\n queue: DXN,\n}).pipe(S.mutable);\n\nexport type QueueTrigger = S.Schema.Type<typeof QueueTriggerSchema>;\n\n/**\n * Webhook.\n */\nconst WebhookTriggerSchema = S.Struct({\n type: S.Literal(TriggerKind.Webhook).annotations(typeLiteralAnnotations),\n method: S.optional(\n S.String.annotations({\n [AST.TitleAnnotationId]: 'Method',\n [OptionsAnnotationId]: ['GET', 'POST'],\n }),\n ),\n port: S.optional(\n S.Number.annotations({\n [AST.TitleAnnotationId]: 'Port',\n }),\n ),\n}).pipe(S.mutable);\n\nexport type WebhookTrigger = S.Schema.Type<typeof WebhookTriggerSchema>;\n\n// TODO(burdon): Use ECHO definition (from https://github.com/dxos/dxos/pull/8233).\nconst QuerySchema = S.Struct({\n type: S.optional(S.String.annotations({ [AST.TitleAnnotationId]: 'Type' })),\n props: S.optional(S.Record({ key: S.String, value: S.Any })),\n}).annotations({ [AST.TitleAnnotationId]: 'Query' });\n\n/**\n * Subscription.\n */\nconst SubscriptionTriggerSchema = S.Struct({\n type: S.Literal(TriggerKind.Subscription).annotations(typeLiteralAnnotations),\n // TODO(burdon): Define query DSL (from ECHO). Reconcile with Table.Query.\n filter: QuerySchema,\n options: S.optional(\n S.Struct({\n // Watch changes to object (not just creation).\n deep: S.optional(S.Boolean.annotations({ [AST.TitleAnnotationId]: 'Nested' })),\n // Debounce changes (delay in ms).\n delay: S.optional(S.Number.annotations({ [AST.TitleAnnotationId]: 'Delay' })),\n }).annotations({ [AST.TitleAnnotationId]: 'Options' }),\n ),\n}).pipe(S.mutable);\n\nexport type SubscriptionTrigger = S.Schema.Type<typeof SubscriptionTriggerSchema>;\n\n/**\n * Trigger schema (discriminated union).\n */\nexport const TriggerSchema = S.Union(\n //\n TimerTriggerSchema,\n WebhookTriggerSchema,\n SubscriptionTriggerSchema,\n EmailTriggerSchema,\n QueueTriggerSchema,\n).annotations({\n [AST.TitleAnnotationId]: 'Trigger',\n});\n\nexport type TriggerType = S.Schema.Type<typeof TriggerSchema>;\n\n/**\n * Function trigger.\n */\nexport const FunctionTriggerSchema = S.Struct({\n // TODO(burdon): What type does this reference.\n function: S.optional(S.String.annotations({ [AST.TitleAnnotationId]: 'Function' })),\n\n enabled: S.optional(S.Boolean.annotations({ [AST.TitleAnnotationId]: 'Enabled' })),\n\n // TODO(burdon): Flatten entire schema.\n spec: S.optional(TriggerSchema),\n\n // TODO(burdon): Get meta from function.\n // The `meta` property is merged into the event data passed to the function.\n meta: S.optional(S.mutable(S.Record({ key: S.String, value: S.Any }))),\n});\n\nexport type FunctionTriggerType = S.Schema.Type<typeof FunctionTriggerSchema>;\n\n/**\n * Function trigger.\n */\nexport class FunctionTrigger extends TypedObject({\n typename: 'dxos.org/type/FunctionTrigger',\n version: '0.1.0',\n})(FunctionTriggerSchema.fields) {}\n\n/**\n * Function definition.\n * @deprecated (Use dxos.org/type/Function)\n */\n// TODO(burdon): Reconcile with FunctionType.\nexport class FunctionDef extends TypedObject({\n typename: 'dxos.org/type/FunctionDef',\n version: '0.1.0',\n})({\n uri: S.String,\n description: S.optional(S.String),\n route: S.String,\n handler: S.String,\n}) {}\n\n/**\n * Function manifest file.\n */\nexport const FunctionManifestSchema = S.Struct({\n functions: S.optional(S.mutable(S.Array(RawObject(FunctionDef)))),\n triggers: S.optional(S.mutable(S.Array(RawObject(FunctionTrigger)))),\n});\n\nexport type FunctionManifest = S.Schema.Type<typeof FunctionManifestSchema>;\n\nexport const FUNCTION_TYPES = [FunctionDef, FunctionTrigger];\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SAAS;AACX,CAAA,EAAGoD,sBAAsBM,MAAM,EAAA;AAAG;AAO3B,IAAMC,cAAN,kBAA0B7D,oBAAAA,aAAY;EAC3CC,UAAU;EACVC,SAAS;AACX,CAAA,EAAG;EACD4D,KAAK1D,oBAAAA,EAAEE;EACPC,aAAaH,oBAAAA,EAAEC,SAASD,oBAAAA,EAAEE,MAAM;EAChCyD,OAAO3D,oBAAAA,EAAEE;EACT0D,SAAS5D,oBAAAA,EAAEE;AACb,CAAA,EAAA;AAAI;AAKG,IAAM2D,yBAAyB7D,oBAAAA,EAAEoB,OAAO;EAC7C0C,WAAW9D,oBAAAA,EAAEC,SAASD,oBAAAA,EAAE2B,QAAQ3B,oBAAAA,EAAE+D,UAAMC,+BAAUP,WAAAA,CAAAA,CAAAA,CAAAA;EAClDQ,UAAUjE,oBAAAA,EAAEC,SAASD,oBAAAA,EAAE2B,QAAQ3B,oBAAAA,EAAE+D,UAAMC,+BAAUT,eAAAA,CAAAA,CAAAA,CAAAA;AACnD,CAAA;AAIO,IAAMW,iBAAiB;EAACT;EAAaF;;",
|
|
6
|
+
"names": ["import_echo_schema", "ScriptType", "TypedObject", "typename", "version", "name", "S", "optional", "String", "description", "changed", "Boolean", "source", "Ref", "TextType", "FunctionType", "NonEmptyString", "inputSchema", "JsonSchemaType", "outputSchema", "binding", "TriggerKind", "typeLiteralAnnotations", "AST", "TitleAnnotationId", "TimerTriggerSchema", "Struct", "type", "Literal", "annotations", "cron", "ExamplesAnnotationId", "pipe", "mutable", "EmailTriggerSchema", "QueueTriggerSchema", "queue", "DXN", "WebhookTriggerSchema", "method", "OptionsAnnotationId", "port", "Number", "QuerySchema", "props", "Record", "key", "value", "Any", "SubscriptionTriggerSchema", "filter", "options", "deep", "delay", "TriggerSchema", "Union", "FunctionTriggerSchema", "function", "enabled", "spec", "meta", "FunctionTrigger", "fields", "FunctionDef", "uri", "route", "handler", "FunctionManifestSchema", "functions", "Array", "RawObject", "triggers", "FUNCTION_TYPES"]
|
|
7
|
+
}
|
package/dist/lib/node/index.cjs
CHANGED
|
@@ -19,19 +19,19 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
19
19
|
var node_exports = {};
|
|
20
20
|
__export(node_exports, {
|
|
21
21
|
FUNCTIONS_PRESET_META_KEY: () => import_chunk_MZMHE4DC.FUNCTIONS_PRESET_META_KEY,
|
|
22
|
-
FUNCTION_TYPES: () =>
|
|
23
|
-
FunctionDef: () =>
|
|
24
|
-
FunctionManifestSchema: () =>
|
|
25
|
-
FunctionRegistry: () =>
|
|
26
|
-
FunctionTrigger: () =>
|
|
27
|
-
FunctionTriggerSchema: () =>
|
|
28
|
-
FunctionType: () =>
|
|
29
|
-
ScriptType: () =>
|
|
30
|
-
TriggerKind: () =>
|
|
31
|
-
TriggerRegistry: () =>
|
|
32
|
-
TriggerSchema: () =>
|
|
33
|
-
createSubscriptionTrigger: () =>
|
|
34
|
-
createTimerTrigger: () =>
|
|
22
|
+
FUNCTION_TYPES: () => import_chunk_PGFJYL6Q.FUNCTION_TYPES,
|
|
23
|
+
FunctionDef: () => import_chunk_PGFJYL6Q.FunctionDef,
|
|
24
|
+
FunctionManifestSchema: () => import_chunk_PGFJYL6Q.FunctionManifestSchema,
|
|
25
|
+
FunctionRegistry: () => import_chunk_2ASAZ4AS.FunctionRegistry,
|
|
26
|
+
FunctionTrigger: () => import_chunk_PGFJYL6Q.FunctionTrigger,
|
|
27
|
+
FunctionTriggerSchema: () => import_chunk_PGFJYL6Q.FunctionTriggerSchema,
|
|
28
|
+
FunctionType: () => import_chunk_PGFJYL6Q.FunctionType,
|
|
29
|
+
ScriptType: () => import_chunk_PGFJYL6Q.ScriptType,
|
|
30
|
+
TriggerKind: () => import_chunk_PGFJYL6Q.TriggerKind,
|
|
31
|
+
TriggerRegistry: () => import_chunk_2ASAZ4AS.TriggerRegistry,
|
|
32
|
+
TriggerSchema: () => import_chunk_PGFJYL6Q.TriggerSchema,
|
|
33
|
+
createSubscriptionTrigger: () => import_chunk_2ASAZ4AS.createSubscriptionTrigger,
|
|
34
|
+
createTimerTrigger: () => import_chunk_2ASAZ4AS.createTimerTrigger,
|
|
35
35
|
getInvocationUrl: () => import_chunk_MZMHE4DC.getInvocationUrl,
|
|
36
36
|
getUserFunctionUrlInMetadata: () => import_chunk_MZMHE4DC.getUserFunctionUrlInMetadata,
|
|
37
37
|
incrementSemverPatch: () => import_chunk_MZMHE4DC.incrementSemverPatch,
|
|
@@ -42,8 +42,8 @@ __export(node_exports, {
|
|
|
42
42
|
});
|
|
43
43
|
module.exports = __toCommonJS(node_exports);
|
|
44
44
|
var import_chunk_MZMHE4DC = require("./chunk-MZMHE4DC.cjs");
|
|
45
|
-
var
|
|
46
|
-
var
|
|
45
|
+
var import_chunk_2ASAZ4AS = require("./chunk-2ASAZ4AS.cjs");
|
|
46
|
+
var import_chunk_PGFJYL6Q = require("./chunk-PGFJYL6Q.cjs");
|
|
47
47
|
var import_chunk_JEQ2X3Z6 = require("./chunk-JEQ2X3Z6.cjs");
|
|
48
48
|
var import_client = require("@dxos/client");
|
|
49
49
|
var import_log = require("@dxos/log");
|