@dxos/functions 0.3.8-next.f4e0086 → 0.3.8
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/README.md +2 -2
- package/dist/lib/browser/index.mjs +203 -164
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +218 -178
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/types/src/handler.d.ts +2 -6
- package/dist/types/src/handler.d.ts.map +1 -1
- package/dist/types/src/manifest.d.ts +3 -2
- package/dist/types/src/manifest.d.ts.map +1 -1
- package/dist/types/src/runtime/dev-server.d.ts +14 -2
- package/dist/types/src/runtime/dev-server.d.ts.map +1 -1
- package/dist/types/src/runtime/index.d.ts +1 -1
- package/dist/types/src/runtime/index.d.ts.map +1 -1
- package/dist/types/src/runtime/{trigger-manager.d.ts → scheduler.d.ts} +9 -7
- package/dist/types/src/runtime/scheduler.d.ts.map +1 -0
- package/package.json +11 -10
- package/src/handler.ts +7 -8
- package/src/manifest.ts +8 -4
- package/src/runtime/dev-server.ts +91 -58
- package/src/runtime/index.ts +1 -1
- package/src/runtime/scheduler.ts +145 -0
- package/dist/types/src/runtime/trigger-manager.d.ts.map +0 -1
- package/src/runtime/trigger-manager.ts +0 -140
|
@@ -1 +1 @@
|
|
|
1
|
-
{"inputs":{"packages/core/functions/src/handler.ts":{"bytes":
|
|
1
|
+
{"inputs":{"packages/core/functions/src/handler.ts":{"bytes":1308,"imports":[],"format":"esm"},"packages/core/functions/src/manifest.ts":{"bytes":1730,"imports":[],"format":"esm"},"packages/core/functions/src/runtime/dev-server.ts":{"bytes":18548,"imports":[{"path":"express","kind":"import-statement","external":true},{"path":"get-port-please","kind":"import-statement","external":true},{"path":"@dxos/node-std/path","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/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":16636,"imports":[{"path":"cron","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/context","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"format":"esm"},"packages/core/functions/src/runtime/index.ts":{"bytes":561,"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/index.ts":{"bytes":632,"imports":[{"path":"packages/core/functions/src/handler.ts","kind":"import-statement","original":"./handler"},{"path":"packages/core/functions/src/manifest.ts","kind":"import-statement","original":"./manifest"},{"path":"packages/core/functions/src/runtime/index.ts","kind":"import-statement","original":"./runtime"}],"format":"esm"}},"outputs":{"packages/core/functions/dist/lib/browser/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":16609},"packages/core/functions/dist/lib/browser/index.mjs":{"imports":[{"path":"express","kind":"import-statement","external":true},{"path":"get-port-please","kind":"import-statement","external":true},{"path":"@dxos/node-std/path","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"cron","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/context","kind":"import-statement","external":true},{"path":"@dxos/echo-schema","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"exports":["DevServer","Scheduler"],"entryPoint":"packages/core/functions/src/index.ts","inputs":{"packages/core/functions/src/index.ts":{"bytesInOutput":0},"packages/core/functions/src/runtime/dev-server.ts":{"bytesInOutput":4734},"packages/core/functions/src/runtime/index.ts":{"bytesInOutput":0},"packages/core/functions/src/runtime/scheduler.ts":{"bytesInOutput":4184}},"bytes":9499}}}
|
package/dist/lib/node/index.cjs
CHANGED
|
@@ -26,64 +26,67 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
26
26
|
mod
|
|
27
27
|
));
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
var src_exports = {};
|
|
32
|
-
__export(src_exports, {
|
|
29
|
+
var node_exports = {};
|
|
30
|
+
__export(node_exports, {
|
|
33
31
|
DevServer: () => DevServer,
|
|
34
|
-
|
|
32
|
+
Scheduler: () => Scheduler
|
|
35
33
|
});
|
|
36
|
-
module.exports = __toCommonJS(
|
|
37
|
-
|
|
38
|
-
// packages/core/functions/src/runtime/dev-server.ts
|
|
34
|
+
module.exports = __toCommonJS(node_exports);
|
|
39
35
|
var import_express = __toESM(require("express"));
|
|
36
|
+
var import_get_port_please = require("get-port-please");
|
|
40
37
|
var import_node_path = require("node:path");
|
|
41
|
-
var import_portfinder = require("portfinder");
|
|
42
38
|
var import_async = require("@dxos/async");
|
|
39
|
+
var import_invariant = require("@dxos/invariant");
|
|
43
40
|
var import_log = require("@dxos/log");
|
|
44
|
-
var
|
|
45
|
-
var
|
|
41
|
+
var import_cron = require("cron");
|
|
42
|
+
var import_async2 = require("@dxos/async");
|
|
43
|
+
var import_context = require("@dxos/context");
|
|
44
|
+
var import_echo_schema = require("@dxos/echo-schema");
|
|
45
|
+
var import_invariant2 = require("@dxos/invariant");
|
|
46
|
+
var import_log2 = require("@dxos/log");
|
|
47
|
+
var import_util = require("@dxos/util");
|
|
48
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
49
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
50
|
+
}) : x)(function(x) {
|
|
51
|
+
if (typeof require !== "undefined")
|
|
52
|
+
return require.apply(this, arguments);
|
|
53
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
54
|
+
});
|
|
55
|
+
var __dxlog_file = "/home/circleci/project/packages/core/functions/src/runtime/dev-server.ts";
|
|
46
56
|
var DevServer = class {
|
|
47
57
|
// prettier-ignore
|
|
48
58
|
constructor(_client, _options) {
|
|
49
59
|
this._client = _client;
|
|
50
60
|
this._options = _options;
|
|
51
61
|
this._handlers = {};
|
|
52
|
-
|
|
53
|
-
get port() {
|
|
54
|
-
return this._port;
|
|
62
|
+
this._seq = 0;
|
|
55
63
|
}
|
|
56
64
|
get endpoint() {
|
|
57
|
-
|
|
65
|
+
(0, import_invariant.invariant)(this._port, void 0, {
|
|
66
|
+
F: __dxlog_file,
|
|
67
|
+
L: 45,
|
|
68
|
+
S: this,
|
|
69
|
+
A: [
|
|
70
|
+
"this._port",
|
|
71
|
+
""
|
|
72
|
+
]
|
|
73
|
+
});
|
|
74
|
+
return `http://localhost:${this._port}`;
|
|
75
|
+
}
|
|
76
|
+
get proxy() {
|
|
77
|
+
return this._proxy;
|
|
58
78
|
}
|
|
59
79
|
get functions() {
|
|
60
80
|
return Object.values(this._handlers);
|
|
61
81
|
}
|
|
62
82
|
async initialize() {
|
|
63
83
|
for (const def of this._options.manifest.functions) {
|
|
64
|
-
const { id, endpoint, handler: path } = def;
|
|
65
84
|
try {
|
|
66
|
-
|
|
67
|
-
const handler = module2.default;
|
|
68
|
-
if (typeof handler !== "function") {
|
|
69
|
-
throw new Error(`Handler must export default function: ${id}`);
|
|
70
|
-
}
|
|
71
|
-
if (this._handlers[endpoint]) {
|
|
72
|
-
import_log.log.warn(`Function already registered: ${id}`, void 0, {
|
|
73
|
-
F: __dxlog_file,
|
|
74
|
-
L: 64,
|
|
75
|
-
S: this,
|
|
76
|
-
C: (f, a) => f(...a)
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
this._handlers[endpoint] = {
|
|
80
|
-
def,
|
|
81
|
-
handler
|
|
82
|
-
};
|
|
85
|
+
await this._load(def);
|
|
83
86
|
} catch (err) {
|
|
84
87
|
import_log.log.error("parsing function (check manifest)", err, {
|
|
85
88
|
F: __dxlog_file,
|
|
86
|
-
L:
|
|
89
|
+
L: 62,
|
|
87
90
|
S: this,
|
|
88
91
|
C: (f, a) => f(...a)
|
|
89
92
|
});
|
|
@@ -93,66 +96,55 @@ var DevServer = class {
|
|
|
93
96
|
async start() {
|
|
94
97
|
const app = (0, import_express.default)();
|
|
95
98
|
app.use(import_express.default.json());
|
|
96
|
-
app.post("/:
|
|
97
|
-
const {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
},
|
|
103
|
-
succeed: (result = {}) => {
|
|
104
|
-
res.end(JSON.stringify(result));
|
|
105
|
-
return response;
|
|
106
|
-
}
|
|
107
|
-
};
|
|
108
|
-
const context = {
|
|
109
|
-
client: this._client,
|
|
110
|
-
status: response.status.bind(response)
|
|
111
|
-
};
|
|
112
|
-
void (async () => {
|
|
113
|
-
try {
|
|
114
|
-
(0, import_log.log)("invoking", {
|
|
115
|
-
endpoint
|
|
116
|
-
}, {
|
|
117
|
-
F: __dxlog_file,
|
|
118
|
-
L: 100,
|
|
119
|
-
S: this,
|
|
120
|
-
C: (f, a) => f(...a)
|
|
121
|
-
});
|
|
122
|
-
const { handler } = this._handlers[endpoint];
|
|
123
|
-
const response2 = await handler({
|
|
124
|
-
context,
|
|
125
|
-
event: req.body
|
|
126
|
-
});
|
|
127
|
-
(0, import_log.log)("done", {
|
|
128
|
-
response: response2
|
|
129
|
-
}, {
|
|
130
|
-
F: __dxlog_file,
|
|
131
|
-
L: 103,
|
|
132
|
-
S: this,
|
|
133
|
-
C: (f, a) => f(...a)
|
|
134
|
-
});
|
|
135
|
-
} catch (err) {
|
|
136
|
-
res.statusCode = 500;
|
|
137
|
-
res.end(err.message);
|
|
99
|
+
app.post("/:name", async (req, res) => {
|
|
100
|
+
const { name } = req.params;
|
|
101
|
+
try {
|
|
102
|
+
if (this._options.reload) {
|
|
103
|
+
const { def } = this._handlers[name];
|
|
104
|
+
await this._load(def, true);
|
|
138
105
|
}
|
|
139
|
-
|
|
106
|
+
res.statusCode = await this._invoke(name, req.body);
|
|
107
|
+
res.end();
|
|
108
|
+
} catch (err) {
|
|
109
|
+
import_log.log.error(err, void 0, {
|
|
110
|
+
F: __dxlog_file,
|
|
111
|
+
L: 82,
|
|
112
|
+
S: this,
|
|
113
|
+
C: (f, a) => f(...a)
|
|
114
|
+
});
|
|
115
|
+
res.statusCode = 500;
|
|
116
|
+
res.end();
|
|
117
|
+
}
|
|
140
118
|
});
|
|
141
|
-
this._port = await (0,
|
|
142
|
-
|
|
119
|
+
this._port = await (0, import_get_port_please.getPort)({
|
|
120
|
+
port: 7200,
|
|
121
|
+
portRange: [
|
|
122
|
+
7200,
|
|
123
|
+
7299
|
|
124
|
+
]
|
|
143
125
|
});
|
|
144
126
|
this._server = app.listen(this._port);
|
|
145
127
|
try {
|
|
146
|
-
const { registrationId } = await this._client.services.services.FunctionRegistryService.register({
|
|
128
|
+
const { registrationId, endpoint } = await this._client.services.services.FunctionRegistryService.register({
|
|
147
129
|
endpoint: this.endpoint,
|
|
148
|
-
functions: this.functions.map(({ def: {
|
|
149
|
-
name
|
|
130
|
+
functions: this.functions.map(({ def: { name } }) => ({
|
|
131
|
+
name
|
|
150
132
|
}))
|
|
151
133
|
});
|
|
134
|
+
import_log.log.info("registered", {
|
|
135
|
+
registrationId,
|
|
136
|
+
endpoint
|
|
137
|
+
}, {
|
|
138
|
+
F: __dxlog_file,
|
|
139
|
+
L: 98,
|
|
140
|
+
S: this,
|
|
141
|
+
C: (f, a) => f(...a)
|
|
142
|
+
});
|
|
152
143
|
this._registrationId = registrationId;
|
|
144
|
+
this._proxy = endpoint;
|
|
153
145
|
} catch (err) {
|
|
154
146
|
await this.stop();
|
|
155
|
-
throw new Error("FunctionRegistryService not available
|
|
147
|
+
throw new Error("FunctionRegistryService not available (check plugin is configured).");
|
|
156
148
|
}
|
|
157
149
|
}
|
|
158
150
|
async stop() {
|
|
@@ -162,31 +154,101 @@ var DevServer = class {
|
|
|
162
154
|
await this._client.services.services.FunctionRegistryService.unregister({
|
|
163
155
|
registrationId: this._registrationId
|
|
164
156
|
});
|
|
157
|
+
import_log.log.info("unregistered", {
|
|
158
|
+
registrationId: this._registrationId
|
|
159
|
+
}, {
|
|
160
|
+
F: __dxlog_file,
|
|
161
|
+
L: 115,
|
|
162
|
+
S: this,
|
|
163
|
+
C: (f, a) => f(...a)
|
|
164
|
+
});
|
|
165
165
|
this._registrationId = void 0;
|
|
166
|
+
this._proxy = void 0;
|
|
166
167
|
}
|
|
167
168
|
trigger.wake();
|
|
168
169
|
});
|
|
169
170
|
await trigger.wait();
|
|
170
|
-
this._server = void 0;
|
|
171
171
|
this._port = void 0;
|
|
172
|
+
this._server = void 0;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Load function.
|
|
176
|
+
*/
|
|
177
|
+
async _load(def, flush = false) {
|
|
178
|
+
const { id, name, handler } = def;
|
|
179
|
+
const path = (0, import_node_path.join)(this._options.directory, handler);
|
|
180
|
+
import_log.log.info("loading", {
|
|
181
|
+
id
|
|
182
|
+
}, {
|
|
183
|
+
F: __dxlog_file,
|
|
184
|
+
L: 134,
|
|
185
|
+
S: this,
|
|
186
|
+
C: (f, a) => f(...a)
|
|
187
|
+
});
|
|
188
|
+
if (flush) {
|
|
189
|
+
Object.keys(__require.cache).filter((key) => key.startsWith(path)).forEach((key) => delete __require.cache[key]);
|
|
190
|
+
}
|
|
191
|
+
const module2 = __require(path);
|
|
192
|
+
if (typeof module2.default !== "function") {
|
|
193
|
+
throw new Error(`Handler must export default function: ${id}`);
|
|
194
|
+
}
|
|
195
|
+
this._handlers[name] = {
|
|
196
|
+
def,
|
|
197
|
+
handler: module2.default
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Invoke function handler.
|
|
202
|
+
*/
|
|
203
|
+
async _invoke(name, event) {
|
|
204
|
+
const seq = ++this._seq;
|
|
205
|
+
const now = Date.now();
|
|
206
|
+
import_log.log.info("req", {
|
|
207
|
+
seq,
|
|
208
|
+
name
|
|
209
|
+
}, {
|
|
210
|
+
F: __dxlog_file,
|
|
211
|
+
L: 159,
|
|
212
|
+
S: this,
|
|
213
|
+
C: (f, a) => f(...a)
|
|
214
|
+
});
|
|
215
|
+
const { handler } = this._handlers[name];
|
|
216
|
+
const context = {
|
|
217
|
+
client: this._client
|
|
218
|
+
};
|
|
219
|
+
let statusCode = 200;
|
|
220
|
+
const response = {
|
|
221
|
+
status: (code) => {
|
|
222
|
+
statusCode = code;
|
|
223
|
+
return response;
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
await handler({
|
|
227
|
+
context,
|
|
228
|
+
event,
|
|
229
|
+
response
|
|
230
|
+
});
|
|
231
|
+
import_log.log.info("res", {
|
|
232
|
+
seq,
|
|
233
|
+
name,
|
|
234
|
+
statusCode,
|
|
235
|
+
duration: Date.now() - now
|
|
236
|
+
}, {
|
|
237
|
+
F: __dxlog_file,
|
|
238
|
+
L: 175,
|
|
239
|
+
S: this,
|
|
240
|
+
C: (f, a) => f(...a)
|
|
241
|
+
});
|
|
242
|
+
return statusCode;
|
|
172
243
|
}
|
|
173
244
|
};
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
var import_context = require("@dxos/context");
|
|
178
|
-
var import_echo_schema = require("@dxos/echo-schema");
|
|
179
|
-
var import_invariant = require("@dxos/invariant");
|
|
180
|
-
var import_log2 = require("@dxos/log");
|
|
181
|
-
var import_util = require("@dxos/util");
|
|
182
|
-
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/core/functions/src/runtime/trigger-manager.ts";
|
|
183
|
-
var TriggerManager = class {
|
|
184
|
-
constructor(_client, _manifest, _invokeOptions) {
|
|
245
|
+
var __dxlog_file2 = "/home/circleci/project/packages/core/functions/src/runtime/scheduler.ts";
|
|
246
|
+
var Scheduler = class {
|
|
247
|
+
constructor(_client, _manifest, _options) {
|
|
185
248
|
this._client = _client;
|
|
186
249
|
this._manifest = _manifest;
|
|
187
|
-
this.
|
|
188
|
-
this._mounts = new import_util.ComplexMap(({
|
|
189
|
-
this._queries = /* @__PURE__ */ new Set();
|
|
250
|
+
this._options = _options;
|
|
251
|
+
this._mounts = new import_util.ComplexMap(({ id, spaceKey }) => `${spaceKey.toHex()}:${id}`);
|
|
190
252
|
}
|
|
191
253
|
async start() {
|
|
192
254
|
this._client.spaces.subscribe(async (spaces) => {
|
|
@@ -199,22 +261,22 @@ var TriggerManager = class {
|
|
|
199
261
|
});
|
|
200
262
|
}
|
|
201
263
|
async stop() {
|
|
202
|
-
for (const {
|
|
203
|
-
await this.unmount(
|
|
264
|
+
for (const { id, spaceKey } of this._mounts.keys()) {
|
|
265
|
+
await this.unmount(id, spaceKey);
|
|
204
266
|
}
|
|
205
267
|
}
|
|
206
268
|
async mount(ctx, space, trigger) {
|
|
207
269
|
const key = {
|
|
208
|
-
|
|
270
|
+
id: trigger.function,
|
|
209
271
|
spaceKey: space.key
|
|
210
272
|
};
|
|
211
|
-
const
|
|
212
|
-
(0,
|
|
273
|
+
const def = this._manifest.functions.find((config) => config.id === trigger.function);
|
|
274
|
+
(0, import_invariant2.invariant)(def, `Function not found: ${trigger.function}`, {
|
|
213
275
|
F: __dxlog_file2,
|
|
214
|
-
L:
|
|
276
|
+
L: 59,
|
|
215
277
|
S: this,
|
|
216
278
|
A: [
|
|
217
|
-
"
|
|
279
|
+
"def",
|
|
218
280
|
"`Function not found: ${trigger.function}`"
|
|
219
281
|
]
|
|
220
282
|
});
|
|
@@ -229,57 +291,55 @@ var TriggerManager = class {
|
|
|
229
291
|
trigger
|
|
230
292
|
}, {
|
|
231
293
|
F: __dxlog_file2,
|
|
232
|
-
L:
|
|
294
|
+
L: 64,
|
|
233
295
|
S: this,
|
|
234
296
|
C: (f, a) => f(...a)
|
|
235
297
|
});
|
|
236
298
|
if (ctx.disposed) {
|
|
237
299
|
return;
|
|
238
300
|
}
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
301
|
+
if (trigger.schedule) {
|
|
302
|
+
const task = new import_async2.DeferredTask(ctx, async () => {
|
|
303
|
+
await this.execFunction(def, {
|
|
304
|
+
space: space.key
|
|
305
|
+
});
|
|
244
306
|
});
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
space: space.key,
|
|
257
|
-
objects: objectIds.size,
|
|
258
|
-
count
|
|
259
|
-
}, {
|
|
260
|
-
F: __dxlog_file2,
|
|
261
|
-
L: 85,
|
|
262
|
-
S: this,
|
|
263
|
-
C: (f, a) => f(...a)
|
|
307
|
+
const job = new import_cron.CronJob(trigger.schedule, () => task.schedule());
|
|
308
|
+
job.start();
|
|
309
|
+
ctx.onDispose(() => job.stop());
|
|
310
|
+
}
|
|
311
|
+
if (trigger.subscription) {
|
|
312
|
+
const objectIds = /* @__PURE__ */ new Set();
|
|
313
|
+
const task = new import_async2.DeferredTask(ctx, async () => {
|
|
314
|
+
await this.execFunction(def, {
|
|
315
|
+
space: space.key,
|
|
316
|
+
objects: Array.from(objectIds)
|
|
317
|
+
});
|
|
264
318
|
});
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
subscription
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
319
|
+
const subscription = (0, import_echo_schema.createSubscription)(({ added, updated }) => {
|
|
320
|
+
for (const object of added) {
|
|
321
|
+
objectIds.add(object.id);
|
|
322
|
+
}
|
|
323
|
+
for (const object of updated) {
|
|
324
|
+
objectIds.add(object.id);
|
|
325
|
+
}
|
|
326
|
+
task.schedule();
|
|
327
|
+
});
|
|
328
|
+
const { type, props } = trigger.subscription;
|
|
329
|
+
const query = space.db.query(import_echo_schema.Filter.typename(type, props));
|
|
330
|
+
const unsubscribe = query.subscribe(({ objects }) => {
|
|
331
|
+
subscription.update(objects);
|
|
332
|
+
}, true);
|
|
333
|
+
ctx.onDispose(() => {
|
|
334
|
+
subscription.unsubscribe();
|
|
335
|
+
unsubscribe();
|
|
336
|
+
});
|
|
337
|
+
}
|
|
278
338
|
}
|
|
279
339
|
}
|
|
280
|
-
async unmount(
|
|
340
|
+
async unmount(id, spaceKey) {
|
|
281
341
|
const key = {
|
|
282
|
-
|
|
342
|
+
id,
|
|
283
343
|
spaceKey
|
|
284
344
|
};
|
|
285
345
|
const { ctx } = this._mounts.get(key) ?? {};
|
|
@@ -288,59 +348,39 @@ var TriggerManager = class {
|
|
|
288
348
|
await ctx.dispose();
|
|
289
349
|
}
|
|
290
350
|
}
|
|
291
|
-
async execFunction(
|
|
292
|
-
const { endpoint, runtime } = options;
|
|
293
|
-
(0, import_invariant.invariant)(endpoint, "Missing endpoint", {
|
|
294
|
-
F: __dxlog_file2,
|
|
295
|
-
L: 121,
|
|
296
|
-
S: this,
|
|
297
|
-
A: [
|
|
298
|
-
"endpoint",
|
|
299
|
-
"'Missing endpoint'"
|
|
300
|
-
]
|
|
301
|
-
});
|
|
302
|
-
(0, import_invariant.invariant)(runtime, "Missing runtime", {
|
|
303
|
-
F: __dxlog_file2,
|
|
304
|
-
L: 122,
|
|
305
|
-
S: this,
|
|
306
|
-
A: [
|
|
307
|
-
"runtime",
|
|
308
|
-
"'Missing runtime'"
|
|
309
|
-
]
|
|
310
|
-
});
|
|
351
|
+
async execFunction(def, data) {
|
|
311
352
|
try {
|
|
312
|
-
(0, import_log2.log)("
|
|
313
|
-
function:
|
|
353
|
+
(0, import_log2.log)("request", {
|
|
354
|
+
function: def.id
|
|
314
355
|
}, {
|
|
315
356
|
F: __dxlog_file2,
|
|
316
|
-
L:
|
|
357
|
+
L: 130,
|
|
317
358
|
S: this,
|
|
318
359
|
C: (f, a) => f(...a)
|
|
319
360
|
});
|
|
320
|
-
const
|
|
321
|
-
const res = await fetch(url, {
|
|
361
|
+
const response = await fetch(`${this._options.endpoint}/${def.name}`, {
|
|
322
362
|
method: "POST",
|
|
323
|
-
body: JSON.stringify(data),
|
|
324
363
|
headers: {
|
|
325
364
|
"Content-Type": "application/json"
|
|
326
|
-
}
|
|
365
|
+
},
|
|
366
|
+
body: JSON.stringify(data)
|
|
327
367
|
});
|
|
328
368
|
(0, import_log2.log)("result", {
|
|
329
|
-
function:
|
|
330
|
-
result:
|
|
369
|
+
function: def.id,
|
|
370
|
+
result: response.status
|
|
331
371
|
}, {
|
|
332
372
|
F: __dxlog_file2,
|
|
333
|
-
L:
|
|
373
|
+
L: 140,
|
|
334
374
|
S: this,
|
|
335
375
|
C: (f, a) => f(...a)
|
|
336
376
|
});
|
|
337
377
|
} catch (err) {
|
|
338
378
|
import_log2.log.error("error", {
|
|
339
|
-
function:
|
|
379
|
+
function: def.id,
|
|
340
380
|
error: err.message
|
|
341
381
|
}, {
|
|
342
382
|
F: __dxlog_file2,
|
|
343
|
-
L:
|
|
383
|
+
L: 142,
|
|
344
384
|
S: this,
|
|
345
385
|
C: (f, a) => f(...a)
|
|
346
386
|
});
|
|
@@ -350,6 +390,6 @@ var TriggerManager = class {
|
|
|
350
390
|
// Annotate the CommonJS export names for ESM import in node:
|
|
351
391
|
0 && (module.exports = {
|
|
352
392
|
DevServer,
|
|
353
|
-
|
|
393
|
+
Scheduler
|
|
354
394
|
});
|
|
355
395
|
//# sourceMappingURL=index.cjs.map
|