@adaas/a-frame 0.0.23 → 0.1.1

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.
Files changed (44) hide show
  1. package/dist/browser/channel.mjs +1 -1
  2. package/dist/browser/chunk-GOADBDTE.mjs +2 -0
  3. package/dist/browser/chunk-GOADBDTE.mjs.map +1 -0
  4. package/dist/browser/chunk-YQJFTBGV.mjs +3 -0
  5. package/dist/browser/chunk-YQJFTBGV.mjs.map +1 -0
  6. package/dist/browser/core.d.mts +1 -1
  7. package/dist/browser/core.mjs +1 -1
  8. package/dist/browser/core.mjs.map +1 -1
  9. package/dist/browser/env.mjs +1 -1
  10. package/dist/browser/storage.mjs +1 -1
  11. package/dist/node/bundle.cjs +2 -2
  12. package/dist/node/bundle.mjs +1 -1
  13. package/dist/node/channel.cjs +14 -14
  14. package/dist/node/channel.mjs +3 -3
  15. package/dist/node/chunk-5BKCX2RO.mjs +33 -0
  16. package/dist/node/chunk-5BKCX2RO.mjs.map +1 -0
  17. package/dist/node/chunk-6KAGWGTE.mjs +529 -0
  18. package/dist/node/chunk-6KAGWGTE.mjs.map +1 -0
  19. package/dist/node/chunk-F46TSY2K.cjs +541 -0
  20. package/dist/node/chunk-F46TSY2K.cjs.map +1 -0
  21. package/dist/node/chunk-GRR6NNWY.cjs +688 -0
  22. package/dist/node/chunk-GRR6NNWY.cjs.map +1 -0
  23. package/dist/node/chunk-OYC6L5NX.mjs +6 -0
  24. package/dist/node/chunk-OYC6L5NX.mjs.map +1 -0
  25. package/dist/node/chunk-R2H234YO.cjs +8 -0
  26. package/dist/node/chunk-R2H234YO.cjs.map +1 -0
  27. package/dist/node/chunk-SDKIJDMH.mjs +655 -0
  28. package/dist/node/chunk-SDKIJDMH.mjs.map +1 -0
  29. package/dist/node/chunk-XFUF7SDO.cjs +35 -0
  30. package/dist/node/chunk-XFUF7SDO.cjs.map +1 -0
  31. package/dist/node/core.cjs +21 -23
  32. package/dist/node/core.cjs.map +1 -1
  33. package/dist/node/core.d.mts +1 -1
  34. package/dist/node/core.d.ts +1 -1
  35. package/dist/node/core.mjs +18 -20
  36. package/dist/node/core.mjs.map +1 -1
  37. package/dist/node/env.cjs +3 -3
  38. package/dist/node/env.mjs +2 -2
  39. package/dist/node/storage.cjs +8 -8
  40. package/dist/node/storage.mjs +3 -3
  41. package/package.json +2 -2
  42. package/src/lib/A-Frame/A-Frame.component.env-browser.ts +5 -3
  43. package/src/lib/A-Frame/A-Frame.component.env-node.ts +13 -14
  44. package/tests/A-Frame.test.ts +2 -0
@@ -0,0 +1,33 @@
1
+ import { version } from './chunk-OYC6L5NX.mjs';
2
+ import { A_Fragment } from '@adaas/a-concept';
3
+
4
+ var A_FrameEnv = class extends A_Fragment {
5
+ get A_FRAME_FILE_EXTENSION() {
6
+ return ".aframe";
7
+ }
8
+ get A_FRAME_NAMESPACES_BIN() {
9
+ return `__namespaces${this.A_FRAME_FILE_EXTENSION}`;
10
+ }
11
+ get A_FRAME_SYNC() {
12
+ return process.env.A_FRAME_SYNC === "false" ? false : true;
13
+ }
14
+ get A_FRAME_TOKEN() {
15
+ return process.env.A_FRAME_TOKEN || "";
16
+ }
17
+ get A_FRAME_SERVER_URL() {
18
+ return process.env.A_FRAME_SERVER_URL || "http://localhost:3663";
19
+ }
20
+ get A_FRAME_SERVER_API_KEY() {
21
+ return process.env.A_FRAME_SERVER_API_KEY || "";
22
+ }
23
+ get A_FRAME_STORAGE_DIR() {
24
+ return process.env.A_FRAME_STORAGE_DIR || ".aframestr";
25
+ }
26
+ get A_FRAME_VERSION() {
27
+ return version || "0.0.1";
28
+ }
29
+ };
30
+
31
+ export { A_FrameEnv };
32
+ //# sourceMappingURL=chunk-5BKCX2RO.mjs.map
33
+ //# sourceMappingURL=chunk-5BKCX2RO.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/lib/A-FrameEnv/A-FrameEnv.fragment.env-node.ts"],"names":[],"mappings":";;;AAKO,IAAM,UAAA,GAAN,cAAyB,UAAA,CAAkC;AAAA,EAE9D,IAAI,sBAAA,GAAyB;AACzB,IAAA,OAAO,SAAA;AAAA,EACX;AAAA,EAEA,IAAI,sBAAA,GAAyB;AACzB,IAAA,OAAO,CAAA,YAAA,EAAe,KAAK,sBAAsB,CAAA,CAAA;AAAA,EACrD;AAAA,EAEA,IAAI,YAAA,GAAe;AACf,IAAA,OAAO,OAAA,CAAQ,GAAA,CAAI,YAAA,KAAiB,OAAA,GAAU,KAAA,GAAQ,IAAA;AAAA,EAC1D;AAAA,EAEA,IAAI,aAAA,GAAgB;AAChB,IAAA,OAAO,OAAA,CAAQ,IAAI,aAAA,IAAiB,EAAA;AAAA,EACxC;AAAA,EAEA,IAAI,kBAAA,GAAqB;AACrB,IAAA,OAAO,OAAA,CAAQ,IAAI,kBAAA,IAAsB,uBAAA;AAAA,EAC7C;AAAA,EAEA,IAAI,sBAAA,GAAyB;AACzB,IAAA,OAAO,OAAA,CAAQ,IAAI,sBAAA,IAA0B,EAAA;AAAA,EACjD;AAAA,EAEA,IAAI,mBAAA,GAAsB;AACtB,IAAA,OAAO,OAAA,CAAQ,IAAI,mBAAA,IAAuB,YAAA;AAAA,EAC9C;AAAA,EAEA,IAAI,eAAA,GAAkB;AAClB,IAAA,OAAW,OAAA,IAAW,OAAA;AAAA,EAC1B;AACJ","file":"chunk-5BKCX2RO.mjs","sourcesContent":["import { A_Fragment } from \"@adaas/a-concept\";\nimport * as pkg from '../../../package.json';\nimport { IA_FrameEnv } from \"./A-FrameEnv.types\";\n\n\nexport class A_FrameEnv extends A_Fragment implements IA_FrameEnv {\n\n get A_FRAME_FILE_EXTENSION() {\n return '.aframe';\n }\n\n get A_FRAME_NAMESPACES_BIN() {\n return `__namespaces${this.A_FRAME_FILE_EXTENSION}`;\n }\n\n get A_FRAME_SYNC() {\n return process.env.A_FRAME_SYNC === 'false' ? false : true;\n }\n\n get A_FRAME_TOKEN() {\n return process.env.A_FRAME_TOKEN || '';\n }\n\n get A_FRAME_SERVER_URL() {\n return process.env.A_FRAME_SERVER_URL || 'http://localhost:3663';\n }\n\n get A_FRAME_SERVER_API_KEY() {\n return process.env.A_FRAME_SERVER_API_KEY || '';\n }\n\n get A_FRAME_STORAGE_DIR() {\n return process.env.A_FRAME_STORAGE_DIR || '.aframestr';\n }\n\n get A_FRAME_VERSION() {\n return pkg.version || '0.0.1';\n }\n}"]}
@@ -0,0 +1,529 @@
1
+ import { A_FrameStorageCodec } from './chunk-3ONWH75E.mjs';
2
+ import { A_FrameEnv } from './chunk-5BKCX2RO.mjs';
3
+ import { A_FrameNamespace, A_FrameNamespaceFeatures } from './chunk-APRYHBEF.mjs';
4
+ import { A_FrameCrypto } from './chunk-UPA7VN4R.mjs';
5
+ import { A_FrameDefinition, A_FrameDefinitionFeatures } from './chunk-B7BXP7K4.mjs';
6
+ import { __decorateClass, __decorateParam } from './chunk-OI76LHVT.mjs';
7
+ import { A_Feature, A_Inject, A_Caller, A_Error, A_Fragment, A_Component, A_Scope, A_Context } from '@adaas/a-concept';
8
+ import fs from 'fs/promises';
9
+ import path from 'path';
10
+
11
+ var A_FrameContext = class extends A_Fragment {
12
+ constructor() {
13
+ super({ name: "a-frame-context" });
14
+ }
15
+ get encryptionKey() {
16
+ return this.credentials?.encryption_key;
17
+ }
18
+ get serverVersion() {
19
+ return this.credentials?.server_version;
20
+ }
21
+ isAuthenticated() {
22
+ return !!this.credentials;
23
+ }
24
+ setCredentials(credentials) {
25
+ if (credentials.error) {
26
+ this.credentials = void 0;
27
+ return;
28
+ }
29
+ this.credentials = credentials.response || void 0;
30
+ }
31
+ };
32
+
33
+ // src/lib/A-FrameStorage/A-FrameStorage.constants.ts
34
+ var A_FrameStorageFeatures = {
35
+ SaveDefinitions: "_A_FRAME_STORAGE_SAVE",
36
+ LoadDefinitions: "_A_FRAME_STORAGE_LOAD",
37
+ DestroyDefinitions: "_A_FRAME_STORAGE_DESTROY",
38
+ SaveNamespaces: "_A_FRAME_STORAGE_SAVE_NAMESPACES",
39
+ LoadNamespaces: "_A_FRAME_STORAGE_LOAD_NAMESPACES",
40
+ DestroyNamespaces: "_A_FRAME_STORAGE_DESTROY_NAMESPACES"
41
+ };
42
+ var A_FrameStorageOperation = class extends A_Fragment {
43
+ constructor(params) {
44
+ super({ name: "a-frame-storage-operation" });
45
+ this._params = params;
46
+ }
47
+ /**
48
+ * If the operation succeeded, this will contain the result data. If the operation failed, this will be undefined.
49
+ */
50
+ get result() {
51
+ return this._result;
52
+ }
53
+ /**
54
+ * If the operation failed, this will contain an error object with details about the failure. If the operation succeeded, this will be undefined.
55
+ */
56
+ get error() {
57
+ return this._error;
58
+ }
59
+ /**
60
+ * Parameters used to execute the operation, e.g. definitionId and namespaceId for a saveDefinition operation.
61
+ */
62
+ get params() {
63
+ return this._params;
64
+ }
65
+ /**
66
+ * Marks the operation as completed successfully with the given result. This will set the `result` property and leave `error` as undefined.
67
+ *
68
+ * @param result
69
+ */
70
+ complete(result) {
71
+ this._result = result;
72
+ }
73
+ /**
74
+ * Marks the operation as failed with the given error. This will set the `error` property and leave `result` as undefined.
75
+ *
76
+ * @param error
77
+ */
78
+ fail(error) {
79
+ this._error = error;
80
+ }
81
+ };
82
+ var A_FrameStorageError = class extends A_Error {
83
+ };
84
+ A_FrameStorageError.SaveDefinitionFailed = "SaveDefinitionFailed";
85
+ A_FrameStorageError.LoadDefinitionsFailed = "LoadDefinitionsFailed";
86
+ A_FrameStorageError.DestroyDefinitionsFailed = "DestroyDefinitionsFailed";
87
+ A_FrameStorageError.SaveNamespaceFailed = "SaveNamespaceFailed";
88
+ A_FrameStorageError.LoadNamespacesFailed = "LoadNamespacesFailed";
89
+ A_FrameStorageError.DestroyNamespacesFailed = "DestroyNamespacesFailed";
90
+ var A_FrameStorage = class extends A_Component {
91
+ async saveDefinitions(definitions) {
92
+ const context = new A_FrameStorageOperation({
93
+ records: definitions
94
+ });
95
+ const executionScope = new A_Scope({
96
+ name: "A_FrameStorage.saveDefinitions",
97
+ fragments: [context]
98
+ }).inherit(A_Context.scope(this));
99
+ try {
100
+ await this.call(A_FrameStorageFeatures.SaveDefinitions, executionScope);
101
+ executionScope.destroy();
102
+ return context;
103
+ } catch (error) {
104
+ context.fail(new A_FrameStorageError({
105
+ title: A_FrameStorageError.SaveDefinitionFailed,
106
+ description: `Failed to save definition records.`
107
+ }));
108
+ executionScope.destroy();
109
+ return context;
110
+ }
111
+ }
112
+ async loadDefinitions(namespaceId, definitionId) {
113
+ const context = new A_FrameStorageOperation({
114
+ namespaceId
115
+ });
116
+ const executionScope = new A_Scope({
117
+ name: "A_FrameStorage.loadDefinitions",
118
+ fragments: [context]
119
+ }).inherit(A_Context.scope(this));
120
+ try {
121
+ await this.call(A_FrameStorageFeatures.LoadDefinitions, executionScope);
122
+ executionScope.destroy();
123
+ return context;
124
+ } catch (error) {
125
+ context.fail(new A_FrameStorageError({
126
+ title: A_FrameStorageError.LoadDefinitionsFailed,
127
+ description: `Failed to load definition records.`
128
+ }));
129
+ executionScope.destroy();
130
+ return context;
131
+ }
132
+ }
133
+ async destroyDefinitions(namespaceId, definitionId) {
134
+ const context = new A_FrameStorageOperation({
135
+ namespaceId,
136
+ definitionId
137
+ });
138
+ const executionScope = new A_Scope({
139
+ name: "A_FrameStorage.destroyDefinitions",
140
+ fragments: [context]
141
+ }).inherit(A_Context.scope(this));
142
+ try {
143
+ await this.call(A_FrameStorageFeatures.DestroyDefinitions, executionScope);
144
+ executionScope.destroy();
145
+ return context;
146
+ } catch (error) {
147
+ context.fail(new A_FrameStorageError({
148
+ title: A_FrameStorageError.DestroyDefinitionsFailed,
149
+ description: `Failed to destroy definition records.`
150
+ }));
151
+ executionScope.destroy();
152
+ return context;
153
+ }
154
+ }
155
+ async saveNamespaces(namespaces) {
156
+ const context = new A_FrameStorageOperation({
157
+ records: namespaces
158
+ });
159
+ const executionScope = new A_Scope({
160
+ name: "A_FrameStorage.saveNamespaces",
161
+ fragments: [context]
162
+ }).inherit(A_Context.scope(this));
163
+ try {
164
+ await this.call(A_FrameStorageFeatures.SaveNamespaces, executionScope);
165
+ executionScope.destroy();
166
+ return context;
167
+ } catch (error) {
168
+ context.fail(new A_FrameStorageError({
169
+ title: A_FrameStorageError.SaveNamespaceFailed,
170
+ description: `Failed to save namespace records.`
171
+ }));
172
+ executionScope.destroy();
173
+ return context;
174
+ }
175
+ }
176
+ async loadNamespaces(namespaceIds) {
177
+ const context = new A_FrameStorageOperation({
178
+ namespaces: namespaceIds
179
+ });
180
+ const executionScope = new A_Scope({
181
+ name: "A_FrameStorage.loadNamespaces",
182
+ fragments: [context]
183
+ }).inherit(A_Context.scope(this));
184
+ try {
185
+ await this.call(A_FrameStorageFeatures.LoadNamespaces, executionScope);
186
+ executionScope.destroy();
187
+ return context;
188
+ } catch (error) {
189
+ context.fail(new A_FrameStorageError({
190
+ title: A_FrameStorageError.LoadNamespacesFailed,
191
+ description: `Failed to load namespace records.`
192
+ }));
193
+ executionScope.destroy();
194
+ return context;
195
+ }
196
+ }
197
+ async destroyNamespaces(namespacesIds) {
198
+ const context = new A_FrameStorageOperation({
199
+ namespaces: namespacesIds
200
+ });
201
+ const executionScope = new A_Scope({
202
+ name: "A_FrameStorage.destroyNamespaces",
203
+ fragments: [context]
204
+ }).inherit(A_Context.scope(this));
205
+ try {
206
+ await this.call(A_FrameStorageFeatures.DestroyNamespaces, executionScope);
207
+ executionScope.destroy();
208
+ return context;
209
+ } catch (error) {
210
+ context.fail(new A_FrameStorageError({
211
+ title: A_FrameStorageError.DestroyNamespacesFailed,
212
+ description: `Failed to destroy namespace records.`
213
+ }));
214
+ executionScope.destroy();
215
+ return context;
216
+ }
217
+ }
218
+ };
219
+ var A_FrameNodeStorage = class extends A_FrameStorage {
220
+ /** Returns file contents, or null when the file does not exist yet. Re-throws all other I/O errors. */
221
+ async tryReadFile(filePath) {
222
+ try {
223
+ return await fs.readFile(filePath);
224
+ } catch (err) {
225
+ if (err?.code === "ENOENT") return null;
226
+ throw err;
227
+ }
228
+ }
229
+ async saveDefinitionToDisk(definition, env, context, codec, aFrameCrypto) {
230
+ const namespace = definition.namespace;
231
+ const incoming = definition.toJSON();
232
+ if (!incoming.embedding)
233
+ throw new Error("Only definitions with embeddings can be saved to storage");
234
+ const rawBuf = await this.tryReadFile(path.join(env.A_FRAME_STORAGE_DIR, codec.getFileName(namespace.id)));
235
+ const existing = rawBuf ? codec.decodePayload(await aFrameCrypto.decryptBytes(new Uint8Array(rawBuf), context.encryptionKey)) : [];
236
+ const merged = /* @__PURE__ */ new Map();
237
+ for (const r of existing) merged.set(r.hash, r);
238
+ merged.set(incoming.hash, incoming);
239
+ const records = Array.from(merged.values());
240
+ const payload = codec.encodePayload(records);
241
+ const encrypted = await aFrameCrypto.encryptBytes(payload, context.encryptionKey);
242
+ await fs.mkdir(env.A_FRAME_STORAGE_DIR, { recursive: true });
243
+ await fs.writeFile(path.join(env.A_FRAME_STORAGE_DIR, codec.getFileName(namespace.id)), encrypted);
244
+ }
245
+ async loadDefinitionFromDisk(definition, env, context, codec, aFrameCrypto) {
246
+ const rawBuf = await this.tryReadFile(path.join(env.A_FRAME_STORAGE_DIR, codec.getFileName(definition.namespace.id)));
247
+ if (!rawBuf) return;
248
+ const plain = await aFrameCrypto.decryptBytes(new Uint8Array(rawBuf), context.encryptionKey);
249
+ const records = codec.decodePayload(plain);
250
+ const record = records.find((r) => r.aseid === definition.aseid.toString());
251
+ if (record && record.hash === definition.hash && record.aFrameServerVersion === context.serverVersion) {
252
+ definition.fromJSON(record);
253
+ }
254
+ }
255
+ async destroyDefinitionFromDisk(definition, env, context, codec, aFrameCrypto) {
256
+ const rawBuf = await this.tryReadFile(path.join(env.A_FRAME_STORAGE_DIR, codec.getFileName(definition.namespace.id)));
257
+ if (!rawBuf) return;
258
+ const plain = await aFrameCrypto.decryptBytes(new Uint8Array(rawBuf), context.encryptionKey);
259
+ const records = codec.decodePayload(plain);
260
+ const filtered = records.filter((r) => r.aseid !== definition.aseid.toString());
261
+ const payload = codec.encodePayload(filtered);
262
+ const encrypted = await aFrameCrypto.encryptBytes(payload, context.encryptionKey);
263
+ await fs.mkdir(env.A_FRAME_STORAGE_DIR, { recursive: true });
264
+ await fs.writeFile(path.join(env.A_FRAME_STORAGE_DIR, codec.getFileName(definition.namespace.id)), encrypted);
265
+ }
266
+ async saveNamespaceToDisk(namespace, env, context, codec, aFrameCrypto) {
267
+ const incoming = namespace.toJSON();
268
+ const rawBuf = await this.tryReadFile(path.join(env.A_FRAME_STORAGE_DIR, codec.getNamespaceFileName()));
269
+ const existing = rawBuf ? codec.decodeNamespacePayload(await aFrameCrypto.decryptBytes(new Uint8Array(rawBuf), context.encryptionKey)) : [];
270
+ const merged = /* @__PURE__ */ new Map();
271
+ for (const r of existing) merged.set(r.aseid, r);
272
+ merged.set(incoming.aseid.toString(), incoming);
273
+ const records = Array.from(merged.values());
274
+ const payload = codec.encodeNamespacePayload(records);
275
+ const encrypted = await aFrameCrypto.encryptBytes(payload, context.encryptionKey);
276
+ await fs.mkdir(env.A_FRAME_STORAGE_DIR, { recursive: true });
277
+ await fs.writeFile(path.join(env.A_FRAME_STORAGE_DIR, codec.getNamespaceFileName()), encrypted);
278
+ }
279
+ async loadNamespaceFromDisk(namespace, env, context, aFrameCrypto, codec) {
280
+ const rawBuf = await this.tryReadFile(path.join(env.A_FRAME_STORAGE_DIR, codec.getNamespaceFileName()));
281
+ if (!rawBuf) return;
282
+ const plain = await aFrameCrypto.decryptBytes(new Uint8Array(rawBuf), context.encryptionKey);
283
+ const records = codec.decodeNamespacePayload(plain);
284
+ const record = records.find((r) => r.aseid === namespace.aseid.toString());
285
+ if (record && record.hash === namespace.hash && record.aFrameServerVersion === context.serverVersion) {
286
+ namespace.fromJSON(record);
287
+ }
288
+ }
289
+ async destroyNamespaceFromLocalFileStorage(namespace, env, context, codec, aFrameCrypto) {
290
+ const rawBuf = await this.tryReadFile(path.join(env.A_FRAME_STORAGE_DIR, codec.getNamespaceFileName()));
291
+ if (!rawBuf) return;
292
+ const plain = await aFrameCrypto.decryptBytes(new Uint8Array(rawBuf), context.encryptionKey);
293
+ const records = codec.decodeNamespacePayload(plain);
294
+ const filtered = records.filter((r) => r.aseid !== namespace.aseid.toString());
295
+ const payload = codec.encodeNamespacePayload(filtered);
296
+ const encrypted = await aFrameCrypto.encryptBytes(payload, context.encryptionKey);
297
+ await fs.mkdir(env.A_FRAME_STORAGE_DIR, { recursive: true });
298
+ await fs.writeFile(path.join(env.A_FRAME_STORAGE_DIR, codec.getNamespaceFileName()), encrypted);
299
+ try {
300
+ await fs.unlink(path.join(env.A_FRAME_STORAGE_DIR, codec.getFileName(namespace.id)));
301
+ } catch {
302
+ }
303
+ }
304
+ async saveDefinitionsToDisk(env, operation, context, codec, aFrameCrypto) {
305
+ const records = operation.params.records;
306
+ const namespace = records[0].namespace;
307
+ const rawBuf = await this.tryReadFile(path.join(env.A_FRAME_STORAGE_DIR, codec.getFileName(namespace)));
308
+ const existing = rawBuf ? codec.decodePayload(await aFrameCrypto.decryptBytes(new Uint8Array(rawBuf), context.encryptionKey)) : [];
309
+ const merged = /* @__PURE__ */ new Map();
310
+ for (const r of existing) merged.set(r.hash, r);
311
+ for (const d of records) merged.set(d.hash, d);
312
+ const result = Array.from(merged.values());
313
+ const payload = codec.encodePayload(result);
314
+ const encrypted = await aFrameCrypto.encryptBytes(payload, context.encryptionKey);
315
+ await fs.mkdir(env.A_FRAME_STORAGE_DIR, { recursive: true });
316
+ await fs.writeFile(path.join(env.A_FRAME_STORAGE_DIR, codec.getFileName(namespace)), encrypted);
317
+ operation.complete({
318
+ saved: records.length
319
+ });
320
+ }
321
+ async loadDefinitionsFromDisk(env, operation, context, codec, aFrameCrypto) {
322
+ const namespace = operation.params.namespaceId;
323
+ const rawBuf = await this.tryReadFile(path.join(env.A_FRAME_STORAGE_DIR, codec.getFileName(namespace)));
324
+ const records = rawBuf ? codec.decodePayload(await aFrameCrypto.decryptBytes(new Uint8Array(rawBuf), context.encryptionKey)) : [];
325
+ operation.complete({
326
+ records
327
+ });
328
+ }
329
+ async destroyDefinitionsFromDisk(env, operation, context, codec, aFrameCrypto) {
330
+ const namespace = operation.params.namespaceId;
331
+ const definitionId = operation.params.definitionId;
332
+ const rawBuf = await this.tryReadFile(path.join(env.A_FRAME_STORAGE_DIR, codec.getFileName(namespace)));
333
+ const records = rawBuf ? codec.decodePayload(await aFrameCrypto.decryptBytes(new Uint8Array(rawBuf), context.encryptionKey)) : [];
334
+ const filtered = records.filter((r) => r.aseid !== definitionId);
335
+ const payload = codec.encodePayload(filtered);
336
+ const encrypted = await aFrameCrypto.encryptBytes(payload, context.encryptionKey);
337
+ await fs.mkdir(env.A_FRAME_STORAGE_DIR, { recursive: true });
338
+ await fs.writeFile(path.join(env.A_FRAME_STORAGE_DIR, codec.getFileName(namespace)), encrypted);
339
+ operation.complete({
340
+ records: filtered
341
+ });
342
+ }
343
+ async saveNamespacesToDisk(env, operation, context, codec, aFrameCrypto) {
344
+ const records = operation.params.records;
345
+ const rawBuf = await this.tryReadFile(path.join(env.A_FRAME_STORAGE_DIR, codec.getNamespaceFileName()));
346
+ const existing = rawBuf ? codec.decodeNamespacePayload(await aFrameCrypto.decryptBytes(new Uint8Array(rawBuf), context.encryptionKey)) : [];
347
+ const merged = /* @__PURE__ */ new Map();
348
+ for (const r of existing) merged.set(r.aseid, r);
349
+ for (const d of records) merged.set(d.aseid.toString(), d);
350
+ const result = Array.from(merged.values());
351
+ const payload = codec.encodeNamespacePayload(result);
352
+ const encrypted = await aFrameCrypto.encryptBytes(payload, context.encryptionKey);
353
+ await fs.mkdir(env.A_FRAME_STORAGE_DIR, { recursive: true });
354
+ await fs.writeFile(path.join(env.A_FRAME_STORAGE_DIR, codec.getNamespaceFileName()), encrypted);
355
+ operation.complete({
356
+ success: true
357
+ });
358
+ }
359
+ async loadNamespacesFromDisk(env, operation, context, codec, aFrameCrypto) {
360
+ const ids = operation.params.namespaces;
361
+ const rawBuf = await this.tryReadFile(path.join(env.A_FRAME_STORAGE_DIR, codec.getNamespaceFileName()));
362
+ const records = rawBuf ? codec.decodeNamespacePayload(await aFrameCrypto.decryptBytes(new Uint8Array(rawBuf), context.encryptionKey)) : [];
363
+ operation.complete({
364
+ records: ids ? records.filter((r) => ids.includes(r.name)) : records
365
+ });
366
+ }
367
+ async destroyNamespacesFromDisk(env, operation, context, codec, aFrameCrypto) {
368
+ const ids = operation.params.namespaces;
369
+ const rawBuf = await this.tryReadFile(path.join(env.A_FRAME_STORAGE_DIR, codec.getNamespaceFileName()));
370
+ const records = rawBuf ? codec.decodeNamespacePayload(await aFrameCrypto.decryptBytes(new Uint8Array(rawBuf), context.encryptionKey)) : [];
371
+ const filtered = records.filter((r) => !ids.includes(r.aseid));
372
+ const payload = codec.encodeNamespacePayload(filtered);
373
+ const encrypted = await aFrameCrypto.encryptBytes(payload, context.encryptionKey);
374
+ await fs.mkdir(env.A_FRAME_STORAGE_DIR, { recursive: true });
375
+ await fs.writeFile(path.join(env.A_FRAME_STORAGE_DIR, codec.getNamespaceFileName()), encrypted);
376
+ try {
377
+ for (const id of ids) {
378
+ await fs.unlink(path.join(env.A_FRAME_STORAGE_DIR, codec.getFileName(id)));
379
+ }
380
+ operation.complete({
381
+ success: true
382
+ });
383
+ } catch (error) {
384
+ operation.fail(new A_FrameStorageError({
385
+ title: A_FrameStorageError.DestroyNamespacesFailed,
386
+ description: `Failed to destroy namespace records.`
387
+ }));
388
+ operation.complete({
389
+ success: false
390
+ });
391
+ }
392
+ }
393
+ };
394
+ __decorateClass([
395
+ A_Feature.Extend({
396
+ name: A_FrameDefinitionFeatures.Save,
397
+ scope: [A_FrameDefinition]
398
+ }),
399
+ __decorateParam(0, A_Inject(A_Caller)),
400
+ __decorateParam(1, A_Inject(A_FrameEnv)),
401
+ __decorateParam(2, A_Inject(A_FrameContext)),
402
+ __decorateParam(3, A_Inject(A_FrameStorageCodec)),
403
+ __decorateParam(4, A_Inject(A_FrameCrypto))
404
+ ], A_FrameNodeStorage.prototype, "saveDefinitionToDisk", 1);
405
+ __decorateClass([
406
+ A_Feature.Extend({
407
+ name: A_FrameDefinitionFeatures.Load,
408
+ scope: [A_FrameDefinition]
409
+ }),
410
+ __decorateParam(0, A_Inject(A_Caller)),
411
+ __decorateParam(1, A_Inject(A_FrameEnv)),
412
+ __decorateParam(2, A_Inject(A_FrameContext)),
413
+ __decorateParam(3, A_Inject(A_FrameStorageCodec)),
414
+ __decorateParam(4, A_Inject(A_FrameCrypto))
415
+ ], A_FrameNodeStorage.prototype, "loadDefinitionFromDisk", 1);
416
+ __decorateClass([
417
+ A_Feature.Extend({
418
+ name: A_FrameDefinitionFeatures.Destroy,
419
+ scope: [A_FrameDefinition]
420
+ }),
421
+ __decorateParam(0, A_Inject(A_Caller)),
422
+ __decorateParam(1, A_Inject(A_FrameEnv)),
423
+ __decorateParam(2, A_Inject(A_FrameContext)),
424
+ __decorateParam(3, A_Inject(A_FrameStorageCodec)),
425
+ __decorateParam(4, A_Inject(A_FrameCrypto))
426
+ ], A_FrameNodeStorage.prototype, "destroyDefinitionFromDisk", 1);
427
+ __decorateClass([
428
+ A_Feature.Extend({
429
+ name: A_FrameNamespaceFeatures.Save,
430
+ scope: [A_FrameNamespace]
431
+ }),
432
+ __decorateParam(0, A_Inject(A_Caller)),
433
+ __decorateParam(1, A_Inject(A_FrameEnv)),
434
+ __decorateParam(2, A_Inject(A_FrameContext)),
435
+ __decorateParam(3, A_Inject(A_FrameStorageCodec)),
436
+ __decorateParam(4, A_Inject(A_FrameCrypto))
437
+ ], A_FrameNodeStorage.prototype, "saveNamespaceToDisk", 1);
438
+ __decorateClass([
439
+ A_Feature.Extend({
440
+ name: A_FrameNamespaceFeatures.Load,
441
+ scope: [A_FrameNamespace]
442
+ }),
443
+ __decorateParam(0, A_Inject(A_Caller)),
444
+ __decorateParam(1, A_Inject(A_FrameEnv)),
445
+ __decorateParam(2, A_Inject(A_FrameContext)),
446
+ __decorateParam(3, A_Inject(A_FrameCrypto)),
447
+ __decorateParam(4, A_Inject(A_FrameStorageCodec))
448
+ ], A_FrameNodeStorage.prototype, "loadNamespaceFromDisk", 1);
449
+ __decorateClass([
450
+ A_Feature.Extend({
451
+ name: A_FrameNamespaceFeatures.Destroy,
452
+ scope: [A_FrameNamespace]
453
+ }),
454
+ __decorateParam(0, A_Inject(A_Caller)),
455
+ __decorateParam(1, A_Inject(A_FrameEnv)),
456
+ __decorateParam(2, A_Inject(A_FrameContext)),
457
+ __decorateParam(3, A_Inject(A_FrameStorageCodec)),
458
+ __decorateParam(4, A_Inject(A_FrameCrypto))
459
+ ], A_FrameNodeStorage.prototype, "destroyNamespaceFromLocalFileStorage", 1);
460
+ __decorateClass([
461
+ A_Feature.Extend({
462
+ name: A_FrameStorageFeatures.SaveDefinitions,
463
+ scope: [A_FrameStorage]
464
+ }),
465
+ __decorateParam(0, A_Inject(A_FrameEnv)),
466
+ __decorateParam(1, A_Inject(A_FrameStorageOperation)),
467
+ __decorateParam(2, A_Inject(A_FrameContext)),
468
+ __decorateParam(3, A_Inject(A_FrameStorageCodec)),
469
+ __decorateParam(4, A_Inject(A_FrameCrypto))
470
+ ], A_FrameNodeStorage.prototype, "saveDefinitionsToDisk", 1);
471
+ __decorateClass([
472
+ A_Feature.Extend({
473
+ name: A_FrameStorageFeatures.LoadDefinitions,
474
+ scope: [A_FrameStorage]
475
+ }),
476
+ __decorateParam(0, A_Inject(A_FrameEnv)),
477
+ __decorateParam(1, A_Inject(A_FrameStorageOperation)),
478
+ __decorateParam(2, A_Inject(A_FrameContext)),
479
+ __decorateParam(3, A_Inject(A_FrameStorageCodec)),
480
+ __decorateParam(4, A_Inject(A_FrameCrypto))
481
+ ], A_FrameNodeStorage.prototype, "loadDefinitionsFromDisk", 1);
482
+ __decorateClass([
483
+ A_Feature.Extend({
484
+ name: A_FrameStorageFeatures.DestroyDefinitions,
485
+ scope: [A_FrameStorage]
486
+ }),
487
+ __decorateParam(0, A_Inject(A_FrameEnv)),
488
+ __decorateParam(1, A_Inject(A_FrameStorageOperation)),
489
+ __decorateParam(2, A_Inject(A_FrameContext)),
490
+ __decorateParam(3, A_Inject(A_FrameStorageCodec)),
491
+ __decorateParam(4, A_Inject(A_FrameCrypto))
492
+ ], A_FrameNodeStorage.prototype, "destroyDefinitionsFromDisk", 1);
493
+ __decorateClass([
494
+ A_Feature.Extend({
495
+ name: A_FrameStorageFeatures.SaveNamespaces,
496
+ scope: [A_FrameStorage]
497
+ }),
498
+ __decorateParam(0, A_Inject(A_FrameEnv)),
499
+ __decorateParam(1, A_Inject(A_FrameStorageOperation)),
500
+ __decorateParam(2, A_Inject(A_FrameContext)),
501
+ __decorateParam(3, A_Inject(A_FrameStorageCodec)),
502
+ __decorateParam(4, A_Inject(A_FrameCrypto))
503
+ ], A_FrameNodeStorage.prototype, "saveNamespacesToDisk", 1);
504
+ __decorateClass([
505
+ A_Feature.Extend({
506
+ name: A_FrameStorageFeatures.LoadNamespaces,
507
+ scope: [A_FrameStorage]
508
+ }),
509
+ __decorateParam(0, A_Inject(A_FrameEnv)),
510
+ __decorateParam(1, A_Inject(A_FrameStorageOperation)),
511
+ __decorateParam(2, A_Inject(A_FrameContext)),
512
+ __decorateParam(3, A_Inject(A_FrameStorageCodec)),
513
+ __decorateParam(4, A_Inject(A_FrameCrypto))
514
+ ], A_FrameNodeStorage.prototype, "loadNamespacesFromDisk", 1);
515
+ __decorateClass([
516
+ A_Feature.Extend({
517
+ name: A_FrameStorageFeatures.DestroyNamespaces,
518
+ scope: [A_FrameStorage]
519
+ }),
520
+ __decorateParam(0, A_Inject(A_FrameEnv)),
521
+ __decorateParam(1, A_Inject(A_FrameStorageOperation)),
522
+ __decorateParam(2, A_Inject(A_FrameContext)),
523
+ __decorateParam(3, A_Inject(A_FrameStorageCodec)),
524
+ __decorateParam(4, A_Inject(A_FrameCrypto))
525
+ ], A_FrameNodeStorage.prototype, "destroyNamespacesFromDisk", 1);
526
+
527
+ export { A_FrameContext, A_FrameNodeStorage, A_FrameStorage, A_FrameStorageError, A_FrameStorageFeatures, A_FrameStorageOperation };
528
+ //# sourceMappingURL=chunk-6KAGWGTE.mjs.map
529
+ //# sourceMappingURL=chunk-6KAGWGTE.mjs.map