@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.
- package/dist/actions-BizGiU87.d.ts +21058 -0
- package/dist/actions-BizGiU87.d.ts.map +1 -0
- package/dist/clis/args/access-token.mjs +1 -1
- package/dist/clis/args/{common-Bc8EcW9w.mjs → common-DPYlcz-d.mjs} +7 -1
- package/dist/clis/args/common-DPYlcz-d.mjs.map +1 -0
- package/dist/clis/args/common.mjs +1 -1
- package/dist/clis/args/connect.mjs +1 -1
- package/dist/clis/args/{generate-DNGRYRdp.mjs → generate-BJPBa0mK.mjs} +2 -2
- package/dist/clis/args/{generate-DNGRYRdp.mjs.map → generate-BJPBa0mK.mjs.map} +1 -1
- package/dist/clis/args/generate.mjs +1 -1
- package/dist/clis/args/{help-CFAVJzhI.mjs → help-rztSuf9S.mjs} +3 -3
- package/dist/clis/args/{help-CFAVJzhI.mjs.map → help-rztSuf9S.mjs.map} +1 -1
- package/dist/clis/args/help.mjs +1 -1
- package/dist/clis/args/index.d.mts +1 -1
- package/dist/clis/args/index.mjs +3 -3
- package/dist/clis/args/init.mjs +1 -1
- package/dist/clis/args/inspect.mjs +1 -1
- package/dist/clis/args/install.mjs +1 -1
- package/dist/clis/args/list.mjs +1 -1
- package/dist/clis/args/login.mjs +1 -1
- package/dist/clis/args/migrate.mjs +1 -1
- package/dist/clis/args/publish.mjs +1 -1
- package/dist/clis/args/registry.mjs +1 -1
- package/dist/clis/args/service-zdLhL5Q0.d.mts +106 -0
- package/dist/clis/args/service-zdLhL5Q0.d.mts.map +1 -0
- package/dist/clis/args/service.d.mts +1 -1
- package/dist/clis/args/service.mjs +1 -1
- package/dist/clis/args/switchboard.mjs +1 -1
- package/dist/clis/args/uninstall.mjs +1 -1
- package/dist/clis/args/unpublish.mjs +1 -1
- package/dist/clis/args/vetra.mjs +1 -1
- package/dist/clis/build-config.d.mts +4 -4
- package/dist/clis/build-config.d.mts.map +1 -1
- package/dist/clis/constants.d.mts +248 -1
- package/dist/clis/constants.d.mts.map +1 -1
- package/dist/clis/constants.mjs +139 -9
- package/dist/clis/constants.mjs.map +1 -1
- package/dist/clis/index.d.mts +273 -10
- package/dist/clis/index.d.mts.map +1 -1
- package/dist/clis/index.mjs +171 -15
- package/dist/clis/index.mjs.map +1 -1
- package/dist/clis/utils.d.mts +11 -1
- package/dist/clis/utils.d.mts.map +1 -1
- package/dist/clis/utils.mjs +17 -2
- package/dist/clis/utils.mjs.map +1 -1
- package/dist/document-drive/index.d.ts +2 -2
- package/dist/document-drive/index.d.ts.map +1 -1
- package/dist/document-model/index.d.ts +2 -2
- package/dist/document-model/index.js +85 -53
- package/dist/document-model/index.js.map +1 -1
- package/dist/{index-fzb9xR0z.d.ts → index-lpBA_hRO.d.ts} +4 -5
- package/dist/index-lpBA_hRO.d.ts.map +1 -0
- package/dist/index.d.ts +2 -2
- package/dist/processors/index.d.ts +1 -1
- package/dist/registry/index.d.ts +1 -1
- package/dist/registry/index.d.ts.map +1 -1
- package/dist/registry/index.js +6 -0
- package/dist/registry/index.js.map +1 -1
- package/dist/{types-DotvSp4R.d.ts → types-KaPjC4vI.d.ts} +2 -2
- package/dist/{types-DotvSp4R.d.ts.map → types-KaPjC4vI.d.ts.map} +1 -1
- package/package.json +3 -3
- package/dist/actions-muZIbpCg.d.ts +0 -2499
- package/dist/actions-muZIbpCg.d.ts.map +0 -1
- package/dist/clis/args/common-Bc8EcW9w.mjs.map +0 -1
- package/dist/clis/args/service-C88bN_g_.d.mts +0 -22
- package/dist/clis/args/service-C88bN_g_.d.mts.map +0 -1
- 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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
508
|
-
|
|
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
|
-
|
|
3241
|
-
|
|
3242
|
-
|
|
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
|
-
|
|
3246
|
-
|
|
3247
|
-
|
|
3248
|
-
|
|
3249
|
-
|
|
3250
|
-
|
|
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
|
-
|
|
3276
|
-
|
|
3277
|
-
|
|
3278
|
-
|
|
3279
|
-
|
|
3280
|
-
|
|
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
|
|
3315
|
+
const data = await createZip(document);
|
|
3284
3316
|
const writable = await input.createWritable();
|
|
3285
|
-
await writable.write(
|
|
3317
|
+
await writable.write(new Uint8Array(data));
|
|
3286
3318
|
await writable.close();
|
|
3287
3319
|
}
|
|
3288
|
-
|
|
3289
|
-
const
|
|
3290
|
-
if (!
|
|
3291
|
-
|
|
3292
|
-
|
|
3293
|
-
|
|
3294
|
-
|
|
3295
|
-
|
|
3296
|
-
const
|
|
3297
|
-
if (!
|
|
3298
|
-
const
|
|
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
|
-
|
|
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);
|