@powerhousedao/shared 6.0.0-dev.247 → 6.0.0-dev.249

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 (67) hide show
  1. package/dist/actions-BizGiU87.d.ts +21058 -0
  2. package/dist/actions-BizGiU87.d.ts.map +1 -0
  3. package/dist/clis/args/access-token.mjs +1 -1
  4. package/dist/clis/args/{common-Bc8EcW9w.mjs → common-DPYlcz-d.mjs} +7 -1
  5. package/dist/clis/args/common-DPYlcz-d.mjs.map +1 -0
  6. package/dist/clis/args/common.mjs +1 -1
  7. package/dist/clis/args/connect.mjs +1 -1
  8. package/dist/clis/args/{generate-DNGRYRdp.mjs → generate-BJPBa0mK.mjs} +2 -2
  9. package/dist/clis/args/{generate-DNGRYRdp.mjs.map → generate-BJPBa0mK.mjs.map} +1 -1
  10. package/dist/clis/args/generate.mjs +1 -1
  11. package/dist/clis/args/{help-CFAVJzhI.mjs → help-rztSuf9S.mjs} +3 -3
  12. package/dist/clis/args/{help-CFAVJzhI.mjs.map → help-rztSuf9S.mjs.map} +1 -1
  13. package/dist/clis/args/help.mjs +1 -1
  14. package/dist/clis/args/index.d.mts +1 -1
  15. package/dist/clis/args/index.mjs +3 -3
  16. package/dist/clis/args/init.mjs +1 -1
  17. package/dist/clis/args/inspect.mjs +1 -1
  18. package/dist/clis/args/install.mjs +1 -1
  19. package/dist/clis/args/list.mjs +1 -1
  20. package/dist/clis/args/login.mjs +1 -1
  21. package/dist/clis/args/migrate.mjs +1 -1
  22. package/dist/clis/args/publish.mjs +1 -1
  23. package/dist/clis/args/registry.mjs +1 -1
  24. package/dist/clis/args/service-zdLhL5Q0.d.mts +106 -0
  25. package/dist/clis/args/service-zdLhL5Q0.d.mts.map +1 -0
  26. package/dist/clis/args/service.d.mts +1 -1
  27. package/dist/clis/args/service.mjs +1 -1
  28. package/dist/clis/args/switchboard.mjs +1 -1
  29. package/dist/clis/args/uninstall.mjs +1 -1
  30. package/dist/clis/args/unpublish.mjs +1 -1
  31. package/dist/clis/args/vetra.mjs +1 -1
  32. package/dist/clis/build-config.d.mts +4 -4
  33. package/dist/clis/build-config.d.mts.map +1 -1
  34. package/dist/clis/constants.d.mts +248 -1
  35. package/dist/clis/constants.d.mts.map +1 -1
  36. package/dist/clis/constants.mjs +139 -9
  37. package/dist/clis/constants.mjs.map +1 -1
  38. package/dist/clis/index.d.mts +273 -10
  39. package/dist/clis/index.d.mts.map +1 -1
  40. package/dist/clis/index.mjs +171 -15
  41. package/dist/clis/index.mjs.map +1 -1
  42. package/dist/clis/utils.d.mts +11 -1
  43. package/dist/clis/utils.d.mts.map +1 -1
  44. package/dist/clis/utils.mjs +17 -2
  45. package/dist/clis/utils.mjs.map +1 -1
  46. package/dist/document-drive/index.d.ts +2 -2
  47. package/dist/document-drive/index.d.ts.map +1 -1
  48. package/dist/document-model/index.d.ts +2 -2
  49. package/dist/document-model/index.js +85 -53
  50. package/dist/document-model/index.js.map +1 -1
  51. package/dist/{index-fzb9xR0z.d.ts → index-lpBA_hRO.d.ts} +4 -5
  52. package/dist/index-lpBA_hRO.d.ts.map +1 -0
  53. package/dist/index.d.ts +2 -2
  54. package/dist/processors/index.d.ts +1 -1
  55. package/dist/registry/index.d.ts +1 -1
  56. package/dist/registry/index.d.ts.map +1 -1
  57. package/dist/registry/index.js +6 -0
  58. package/dist/registry/index.js.map +1 -1
  59. package/dist/{types-DotvSp4R.d.ts → types-KaPjC4vI.d.ts} +2 -2
  60. package/dist/{types-DotvSp4R.d.ts.map → types-KaPjC4vI.d.ts.map} +1 -1
  61. package/package.json +3 -3
  62. package/dist/actions-muZIbpCg.d.ts +0 -2499
  63. package/dist/actions-muZIbpCg.d.ts.map +0 -1
  64. package/dist/clis/args/common-Bc8EcW9w.mjs.map +0 -1
  65. package/dist/clis/args/service-C88bN_g_.d.mts +0 -22
  66. package/dist/clis/args/service-C88bN_g_.d.mts.map +0 -1
  67. package/dist/index-fzb9xR0z.d.ts.map +0 -1
@@ -2,6 +2,7 @@ import { a as buildOperationSignatureParams, c as hex2ab, i as buildOperationSig
2
2
  import { generateMock } from "./mock.js";
3
3
  import { ZodError, z } from "zod";
4
4
  import { stringify } from "safe-stable-stringify";
5
+ import { strFromU8, strToU8, unzip, zip } from "fflate";
5
6
  import { castDraft, create, unsafe } from "mutative";
6
7
  import { pascalCase } from "change-case";
7
8
  //#region document-model/errors.ts
@@ -303,29 +304,29 @@ function DocumentModelInputSchema() {
303
304
  function DocumentModelGlobalStateSchema() {
304
305
  return z.object({
305
306
  __typename: z.literal("DocumentModelGlobalState").optional(),
306
- author: AuthorSchema(),
307
- description: z.string(),
308
- extension: z.string(),
309
307
  id: z.string(),
310
308
  name: z.string(),
309
+ author: AuthorSchema(),
310
+ extension: z.string(),
311
+ description: z.string(),
311
312
  specifications: z.array(DocumentSpecificationSchema())
312
313
  });
313
314
  }
314
315
  function DocumentSpecificationSchema() {
315
316
  return z.object({
316
317
  __typename: z.literal("DocumentSpecification").optional(),
317
- changeLog: z.array(z.string()),
318
- modules: z.array(ModuleSchema()),
319
318
  state: ScopeStateSchema(),
320
- version: z.number().int()
319
+ modules: z.array(ModuleSchema()),
320
+ version: z.number().int(),
321
+ changeLog: z.array(z.string())
321
322
  });
322
323
  }
323
324
  function ModuleSchema() {
324
325
  return z.object({
325
326
  __typename: z.literal("ModuleSpecification").optional(),
326
- description: z.string().nullable(),
327
327
  id: z.string(),
328
328
  name: z.string(),
329
+ description: z.string().nullable(),
329
330
  operations: z.array(OperationSpecificationSchema())
330
331
  });
331
332
  }
@@ -338,24 +339,24 @@ function MoveOperationInputSchema() {
338
339
  function OperationSpecificationSchema() {
339
340
  return z.object({
340
341
  __typename: z.literal("OperationSpecification").optional(),
341
- description: z.string().nullable(),
342
- errors: z.array(OperationErrorSchema()),
343
- examples: z.array(CodeExampleSchema()),
344
342
  id: z.string(),
345
343
  name: z.string().nullable(),
346
- reducer: z.string().nullable(),
344
+ description: z.string().nullable(),
347
345
  schema: z.string().nullable(),
348
346
  template: z.string().nullable(),
347
+ reducer: z.string().nullable(),
348
+ errors: z.array(OperationErrorSchema()),
349
+ examples: z.array(CodeExampleSchema()),
349
350
  scope: OperationScopeSchema()
350
351
  });
351
352
  }
352
353
  function OperationErrorSchema() {
353
354
  return z.object({
354
355
  __typename: z.literal("OperationErrorSpecification").optional(),
355
- code: z.string().nullable(),
356
- description: z.string().nullable(),
357
356
  id: z.string(),
358
357
  name: z.string().nullable(),
358
+ code: z.string().nullable(),
359
+ description: z.string().nullable(),
359
360
  template: z.string().nullable()
360
361
  });
361
362
  }
@@ -497,15 +498,15 @@ function SetStateSchemaInputSchema() {
497
498
  function StateSchema() {
498
499
  return z.object({
499
500
  __typename: z.literal("State").optional(),
501
+ schema: z.string(),
500
502
  examples: z.array(CodeExampleSchema()),
501
- initialValue: z.string(),
502
- schema: z.string()
503
+ initialValue: z.string()
503
504
  });
504
505
  }
505
506
  function ScopeStateSchema() {
506
507
  return z.object({
507
- global: StateSchema(),
508
- local: StateSchema()
508
+ local: StateSchema(),
509
+ global: StateSchema()
509
510
  });
510
511
  }
511
512
  function UpdateChangeLogItemInputSchema() {
@@ -2563,16 +2564,16 @@ function baseReducer(document, action, customReducer, dispatch, options = {}) {
2563
2564
  });
2564
2565
  } catch (error) {
2565
2566
  const actionScopeOps = newDocument.operations[_action.scope];
2566
- if (!actionScopeOps) throw new Error(`No operations found for scope: ${_action.scope}`);
2567
+ if (!actionScopeOps) throw new Error(`No operations found for scope: ${_action.scope}`, { cause: error });
2567
2568
  const lastOperationIndex = actionScopeOps.length - 1;
2568
2569
  const draftScopeOps = draft.operations[_action.scope];
2569
- if (!draftScopeOps) throw new Error(`No operations found in draft for scope: ${_action.scope}`);
2570
+ if (!draftScopeOps) throw new Error(`No operations found in draft for scope: ${_action.scope}`, { cause: error });
2570
2571
  draftScopeOps[lastOperationIndex].error = error.message;
2571
2572
  draftScopeOps[lastOperationIndex].skip = 0;
2572
2573
  if (shouldProcessSkipOperation) {
2573
2574
  draft.state = castDraft({ ...document.state });
2574
2575
  const documentScopeOps = document.operations[_action.scope];
2575
- if (!documentScopeOps) throw new Error(`No operations found for scope: ${_action.scope}`);
2576
+ if (!documentScopeOps) throw new Error(`No operations found for scope: ${_action.scope}`, { cause: error });
2576
2577
  draft.operations = castDraft({
2577
2578
  ...document.operations,
2578
2579
  [_action.scope]: [...documentScopeOps, { ...draftScopeOps[lastOperationIndex] }]
@@ -3237,18 +3238,50 @@ const documentModelReducer = createReducer(documentModelStateReducer);
3237
3238
  //#endregion
3238
3239
  //#region document-model/files.ts
3239
3240
  const NON_DOMAIN_SCOPES = new Set(["auth", "document"]);
3240
- async function loadJSZip() {
3241
- const { default: JSZip } = await import("jszip");
3242
- return JSZip;
3241
+ function zipAsync(data) {
3242
+ return new Promise((resolve, reject) => {
3243
+ zip(data, (err, out) => err ? reject(err) : resolve(out));
3244
+ });
3245
+ }
3246
+ function unzipAsync(data) {
3247
+ return new Promise((resolve, reject) => {
3248
+ unzip(data, (err, out) => err ? reject(err) : resolve(out));
3249
+ });
3250
+ }
3251
+ const BASE64_RE = /^[A-Za-z0-9+/]+={0,2}$/;
3252
+ function isLikelyBase64(s) {
3253
+ if (s.length === 0 || s.length % 4 !== 0) return false;
3254
+ return BASE64_RE.test(s);
3255
+ }
3256
+ function binaryStringToUint8Array(s) {
3257
+ const arr = new Uint8Array(s.length);
3258
+ for (let i = 0; i < s.length; i++) arr[i] = s.charCodeAt(i) & 255;
3259
+ return arr;
3260
+ }
3261
+ function base64ToUint8Array(s) {
3262
+ if (typeof atob === "function") return binaryStringToUint8Array(atob(s));
3263
+ const BufferCtor = globalThis.Buffer;
3264
+ if (!BufferCtor) throw new Error("Cannot decode base64 string: neither `atob` nor `Buffer` is available in this environment");
3265
+ return BufferCtor.from(s, "base64");
3266
+ }
3267
+ async function toUint8Array(input) {
3268
+ if (input instanceof Uint8Array) return input;
3269
+ if (input instanceof ArrayBuffer) return new Uint8Array(input);
3270
+ if (typeof Blob !== "undefined" && input instanceof Blob) return new Uint8Array(await input.arrayBuffer());
3271
+ if (Array.isArray(input)) return new Uint8Array(input);
3272
+ if (typeof input === "string") return isLikelyBase64(input) ? base64ToUint8Array(input) : binaryStringToUint8Array(input);
3273
+ throw new Error("Unsupported FileInput type");
3274
+ }
3275
+ function jsonEntry(value) {
3276
+ return strToU8(JSON.stringify(value, null, 2));
3243
3277
  }
3244
3278
  async function createZip(document) {
3245
- const zip = new (await (loadJSZip()))();
3246
- const header = document.header;
3247
- zip.file("header.json", JSON.stringify(header, null, 2));
3248
- zip.file("state.json", JSON.stringify(document.initialState || {}, null, 2));
3249
- zip.file("current-state.json", JSON.stringify(document.state || {}, null, 2));
3250
- zip.file("operations.json", JSON.stringify(filterDocumentOperationsResultingState(document.operations), null, 2));
3251
- return zip;
3279
+ return zipAsync({
3280
+ "header.json": jsonEntry(document.header),
3281
+ "state.json": jsonEntry(document.initialState || {}),
3282
+ "current-state.json": jsonEntry(document.state || {}),
3283
+ "operations.json": jsonEntry(filterDocumentOperationsResultingState(document.operations))
3284
+ });
3252
3285
  }
3253
3286
  /**
3254
3287
  * Creates a minimal ZIP backup from strand data.
@@ -3256,7 +3289,6 @@ async function createZip(document) {
3256
3289
  * Creates a ZIP with minimal header and empty operations.
3257
3290
  */
3258
3291
  async function createMinimalZip(data) {
3259
- const JSZip = await loadJSZip();
3260
3292
  const now = (/* @__PURE__ */ new Date()).toISOString();
3261
3293
  const header = {
3262
3294
  id: data.documentId,
@@ -3272,30 +3304,32 @@ async function createMinimalZip(data) {
3272
3304
  revision: {},
3273
3305
  lastModifiedAtUtcIso: now
3274
3306
  };
3275
- const zip = new JSZip();
3276
- zip.file("header.json", JSON.stringify(header, null, 2));
3277
- zip.file("state.json", JSON.stringify(data.state, null, 2));
3278
- zip.file("current-state.json", JSON.stringify(data.state, null, 2));
3279
- zip.file("operations.json", JSON.stringify({}, null, 2));
3280
- return zip;
3307
+ return zipAsync({
3308
+ "header.json": jsonEntry(header),
3309
+ "state.json": jsonEntry(data.state),
3310
+ "current-state.json": jsonEntry(data.state),
3311
+ "operations.json": jsonEntry({})
3312
+ });
3281
3313
  }
3282
3314
  async function baseSaveToFileHandle(document, input) {
3283
- const blob = await (await createZip(document)).generateAsync({ type: "blob" });
3315
+ const data = await createZip(document);
3284
3316
  const writable = await input.createWritable();
3285
- await writable.write(blob);
3317
+ await writable.write(new Uint8Array(data));
3286
3318
  await writable.close();
3287
3319
  }
3288
- async function loadFromZip(zip, reducer, options) {
3289
- const initialStateZip = zip.file("state.json");
3290
- if (!initialStateZip) throw new Error("Initial state not found");
3291
- const initialStateStr = await initialStateZip.async("string");
3292
- const initialState = JSON.parse(initialStateStr);
3293
- const headerZip = zip.file("header.json");
3294
- if (!headerZip) throw new Error("Document header not found - file format may be outdated");
3295
- const header = JSON.parse(await headerZip.async("string"));
3296
- const operationsZip = zip.file("operations.json");
3297
- if (!operationsZip) throw new Error("Operations history not found");
3298
- const clearedOperations = garbageCollectDocumentOperations(JSON.parse(await operationsZip.async("string")));
3320
+ function readEntry(files, name) {
3321
+ const entry = files[name];
3322
+ if (!entry) throw new Error(`${name} not found in document zip`);
3323
+ return strFromU8(entry);
3324
+ }
3325
+ async function loadFromZipData(data, reducer, options) {
3326
+ const files = await unzipAsync(data);
3327
+ if (!files["state.json"]) throw new Error("Initial state not found");
3328
+ const initialState = JSON.parse(readEntry(files, "state.json"));
3329
+ if (!files["header.json"]) throw new Error("Document header not found - file format may be outdated");
3330
+ const header = JSON.parse(readEntry(files, "header.json"));
3331
+ if (!files["operations.json"]) throw new Error("Operations history not found");
3332
+ const clearedOperations = garbageCollectDocumentOperations(JSON.parse(readEntry(files, "operations.json")));
3299
3333
  const operationsError = validateOperations(clearedOperations);
3300
3334
  if (operationsError.length) {
3301
3335
  const errorMessages = operationsError.map((err) => err.message);
@@ -3307,9 +3341,7 @@ async function loadFromZip(zip, reducer, options) {
3307
3341
  };
3308
3342
  }
3309
3343
  async function baseLoadFromInput(input, reducer, options) {
3310
- const zip = new (await (loadJSZip()))();
3311
- await zip.loadAsync(input);
3312
- return loadFromZip(zip, reducer, options);
3344
+ return loadFromZipData(await toUint8Array(input), reducer, options);
3313
3345
  }
3314
3346
  const documentModelLoadFromInput = (input) => {
3315
3347
  return baseLoadFromInput(input, documentModelReducer);