orchajs 0.26.1 → 0.27.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.
- package/dist/browser.d.ts +2 -1
- package/dist/browser.js +17 -3
- package/dist/cli.js +58 -9
- package/dist/compiler/build-project.js +27 -2
- package/dist/compiler/compile.js +12 -1
- package/dist/initialize-project.js +48 -0
- package/dist/integrations/metro.d.ts +1 -0
- package/dist/integrations/metro.js +1 -1
- package/dist/integrations/next.d.ts +1 -0
- package/dist/integrations/next.js +1 -1
- package/dist/integrations/runtime-build.js +23 -3
- package/dist/orcha.js +58 -8
- package/dist/project-loader.js +4 -5
- package/dist/react-native.d.ts +2 -1
- package/dist/react-native.js +17 -3
- package/dist/runtime/compiled-manifest.d.ts +6 -0
- package/dist/runtime/compiled-manifest.js +5 -0
- package/dist/runtime/compiler-hook.d.ts +4 -0
- package/dist/runtime/compiler-hook.js +9 -0
- package/dist/storage/react-native-jsonl.js +66 -19
- package/dist-cjs/browser.js +22 -8
- package/dist-cjs/compiler/build-project.js +31 -0
- package/dist-cjs/compiler/compile.js +15 -2
- package/dist-cjs/initialize-project.js +45 -0
- package/dist-cjs/integrations/metro.js +1 -1
- package/dist-cjs/integrations/next.js +1 -1
- package/dist-cjs/integrations/runtime-build.js +27 -13
- package/dist-cjs/orcha.js +86 -4
- package/dist-cjs/project-loader.js +4 -2
- package/dist-cjs/react-native.js +24 -8
- package/dist-cjs/runtime/compiled-manifest.js +29 -0
- package/dist-cjs/runtime/compiler-hook.js +12 -1
- package/dist-cjs/storage/react-native-jsonl.js +64 -29
- package/package.json +1 -1
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict"; const __orchaImportMetaUrl = require("url").pathToFileURL(__filename).href;
|
|
2
|
+
"use strict";
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
var compiled_manifest_exports = {};
|
|
21
|
+
__export(compiled_manifest_exports, {
|
|
22
|
+
compiledManifest: () => compiledManifest
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(compiled_manifest_exports);
|
|
25
|
+
const compiledManifest = void 0;
|
|
26
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
27
|
+
0 && (module.exports = {
|
|
28
|
+
compiledManifest
|
|
29
|
+
});
|
|
@@ -19,8 +19,10 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
19
19
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
20
|
var compiler_hook_exports = {};
|
|
21
21
|
__export(compiler_hook_exports, {
|
|
22
|
+
getGlobalCompiledManifest: () => getGlobalCompiledManifest,
|
|
22
23
|
getRegistryCompiler: () => getRegistryCompiler,
|
|
23
24
|
isRegistryCompilationActive: () => isRegistryCompilationActive,
|
|
25
|
+
setGlobalCompiledManifest: () => setGlobalCompiledManifest,
|
|
24
26
|
setRegistryCompilationActive: () => setRegistryCompilationActive,
|
|
25
27
|
setRegistryCompiler: () => setRegistryCompiler
|
|
26
28
|
});
|
|
@@ -31,7 +33,8 @@ function getCompilerHookState() {
|
|
|
31
33
|
if (!globalRecord[COMPILER_HOOK_STATE_KEY]) {
|
|
32
34
|
globalRecord[COMPILER_HOOK_STATE_KEY] = {
|
|
33
35
|
registryCompiler: void 0,
|
|
34
|
-
registryCompilationActive: false
|
|
36
|
+
registryCompilationActive: false,
|
|
37
|
+
compiledManifest: void 0
|
|
35
38
|
};
|
|
36
39
|
}
|
|
37
40
|
return globalRecord[COMPILER_HOOK_STATE_KEY];
|
|
@@ -48,10 +51,18 @@ function setRegistryCompilationActive(active) {
|
|
|
48
51
|
function isRegistryCompilationActive() {
|
|
49
52
|
return getCompilerHookState().registryCompilationActive;
|
|
50
53
|
}
|
|
54
|
+
function setGlobalCompiledManifest(bundle) {
|
|
55
|
+
getCompilerHookState().compiledManifest = bundle;
|
|
56
|
+
}
|
|
57
|
+
function getGlobalCompiledManifest() {
|
|
58
|
+
return getCompilerHookState().compiledManifest;
|
|
59
|
+
}
|
|
51
60
|
// Annotate the CommonJS export names for ESM import in node:
|
|
52
61
|
0 && (module.exports = {
|
|
62
|
+
getGlobalCompiledManifest,
|
|
53
63
|
getRegistryCompiler,
|
|
54
64
|
isRegistryCompilationActive,
|
|
65
|
+
setGlobalCompiledManifest,
|
|
55
66
|
setRegistryCompilationActive,
|
|
56
67
|
setRegistryCompiler
|
|
57
68
|
});
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
"use strict"; const __orchaImportMetaUrl = require("url").pathToFileURL(__filename).href;
|
|
2
2
|
"use strict";
|
|
3
|
-
var __create = Object.create;
|
|
4
3
|
var __defProp = Object.defineProperty;
|
|
5
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
8
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
7
|
var __export = (target, all) => {
|
|
10
8
|
for (var name in all)
|
|
@@ -18,21 +16,48 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
16
|
}
|
|
19
17
|
return to;
|
|
20
18
|
};
|
|
21
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
-
mod
|
|
28
|
-
));
|
|
29
19
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
20
|
var react_native_jsonl_exports = {};
|
|
31
21
|
__export(react_native_jsonl_exports, {
|
|
32
22
|
ReactNativeJsonlSessionStore: () => ReactNativeJsonlSessionStore
|
|
33
23
|
});
|
|
34
24
|
module.exports = __toCommonJS(react_native_jsonl_exports);
|
|
35
|
-
|
|
25
|
+
const fallbackMemoryMap = /* @__PURE__ */ new Map();
|
|
26
|
+
const fallbackMemoryStorage = {
|
|
27
|
+
async getItem(key) {
|
|
28
|
+
return fallbackMemoryMap.get(key) ?? null;
|
|
29
|
+
},
|
|
30
|
+
async setItem(key, value) {
|
|
31
|
+
fallbackMemoryMap.set(key, value);
|
|
32
|
+
},
|
|
33
|
+
async removeItem(key) {
|
|
34
|
+
fallbackMemoryMap.delete(key);
|
|
35
|
+
},
|
|
36
|
+
async getAllKeys() {
|
|
37
|
+
return [...fallbackMemoryMap.keys()];
|
|
38
|
+
},
|
|
39
|
+
async multiSet(keyValuePairs) {
|
|
40
|
+
for (const [key, value] of keyValuePairs) {
|
|
41
|
+
fallbackMemoryMap.set(key, value);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
let resolvedAsyncStoragePromise;
|
|
46
|
+
function getAsyncStorage() {
|
|
47
|
+
if (!resolvedAsyncStoragePromise) {
|
|
48
|
+
const moduleSpecifier = "@react-native-async-storage/async-storage";
|
|
49
|
+
resolvedAsyncStoragePromise = import(moduleSpecifier).then((loaded) => {
|
|
50
|
+
if (loaded?.default && typeof loaded.default.getItem === "function") {
|
|
51
|
+
return loaded.default;
|
|
52
|
+
}
|
|
53
|
+
if (typeof loaded?.getItem === "function") {
|
|
54
|
+
return loaded;
|
|
55
|
+
}
|
|
56
|
+
return fallbackMemoryStorage;
|
|
57
|
+
}).catch(() => fallbackMemoryStorage);
|
|
58
|
+
}
|
|
59
|
+
return resolvedAsyncStoragePromise;
|
|
60
|
+
}
|
|
36
61
|
const writes = /* @__PURE__ */ new Map();
|
|
37
62
|
const tailIndexes = /* @__PURE__ */ new Map();
|
|
38
63
|
const TAIL_CHUNK_SIZE = 100;
|
|
@@ -45,7 +70,8 @@ class ReactNativeJsonlSessionStore {
|
|
|
45
70
|
this.#namespace = namespace;
|
|
46
71
|
}
|
|
47
72
|
async read(sessionId) {
|
|
48
|
-
const
|
|
73
|
+
const storage = await getAsyncStorage();
|
|
74
|
+
const contents = await storage.getItem(this.#key(sessionId));
|
|
49
75
|
if (!contents) {
|
|
50
76
|
return [];
|
|
51
77
|
}
|
|
@@ -55,6 +81,7 @@ class ReactNativeJsonlSessionStore {
|
|
|
55
81
|
if (!Number.isInteger(afterSequence) || afterSequence < 0 || !Number.isInteger(limit) || limit <= 0) {
|
|
56
82
|
throw new Error("Invalid session event tail range.");
|
|
57
83
|
}
|
|
84
|
+
const storage = await getAsyncStorage();
|
|
58
85
|
await writes.get(this.#key(sessionId))?.catch(() => void 0);
|
|
59
86
|
const index = await this.#ensureTailIndex(sessionId);
|
|
60
87
|
const relevant = index.chunks.filter(
|
|
@@ -62,7 +89,7 @@ class ReactNativeJsonlSessionStore {
|
|
|
62
89
|
);
|
|
63
90
|
const events = [];
|
|
64
91
|
for (const chunk of relevant) {
|
|
65
|
-
const contents = await
|
|
92
|
+
const contents = await storage.getItem(chunk.key);
|
|
66
93
|
if (contents === null) {
|
|
67
94
|
tailIndexes.delete(this.#tailIndexKey(sessionId));
|
|
68
95
|
return this.#readTailFromCanonical(
|
|
@@ -86,11 +113,12 @@ class ReactNativeJsonlSessionStore {
|
|
|
86
113
|
const key = this.#key(sessionId);
|
|
87
114
|
const previous = writes.get(key) ?? Promise.resolve();
|
|
88
115
|
const write = previous.then(async () => {
|
|
116
|
+
const storage = await getAsyncStorage();
|
|
89
117
|
const index = await this.#ensureTailIndex(sessionId);
|
|
90
|
-
await
|
|
91
|
-
const existing = await
|
|
118
|
+
await storage.setItem(this.#tailPendingKey(sessionId), "1");
|
|
119
|
+
const existing = await storage.getItem(key);
|
|
92
120
|
const appended = events.map((event) => JSON.stringify(event)).join("\n");
|
|
93
|
-
await
|
|
121
|
+
await storage.setItem(
|
|
94
122
|
key,
|
|
95
123
|
`${existing ? `${existing.replace(/\n*$/, "")}
|
|
96
124
|
` : ""}${appended}
|
|
@@ -98,7 +126,7 @@ class ReactNativeJsonlSessionStore {
|
|
|
98
126
|
);
|
|
99
127
|
try {
|
|
100
128
|
await this.#appendTailIndex(sessionId, index, events);
|
|
101
|
-
await
|
|
129
|
+
await storage.removeItem(this.#tailPendingKey(sessionId));
|
|
102
130
|
} catch {
|
|
103
131
|
tailIndexes.delete(this.#tailIndexKey(sessionId));
|
|
104
132
|
}
|
|
@@ -115,12 +143,14 @@ class ReactNativeJsonlSessionStore {
|
|
|
115
143
|
this.#allListeners.forEach((listener) => listener(sessionId, events));
|
|
116
144
|
}
|
|
117
145
|
async listSessionIds() {
|
|
146
|
+
const storage = await getAsyncStorage();
|
|
118
147
|
const prefix = `@orchajs:${this.#namespace}:`;
|
|
119
|
-
return (await
|
|
148
|
+
return (await storage.getAllKeys()).filter((key) => key.startsWith(prefix)).map((key) => key.slice(prefix.length)).sort();
|
|
120
149
|
}
|
|
121
150
|
async getCloudAcknowledgement(sessionId) {
|
|
151
|
+
const storage = await getAsyncStorage();
|
|
122
152
|
const value = Number(
|
|
123
|
-
await
|
|
153
|
+
await storage.getItem(this.#acknowledgementKey(sessionId))
|
|
124
154
|
);
|
|
125
155
|
return Number.isInteger(value) && value >= 0 ? value : 0;
|
|
126
156
|
}
|
|
@@ -131,9 +161,10 @@ class ReactNativeJsonlSessionStore {
|
|
|
131
161
|
const key = this.#acknowledgementKey(sessionId);
|
|
132
162
|
const previous = writes.get(key) ?? Promise.resolve();
|
|
133
163
|
const write = previous.then(async () => {
|
|
134
|
-
const
|
|
164
|
+
const storage = await getAsyncStorage();
|
|
165
|
+
const current = Number(await storage.getItem(key));
|
|
135
166
|
if (!Number.isInteger(current) || current < sequence) {
|
|
136
|
-
await
|
|
167
|
+
await storage.setItem(key, String(sequence));
|
|
137
168
|
}
|
|
138
169
|
});
|
|
139
170
|
writes.set(key, write);
|
|
@@ -178,14 +209,15 @@ class ReactNativeJsonlSessionStore {
|
|
|
178
209
|
return `@orchajs-tail-chunk:${this.#namespace}:${sessionId}:${Date.now()}:${tailChunkGeneration}`;
|
|
179
210
|
}
|
|
180
211
|
async #ensureTailIndex(sessionId) {
|
|
212
|
+
const storage = await getAsyncStorage();
|
|
181
213
|
const indexKey = this.#tailIndexKey(sessionId);
|
|
182
|
-
const pending = await
|
|
214
|
+
const pending = await storage.getItem(
|
|
183
215
|
this.#tailPendingKey(sessionId)
|
|
184
216
|
);
|
|
185
217
|
if (!pending) {
|
|
186
218
|
const cached = tailIndexes.get(indexKey);
|
|
187
219
|
if (cached) return cached;
|
|
188
|
-
const stored = await
|
|
220
|
+
const stored = await storage.getItem(indexKey);
|
|
189
221
|
if (stored) {
|
|
190
222
|
try {
|
|
191
223
|
const parsed = parseTailIndex(stored);
|
|
@@ -198,6 +230,7 @@ class ReactNativeJsonlSessionStore {
|
|
|
198
230
|
return this.#rebuildTailIndex(sessionId);
|
|
199
231
|
}
|
|
200
232
|
async #rebuildTailIndex(sessionId) {
|
|
233
|
+
const storage = await getAsyncStorage();
|
|
201
234
|
const events = await this.read(sessionId);
|
|
202
235
|
const chunks = [];
|
|
203
236
|
const writes2 = [];
|
|
@@ -213,19 +246,20 @@ class ReactNativeJsonlSessionStore {
|
|
|
213
246
|
chunks
|
|
214
247
|
};
|
|
215
248
|
writes2.push([this.#tailIndexKey(sessionId), JSON.stringify(index)]);
|
|
216
|
-
if (writes2.length > 0) await
|
|
217
|
-
await
|
|
249
|
+
if (writes2.length > 0) await storage.multiSet(writes2);
|
|
250
|
+
await storage.removeItem(this.#tailPendingKey(sessionId));
|
|
218
251
|
tailIndexes.set(this.#tailIndexKey(sessionId), index);
|
|
219
252
|
return index;
|
|
220
253
|
}
|
|
221
254
|
async #appendTailIndex(sessionId, current, events) {
|
|
255
|
+
const storage = await getAsyncStorage();
|
|
222
256
|
const chunks = [...current.chunks];
|
|
223
257
|
const replacements = [];
|
|
224
258
|
const obsolete = [];
|
|
225
259
|
let remaining = [...events];
|
|
226
260
|
const last = chunks.at(-1);
|
|
227
261
|
if (last && last.count < TAIL_CHUNK_SIZE) {
|
|
228
|
-
const stored = await
|
|
262
|
+
const stored = await storage.getItem(last.key);
|
|
229
263
|
if (stored === null) throw new Error("Missing tail index chunk.");
|
|
230
264
|
const retained = parseEvents(stored).slice(0, last.count);
|
|
231
265
|
const added = remaining.splice(
|
|
@@ -253,18 +287,19 @@ class ReactNativeJsonlSessionStore {
|
|
|
253
287
|
this.#tailIndexKey(sessionId),
|
|
254
288
|
JSON.stringify(index)
|
|
255
289
|
]);
|
|
256
|
-
await
|
|
290
|
+
await storage.multiSet(replacements);
|
|
257
291
|
tailIndexes.set(this.#tailIndexKey(sessionId), index);
|
|
258
292
|
await Promise.all(
|
|
259
|
-
obsolete.map((key) =>
|
|
293
|
+
obsolete.map((key) => storage.removeItem(key))
|
|
260
294
|
);
|
|
261
295
|
}
|
|
262
296
|
async #readTailFromCanonical(sessionId, afterSequence, limit) {
|
|
297
|
+
const storage = await getAsyncStorage();
|
|
263
298
|
const index = await this.#rebuildTailIndex(sessionId);
|
|
264
299
|
const events = [];
|
|
265
300
|
for (const chunk of index.chunks) {
|
|
266
301
|
if (chunk.lastSequence <= afterSequence) continue;
|
|
267
|
-
const contents = await
|
|
302
|
+
const contents = await storage.getItem(chunk.key);
|
|
268
303
|
if (!contents) continue;
|
|
269
304
|
for (const event of parseEvents(contents).slice(0, chunk.count)) {
|
|
270
305
|
if (event.sequence > afterSequence) events.push(event);
|