@coda-console/plugin-check 0.8.29 → 0.8.30
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,10 +1,11 @@
|
|
|
1
1
|
// The plugin host's modules (docs/plugins.md「插件宿主」): each plugin's that has a `main`, loaded the first time anything
|
|
2
2
|
// of it is needed, or when the backend says to, and given a `coda` of its own. What the runner (adapters/plugin-host-runner.mjs)
|
|
3
3
|
// runs over Node's IPC channel with the backend, and the test host (adapters/plugin-test-host.mjs) over a channel of its own:
|
|
4
|
-
// `send(message)` to the backend, `receive(message)` from it. `adopt(plugin, token,
|
|
5
|
-
// loaded, for whoever holds it to activate a module with; `stop()`: each module loaded
|
|
4
|
+
// `send(message)` to the backend, `receive(message)` from it. `adopt(plugin, token, pluginSetup?)`: a plugin's `coda` made with no
|
|
5
|
+
// module loaded, for whoever holds it to activate a module with, its `pluginSetup` the one given; `stop()`: each module loaded
|
|
6
|
+
// ends what it started (`deactivate`).
|
|
6
7
|
//
|
|
7
|
-
// From the backend: `start { api: { url }
|
|
8
|
+
// From the backend: `start { api: { url } }`, `activate { plugin, token }` (before anything else of the plugin's),
|
|
8
9
|
// `open { instance, plugin, view, context, caller }`, `query { plugin, request, deadline }`, `run { plugin, call }` and
|
|
9
10
|
// `resume { plugin, call }`, and `cancel { id, reason }` of any of them, `mode { plugin, mode, hook, context }` (a request
|
|
10
11
|
// each), and `message`, `callProgress { id, value }` (a `call`'s progress, by the request's ID), `context`, `close { instance, … }`, `changed { watch, events }`, `settingsChanged { plugin,
|
|
@@ -13,7 +14,7 @@
|
|
|
13
14
|
// of a process it started (adapters/process-relay.mjs). To it: `post { instance, message }`, `change { instance,
|
|
14
15
|
// collection, type, id, object }`, `unwatch { watch }`, `cancel { id }` of a `query` or a `question`, `progress { run,
|
|
15
16
|
// value }` of a `run`, `drained`, `kill` of a process, and the requests `settings`
|
|
16
|
-
// (the plugin's own, as they are now), `watch { collection, selector }`, `tell { session, text }`, `
|
|
17
|
+
// (the plugin's own, as they are now), `watch { collection, selector }`, `tell { session, text }`, `pluginSetup { method,
|
|
17
18
|
// args }`, `provider { method, args }`, `serviceRegister { id, port, secret }`, `serviceUnregister { id }`, `query { record,
|
|
18
19
|
// operation, input, timeout, deadline }`, `call { record, operation, input, id, timeout, deadline, under, progress }`, `spawn { under, process, command, args, cwd, env, name }`, each with the
|
|
19
20
|
// module's `token`, by which the backend knows the plugin it is of, never by what it names; and `question { run,
|
|
@@ -27,14 +28,12 @@ import { pathToFileURL } from 'node:url';
|
|
|
27
28
|
import { callingAPI, canceled, codaError, failed, failureOf, givenUp, providerAPI, queryingAPI } from './provider-api.mjs';
|
|
28
29
|
import { queryId } from './plugin-command.mjs';
|
|
29
30
|
import { pluginEvents } from './plugin-events.mjs';
|
|
31
|
+
import { pluginSetupAPI } from './plugin-setup-api.mjs';
|
|
30
32
|
|
|
31
33
|
export function pluginModules({ send }) {
|
|
32
34
|
// This machine's Coda, as `start` gives it: its address only. Each module reaches it with its own plugin's token, given
|
|
33
35
|
// with `activate` and kept in its own `coda` only.
|
|
34
36
|
let api = null;
|
|
35
|
-
// The parts of `coda` others provide (components/plugins/plugin-host.mjs provide), as `start` names them: each made of the
|
|
36
|
-
// calls it asks by what its module exports (`make`).
|
|
37
|
-
let parts = Promise.resolve([]);
|
|
38
37
|
const loading = new Map(), instances = new Map(), asked = new Map(), watches = new Map();
|
|
39
38
|
// The queries and doing calls being handled, by the backend's request: each called off with the reason the backend gives
|
|
40
39
|
// (`cancel`).
|
|
@@ -198,10 +197,9 @@ export function pluginModules({ send }) {
|
|
|
198
197
|
return entry.value;
|
|
199
198
|
};
|
|
200
199
|
|
|
201
|
-
// What a plugin's module is given: this plugin's own
|
|
202
|
-
//
|
|
203
|
-
|
|
204
|
-
function codaFor(plugin, provided, token) {
|
|
200
|
+
// What a plugin's module is given: this plugin's own, `pluginSetup` asking the backend unless another is given.
|
|
201
|
+
// `token`: this plugin's for this host process, brought with every request it asks (`asks`).
|
|
202
|
+
function codaFor(plugin, token, pluginSetup = null) {
|
|
205
203
|
const views = new Map(), protocols = new Map(), operations = new Map();
|
|
206
204
|
const asks = (method, params, signal = null, progress = null) => ask(method, { ...params, token }, signal, progress);
|
|
207
205
|
const services = pluginServices(asks);
|
|
@@ -244,7 +242,8 @@ export function pluginModules({ send }) {
|
|
|
244
242
|
put: (record, value) => write('putRecord', [record, value]),
|
|
245
243
|
delete: record => write('deleteRecord', [record]),
|
|
246
244
|
replace: (kind, entries) => write('replaceRecords', [kind, entries]),
|
|
247
|
-
|
|
245
|
+
// Another plugin's setup run again (docs/plugins.md「准备运行环境」).
|
|
246
|
+
pluginSetup: Object.freeze(pluginSetup ?? pluginSetupAPI((method, args) => asks('pluginSetup', { method, args }))),
|
|
248
247
|
views: Object.freeze({
|
|
249
248
|
register(id, provider) {
|
|
250
249
|
if (typeof id !== 'string' || typeof provider?.open !== 'function') throw new TypeError('views.register(视图 ID, { open(view) })');
|
|
@@ -296,7 +295,7 @@ export function pluginModules({ send }) {
|
|
|
296
295
|
function load(plugin, token) {
|
|
297
296
|
if (!loading.has(plugin.id)) {
|
|
298
297
|
const loaded = (async () => {
|
|
299
|
-
const made = codaFor(plugin,
|
|
298
|
+
const made = codaFor(plugin, token);
|
|
300
299
|
try {
|
|
301
300
|
const module = await import(pathToFileURL(join(plugin.path, plugin.main)).href);
|
|
302
301
|
if (typeof module.activate !== 'function') throw new Error(`${plugin.main} 没有导出 activate`);
|
|
@@ -312,10 +311,7 @@ export function pluginModules({ send }) {
|
|
|
312
311
|
const activated = plugin => loading.get(plugin.id) ?? Promise.reject(new Error(`插件 ${plugin.id} 还没有激活`));
|
|
313
312
|
|
|
314
313
|
const handlers = {
|
|
315
|
-
start(params) {
|
|
316
|
-
api = params.api;
|
|
317
|
-
parts = Promise.all(params.parts.map(async ({ name, module, make }) => [name, (await import(module))[make]]));
|
|
318
|
-
},
|
|
314
|
+
start(params) { api = params.api; },
|
|
319
315
|
// A plugin's module, loaded the first time anything of it is needed, or as soon as the backend has started.
|
|
320
316
|
async activate({ plugin, token }) { await load(plugin, token); },
|
|
321
317
|
async open({ instance, plugin, view, context, caller }) {
|
|
@@ -504,8 +500,8 @@ export function pluginModules({ send }) {
|
|
|
504
500
|
if (typeof module?.deactivate === 'function') await module.deactivate();
|
|
505
501
|
})));
|
|
506
502
|
const adopted = new Map();
|
|
507
|
-
function adopt(plugin, token,
|
|
508
|
-
const made = codaFor(plugin,
|
|
503
|
+
function adopt(plugin, token, pluginSetup = null) {
|
|
504
|
+
const made = codaFor(plugin, token, pluginSetup);
|
|
509
505
|
adopted.set(plugin.id, made);
|
|
510
506
|
loading.set(plugin.id, Promise.resolve(made));
|
|
511
507
|
return made.coda;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
// What a plugin's module is given as `coda.pluginSetup` (adapters/plugin-modules.mjs `codaFor`; answered by components/plugins/plugin-setup.mjs `setupRequests`): `retry(plugin)`,
|
|
2
|
+
// an installed plugin's setup run again, asked as the module's own plugin, never as that one.
|
|
3
|
+
export function pluginSetupAPI(call) {
|
|
4
|
+
return { retry: plugin => call('retry', [plugin]) };
|
|
5
|
+
}
|
|
@@ -84,9 +84,9 @@ export function createTestHost({ plugin = {}, call = null, clock = new Clock(),
|
|
|
84
84
|
const ending = new AbortController();
|
|
85
85
|
// What the module sends the backend, taken after the turn it is sent in, as over a process's channel.
|
|
86
86
|
const modules = pluginModules({ send: message => queueMicrotask(() => taken(message)) });
|
|
87
|
-
// `coda.pluginSetup
|
|
88
|
-
const setup =
|
|
89
|
-
const coda = modules.adopt(described, randomUUID(),
|
|
87
|
+
// `coda.pluginSetup` is there as the module has it, but fails: the test host has no backend to ask.
|
|
88
|
+
const setup = { retry: async () => { throw refused('unsupported', '测试宿主不提供 coda.pluginSetup'); } };
|
|
89
|
+
const coda = modules.adopt(described, randomUUID(), setup);
|
|
90
90
|
// The records, by kind, each an entry (`{ owner, location, id, plugin, local, spec, status, labels?, version }`) by its holder and
|
|
91
91
|
// ID, and the keys of those of each kind the plugin holds, by their IDs (record-rules.mjs `recordId`); and the module's
|
|
92
92
|
// watches of them, by the watch's key, each with what it was last told.
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// What a plugin's reads and writes of the records (coda#2749 3.7, `coda.get`, `list`, `put`, `replace`) are held to,
|
|
2
2
|
// wherever they are answered: by the backend (./mirror.mjs, ./providers.mjs, ./protocols.mjs) and by a plugin's test host
|
|
3
3
|
// (adapters/plugin-test-host.mjs).
|
|
4
|
+
import { protocolShortName } from '@coda-console/protocol/protocol';
|
|
4
5
|
import { requireCondition as check } from '../../domain/errors.mjs';
|
|
5
6
|
import { derivedUUID } from '../../domain/values.mjs';
|
|
6
7
|
|
|
@@ -13,6 +14,13 @@ import { derivedUUID } from '../../domain/values.mjs';
|
|
|
13
14
|
// the record directory, which the other backends of a space copy.
|
|
14
15
|
export const LOCAL_KINDS = new Set(['coda/composer@1', 'coda/submission@1', 'coda/run@1', 'coda/thread@1', 'coda/project@1', 'coda/card@1',
|
|
15
16
|
'coda/plugin@1', 'coda/usage@1', 'coda/accord@1', 'coda/workflow@1', 'coda/workflow-run@1']);
|
|
17
|
+
export const mirrorPlural = kind => protocolShortName(kind);
|
|
18
|
+
// A kind's records in the record directory are of its plural: the one its definition names, which only Coda's own
|
|
19
|
+
// definitions do (the core protocols'; a plugin's definition's `plural` is dropped as it is
|
|
20
|
+
// installed, providers.mjs `install`), else its short name. migrate-v254.mjs keeps a fixed copy of this rule.
|
|
21
|
+
export const pluralOf = definition => definition.plural ?? mirrorPlural(definition.kind);
|
|
22
|
+
/** What the directory says as it refuses a record over its size (coda-directory src/directory.mjs `put`). */
|
|
23
|
+
export const TOO_LARGE = /^the record is \d+ bytes, more than \d+$/;
|
|
16
24
|
// `list(kind, { scope?, id?, labels? })`: this machine's records (`local`) or this machine's and the others' (`available`,
|
|
17
25
|
// unsaid), all of them, those of an ID, or those whose labels have each of these values (`labels`, as Kubernetes' equality
|
|
18
26
|
// selector: nothing but equality).
|
package/check/coda/contract.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"commit": "
|
|
2
|
+
"commit": "6b6dba1b6e1fc82c2a5703c7513a2612f7342051",
|
|
3
3
|
"apiLevel": 8,
|
|
4
4
|
"packages": {
|
|
5
5
|
"@0dep/piso": "5.2.0",
|
|
@@ -11,17 +11,18 @@
|
|
|
11
11
|
"files": {
|
|
12
12
|
"check/coda/application/contributions.mjs": "30fb6eb01a4a26cc34df79655818a15aa6e846f34128752ca3c7a892939179da",
|
|
13
13
|
"check/coda/components/protocols/protocol-events.mjs": "076f335287d0398c602ad6db286ab0001dc00ac42d32a23918a66ee37c3e9a2f",
|
|
14
|
-
"check/coda/components/protocols/record-rules.mjs": "
|
|
14
|
+
"check/coda/components/protocols/record-rules.mjs": "9b3b8f4307a77f9beb658e62c11c9e8fa39ec6b3cc93516e845e7083e303df44",
|
|
15
15
|
"check/coda/components/protocols/types.mjs": "283cd0f4516f10637d6fe257fe645ead87912219d471c06408d56617f244e1d1",
|
|
16
16
|
"check/coda/adapters/provider-api.mjs": "70441ea2a417ede13e04113ec254496883be3186f291ef5ee65834f35009eb9e",
|
|
17
17
|
"check/coda/adapters/call-limit.mjs": "7e86d95ff7b0a88955015904ec91ae55e78fad816d06f710d6e62af53ccbdeab",
|
|
18
18
|
"check/coda/adapters/clock.mjs": "79733b9ac3807b3da147fe8b782318a1cb42d1d51b9c8b81a507c13c7a8025fd",
|
|
19
19
|
"check/coda/adapters/plugin-command.mjs": "47bd580f7142780933315f64d4562d23a61f996b3f411cfb583333261b590ee8",
|
|
20
20
|
"check/coda/adapters/plugin-events.mjs": "4435aabd04b072069bf8af58663c81130b42821faf4905133fbf523bc64f9f6d",
|
|
21
|
-
"check/coda/adapters/plugin-modules.mjs": "
|
|
21
|
+
"check/coda/adapters/plugin-modules.mjs": "0ae151faa26c5682ace16c36d42c32f02986e16b15674a55dbadefd79766aa63",
|
|
22
|
+
"check/coda/adapters/plugin-setup-api.mjs": "82239b1572de05367c134c9a9f0491fa8cc54a56655dcc7b0e346227e0a900b1",
|
|
22
23
|
"check/coda/adapters/plugin-stream-services.mjs": "1e92eb3dd9d844d4f2773a60bc2941aae3c9cda10d9e96e31de9f09f51e672e5",
|
|
23
24
|
"check/coda/adapters/plugin-test-host.d.mts": "7cb271a61cdb8f704e21e003e70d9962308aeecc4f95ec1ff3bf92cdf134b6be",
|
|
24
|
-
"check/coda/adapters/plugin-test-host.mjs": "
|
|
25
|
+
"check/coda/adapters/plugin-test-host.mjs": "6cebdef12df571ad8bbd340844deeeb12e1a44af443c6038b43573944883334d",
|
|
25
26
|
"check/coda/adapters/process-relay.mjs": "5d379bd7ad07138d69c7accbe769d71294843399539bdf1fab8b6a1ddf13b9d8",
|
|
26
27
|
"check/coda/components/composers/contributions.mjs": "43d3e15fb1f63b7b5c20716030d9537613809ed5cc2fb466a3678bfa308f9f92",
|
|
27
28
|
"check/coda/components/concurrency-groups/schemas.mjs": "3c422044c637dee10565fb1b8bdc75b9c6a31e3b600ed223b7e5e345e1baf092",
|