@kubohiroya/turbowarp-cloudflare-worker 0.7.0 → 0.8.0
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.
|
@@ -9561,31 +9561,63 @@ var fixedInputEditors = [...new Set(fields.map((f) => f.opcode))].map((opcode) =
|
|
|
9561
9561
|
settings: null
|
|
9562
9562
|
})
|
|
9563
9563
|
}));
|
|
9564
|
-
/**
|
|
9564
|
+
/**
|
|
9565
|
+
* Registration follows the advertised opcode membership and the optional host capability.
|
|
9566
|
+
*
|
|
9567
|
+
* Every project load disposes the runtime, which releases the registrations, but the extension
|
|
9568
|
+
* stays loaded for the next project: the same membership is registered again once that project
|
|
9569
|
+
* has loaded. Only `dispose()` is final.
|
|
9570
|
+
*/
|
|
9565
9571
|
function fixedInputRegistration(scratch) {
|
|
9566
9572
|
const host = scratch ?? {};
|
|
9567
9573
|
let active;
|
|
9568
9574
|
let membership = "";
|
|
9575
|
+
let lastOpcodes;
|
|
9569
9576
|
const removers = [];
|
|
9570
9577
|
let stopped = false;
|
|
9578
|
+
let released = false;
|
|
9579
|
+
let listening = false;
|
|
9571
9580
|
const clear = () => {
|
|
9572
|
-
host.vm?.runtime?.off?.("RUNTIME_DISPOSED", shutdown);
|
|
9573
9581
|
for (const remove of removers.splice(0).reverse()) remove();
|
|
9574
9582
|
active = void 0;
|
|
9575
9583
|
membership = "";
|
|
9576
9584
|
};
|
|
9585
|
+
const unlisten = () => {
|
|
9586
|
+
if (!listening) return;
|
|
9587
|
+
host.vm?.runtime?.off?.("RUNTIME_DISPOSED", runtimeDisposed);
|
|
9588
|
+
host.vm?.runtime?.off?.("PROJECT_LOADED", projectLoaded);
|
|
9589
|
+
listening = false;
|
|
9590
|
+
};
|
|
9591
|
+
const runtimeDisposed = () => {
|
|
9592
|
+
clear();
|
|
9593
|
+
released = true;
|
|
9594
|
+
};
|
|
9595
|
+
const projectLoaded = () => {
|
|
9596
|
+
if (!released || lastOpcodes === void 0) return;
|
|
9597
|
+
released = false;
|
|
9598
|
+
try {
|
|
9599
|
+
registration.ensure(lastOpcodes);
|
|
9600
|
+
} catch {}
|
|
9601
|
+
};
|
|
9577
9602
|
const shutdown = () => {
|
|
9578
9603
|
stopped = true;
|
|
9604
|
+
released = false;
|
|
9605
|
+
unlisten();
|
|
9579
9606
|
clear();
|
|
9580
9607
|
};
|
|
9581
|
-
|
|
9608
|
+
const registration = {
|
|
9582
9609
|
ensure(visibleOpcodes) {
|
|
9583
9610
|
const api = host.gui?.blockEditors;
|
|
9584
9611
|
const definitions = fixedInputEditors.filter((definition) => definition.opcodes.every((opcode) => visibleOpcodes.includes(opcode)));
|
|
9585
9612
|
const key = definitions.map((definition) => definition.editorId).join(",");
|
|
9586
9613
|
if (stopped || api === active && membership === key) return;
|
|
9587
9614
|
clear();
|
|
9588
|
-
|
|
9615
|
+
released = false;
|
|
9616
|
+
lastOpcodes = [...visibleOpcodes];
|
|
9617
|
+
if (api?.apiVersion !== 1 || typeof api.registerFixedInputEditor !== "function" || !definitions.length) {
|
|
9618
|
+
unlisten();
|
|
9619
|
+
return;
|
|
9620
|
+
}
|
|
9589
9621
|
try {
|
|
9590
9622
|
for (const definition of definitions) {
|
|
9591
9623
|
const remove = api.registerFixedInputEditor.call(api, definition);
|
|
@@ -9594,14 +9626,20 @@ function fixedInputRegistration(scratch) {
|
|
|
9594
9626
|
}
|
|
9595
9627
|
active = api;
|
|
9596
9628
|
membership = key;
|
|
9597
|
-
|
|
9629
|
+
if (!listening) {
|
|
9630
|
+
host.vm?.runtime?.on?.("RUNTIME_DISPOSED", runtimeDisposed);
|
|
9631
|
+
host.vm?.runtime?.on?.("PROJECT_LOADED", projectLoaded);
|
|
9632
|
+
listening = true;
|
|
9633
|
+
}
|
|
9598
9634
|
} catch (error) {
|
|
9599
9635
|
clear();
|
|
9636
|
+
unlisten();
|
|
9600
9637
|
throw error;
|
|
9601
9638
|
}
|
|
9602
9639
|
},
|
|
9603
9640
|
dispose: shutdown
|
|
9604
9641
|
};
|
|
9642
|
+
return registration;
|
|
9605
9643
|
}
|
|
9606
9644
|
function canonicalBundle(ownerId, contractId, document, ownerSource) {
|
|
9607
9645
|
const source = {
|
|
@@ -9699,22 +9737,54 @@ function sourceBinding(argument, bundle, read, check = read, format = "json", ui
|
|
|
9699
9737
|
}
|
|
9700
9738
|
};
|
|
9701
9739
|
}
|
|
9702
|
-
/**
|
|
9740
|
+
/**
|
|
9741
|
+
* The optional capability keeps legacy hosts and the startup flag safely inactive.
|
|
9742
|
+
*
|
|
9743
|
+
* Every project load disposes the runtime, which releases the registrations, but the extension
|
|
9744
|
+
* stays loaded for the next project: the same definitions are registered again once that project
|
|
9745
|
+
* has loaded. Only the returned remover is final.
|
|
9746
|
+
*/
|
|
9703
9747
|
function registerSourceEditors(scratch, definitions) {
|
|
9704
9748
|
const host = scratch;
|
|
9705
9749
|
const api = host.gui?.blockEditors;
|
|
9706
9750
|
if (api?.apiVersion !== 1 || typeof api.registerSourceEditor !== "function") return () => {};
|
|
9751
|
+
const register = api.registerSourceEditor;
|
|
9707
9752
|
const removers = [];
|
|
9708
9753
|
let active = true;
|
|
9754
|
+
let released = false;
|
|
9755
|
+
const release = () => {
|
|
9756
|
+
for (const remove of removers.splice(0).reverse()) remove();
|
|
9757
|
+
};
|
|
9758
|
+
const registerAll = () => {
|
|
9759
|
+
try {
|
|
9760
|
+
for (const definition of definitions) removers.push(register.call(api, definition));
|
|
9761
|
+
} catch (error) {
|
|
9762
|
+
release();
|
|
9763
|
+
throw error;
|
|
9764
|
+
}
|
|
9765
|
+
};
|
|
9766
|
+
const runtimeDisposed = () => {
|
|
9767
|
+
release();
|
|
9768
|
+
released = true;
|
|
9769
|
+
};
|
|
9770
|
+
const projectLoaded = () => {
|
|
9771
|
+
if (!released) return;
|
|
9772
|
+
released = false;
|
|
9773
|
+
try {
|
|
9774
|
+
registerAll();
|
|
9775
|
+
} catch {}
|
|
9776
|
+
};
|
|
9709
9777
|
const dispose = () => {
|
|
9710
9778
|
if (!active) return;
|
|
9711
9779
|
active = false;
|
|
9712
|
-
host.vm?.runtime?.off?.("RUNTIME_DISPOSED",
|
|
9713
|
-
|
|
9780
|
+
host.vm?.runtime?.off?.("RUNTIME_DISPOSED", runtimeDisposed);
|
|
9781
|
+
host.vm?.runtime?.off?.("PROJECT_LOADED", projectLoaded);
|
|
9782
|
+
release();
|
|
9714
9783
|
};
|
|
9715
9784
|
try {
|
|
9716
|
-
|
|
9717
|
-
host.vm?.runtime?.on?.("RUNTIME_DISPOSED",
|
|
9785
|
+
registerAll();
|
|
9786
|
+
host.vm?.runtime?.on?.("RUNTIME_DISPOSED", runtimeDisposed);
|
|
9787
|
+
host.vm?.runtime?.on?.("PROJECT_LOADED", projectLoaded);
|
|
9718
9788
|
} catch (error) {
|
|
9719
9789
|
dispose();
|
|
9720
9790
|
throw error;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubohiroya/turbowarp-cloudflare-worker",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "Cloudflare Workers TypeScript generator and TurboWarp extension bridge for turbowarp-http-server.",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Hiroya Kubo",
|
|
@@ -73,7 +73,7 @@
|
|
|
73
73
|
},
|
|
74
74
|
"dependencies": {
|
|
75
75
|
"hono": "^4.10.7",
|
|
76
|
-
"@kubohiroya/turbowarp-extension-data-editor": "^0.
|
|
76
|
+
"@kubohiroya/turbowarp-extension-data-editor": "^0.11.0"
|
|
77
77
|
},
|
|
78
78
|
"devDependencies": {
|
|
79
79
|
"@cloudflare/workers-types": "^5.20260826.1",
|
|
@@ -168,28 +168,50 @@ interface OptionalFixedHost {
|
|
|
168
168
|
gui?: {blockEditors?: {apiVersion?: number; registerFixedInputEditor?: (definition: FixedInputEditorOptions) => () => void}};
|
|
169
169
|
vm?: {runtime?: {on?: (event: string, listener: () => void) => void; off?: (event: string, listener: () => void) => void}};
|
|
170
170
|
}
|
|
171
|
-
/**
|
|
171
|
+
/**
|
|
172
|
+
* Registration follows the advertised opcode membership and the optional host capability.
|
|
173
|
+
*
|
|
174
|
+
* Every project load disposes the runtime, which releases the registrations, but the extension
|
|
175
|
+
* stays loaded for the next project: the same membership is registered again once that project
|
|
176
|
+
* has loaded. Only `dispose()` is final.
|
|
177
|
+
*/
|
|
172
178
|
export function fixedInputRegistration(scratch: unknown) {
|
|
173
179
|
const host = (scratch ?? {}) as OptionalFixedHost;
|
|
174
180
|
let active: unknown;
|
|
175
181
|
let membership = '';
|
|
182
|
+
let lastOpcodes: readonly string[] | undefined;
|
|
176
183
|
const removers: (() => void)[] = [];
|
|
177
184
|
let stopped = false;
|
|
185
|
+
let released = false;
|
|
186
|
+
let listening = false;
|
|
178
187
|
const clear = () => {
|
|
179
|
-
host.vm?.runtime?.off?.('RUNTIME_DISPOSED', shutdown);
|
|
180
188
|
for (const remove of removers.splice(0).reverse()) remove();
|
|
181
189
|
active = undefined;
|
|
182
190
|
membership = '';
|
|
183
191
|
};
|
|
184
|
-
const
|
|
185
|
-
|
|
192
|
+
const unlisten = () => {
|
|
193
|
+
if (!listening) return;
|
|
194
|
+
host.vm?.runtime?.off?.('RUNTIME_DISPOSED', runtimeDisposed);
|
|
195
|
+
host.vm?.runtime?.off?.('PROJECT_LOADED', projectLoaded);
|
|
196
|
+
listening = false;
|
|
197
|
+
};
|
|
198
|
+
const runtimeDisposed = () => {clear(); released = true;};
|
|
199
|
+
const projectLoaded = () => {
|
|
200
|
+
if (!released || lastOpcodes === undefined) return;
|
|
201
|
+
released = false;
|
|
202
|
+
// A failure leaves nothing registered; it must not break the project load.
|
|
203
|
+
try {registration.ensure(lastOpcodes);} catch {/* the next getInfo retries */}
|
|
204
|
+
};
|
|
205
|
+
const shutdown = () => {stopped = true; released = false; unlisten(); clear();};
|
|
206
|
+
const registration = {
|
|
186
207
|
ensure(visibleOpcodes: readonly string[]) {
|
|
187
208
|
const api = host.gui?.blockEditors;
|
|
188
209
|
const definitions = fixedInputEditors.filter(definition => definition.opcodes.every(opcode => visibleOpcodes.includes(opcode)));
|
|
189
210
|
const key = definitions.map(definition => definition.editorId).join(',');
|
|
190
211
|
if (stopped || (api === active && membership === key)) return;
|
|
191
212
|
clear();
|
|
192
|
-
|
|
213
|
+
released = false; lastOpcodes = [...visibleOpcodes];
|
|
214
|
+
if (api?.apiVersion !== 1 || typeof api.registerFixedInputEditor !== 'function' || !definitions.length) {unlisten(); return;}
|
|
193
215
|
try {
|
|
194
216
|
for (const definition of definitions) {
|
|
195
217
|
const remove = api.registerFixedInputEditor.call(api, definition);
|
|
@@ -198,9 +220,14 @@ export function fixedInputRegistration(scratch: unknown) {
|
|
|
198
220
|
}
|
|
199
221
|
active = api;
|
|
200
222
|
membership = key;
|
|
201
|
-
|
|
202
|
-
|
|
223
|
+
if (!listening) {
|
|
224
|
+
host.vm?.runtime?.on?.('RUNTIME_DISPOSED', runtimeDisposed);
|
|
225
|
+
host.vm?.runtime?.on?.('PROJECT_LOADED', projectLoaded);
|
|
226
|
+
listening = true;
|
|
227
|
+
}
|
|
228
|
+
} catch (error) {clear(); unlisten(); throw error;}
|
|
203
229
|
},
|
|
204
230
|
dispose: shutdown
|
|
205
231
|
};
|
|
232
|
+
return registration;
|
|
206
233
|
}
|
package/src/source-editor.ts
CHANGED
|
@@ -35,23 +35,46 @@ export function sourceBinding(argument: string, bundle: SchemaBundle,
|
|
|
35
35
|
};
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
/**
|
|
38
|
+
/**
|
|
39
|
+
* The optional capability keeps legacy hosts and the startup flag safely inactive.
|
|
40
|
+
*
|
|
41
|
+
* Every project load disposes the runtime, which releases the registrations, but the extension
|
|
42
|
+
* stays loaded for the next project: the same definitions are registered again once that project
|
|
43
|
+
* has loaded. Only the returned remover is final.
|
|
44
|
+
*/
|
|
39
45
|
export function registerSourceEditors(scratch: unknown, definitions: readonly SourceEditorOptions[]): () => void {
|
|
40
46
|
const host = scratch as {gui?: {blockEditors?: {apiVersion?: number; registerSourceEditor?: (options: SourceEditorOptions) => () => void}};
|
|
41
47
|
vm?: {runtime?: {on?: (event: string, listener: () => void) => void; off?: (event: string, listener: () => void) => void}}};
|
|
42
48
|
const api = host.gui?.blockEditors;
|
|
43
49
|
if (api?.apiVersion !== 1 || typeof api.registerSourceEditor !== 'function') return () => {};
|
|
50
|
+
const register = api.registerSourceEditor;
|
|
44
51
|
const removers: (() => void)[] = [];
|
|
45
52
|
let active = true;
|
|
53
|
+
let released = false;
|
|
54
|
+
const release = () => {for (const remove of removers.splice(0).reverse()) remove();};
|
|
55
|
+
const registerAll = () => {
|
|
56
|
+
try {
|
|
57
|
+
for (const definition of definitions) removers.push(register.call(api, definition));
|
|
58
|
+
} catch (error) {release(); throw error;}
|
|
59
|
+
};
|
|
60
|
+
const runtimeDisposed = () => {release(); released = true;};
|
|
61
|
+
const projectLoaded = () => {
|
|
62
|
+
if (!released) return;
|
|
63
|
+
released = false;
|
|
64
|
+
// A failure leaves nothing registered; it must not break the project load.
|
|
65
|
+
try {registerAll();} catch {/* nothing registered */}
|
|
66
|
+
};
|
|
46
67
|
const dispose = () => {
|
|
47
68
|
if (!active) return;
|
|
48
69
|
active = false;
|
|
49
|
-
host.vm?.runtime?.off?.('RUNTIME_DISPOSED',
|
|
50
|
-
|
|
70
|
+
host.vm?.runtime?.off?.('RUNTIME_DISPOSED', runtimeDisposed);
|
|
71
|
+
host.vm?.runtime?.off?.('PROJECT_LOADED', projectLoaded);
|
|
72
|
+
release();
|
|
51
73
|
};
|
|
52
74
|
try {
|
|
53
|
-
|
|
54
|
-
host.vm?.runtime?.on?.('RUNTIME_DISPOSED',
|
|
75
|
+
registerAll();
|
|
76
|
+
host.vm?.runtime?.on?.('RUNTIME_DISPOSED', runtimeDisposed);
|
|
77
|
+
host.vm?.runtime?.on?.('PROJECT_LOADED', projectLoaded);
|
|
55
78
|
} catch (error) {dispose(); throw error;}
|
|
56
79
|
return dispose;
|
|
57
80
|
}
|