document-model 1.5.0 → 1.7.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/cjs/document-model.js +2 -2
- package/dist/browser/cjs/document.js +2 -2
- package/dist/browser/cjs/index.js +2 -2
- package/dist/{node/cjs/internal/index-RX6RcsNg.js → browser/cjs/internal/index-BllCzBc9.js} +11 -3
- package/dist/browser/cjs/internal/index-BllCzBc9.js.map +1 -0
- package/dist/browser/cjs/internal/{index-BoiSedJ2.js → index-DTRXQ2Nf.js} +5 -10
- package/dist/browser/{es/internal/index-B7idSyw8.js.map → cjs/internal/index-DTRXQ2Nf.js.map} +1 -1
- package/dist/browser/cjs/internal/{object-DldjPOTT.js → object-Bf9_woMQ.js} +327 -321
- package/dist/browser/cjs/internal/object-Bf9_woMQ.js.map +1 -0
- package/dist/browser/es/document-model.js +2 -2
- package/dist/browser/es/document.js +8 -8
- package/dist/browser/es/index.js +2 -2
- package/dist/browser/es/internal/{index-B7idSyw8.js → index-BAvDobTr.js} +5 -10
- package/dist/{node/es/internal/index-BFRJ-0Rp.js.map → browser/es/internal/index-BAvDobTr.js.map} +1 -1
- package/dist/browser/es/internal/index-Db40bdYP.js +58 -0
- package/dist/browser/es/internal/index-Db40bdYP.js.map +1 -0
- package/dist/browser/es/internal/{object-I6vKsK3r.js → object-CY74acQg.js} +352 -346
- package/dist/browser/es/internal/object-CY74acQg.js.map +1 -0
- package/dist/browser/src/document/actions/creators.d.ts +1 -1
- package/dist/browser/src/document/schema/zod.d.ts +18 -18
- package/dist/browser/src/document/types.d.ts +12 -1
- package/dist/browser/src/document/utils/base.d.ts +1 -1
- package/dist/browser/src/document/utils/crypto.d.ts +10 -0
- package/dist/browser/src/document/utils/document-helpers.d.ts +1 -0
- package/dist/browser/src/document/utils/index.d.ts +1 -0
- package/dist/browser/src/document/utils/node.d.ts +3 -2
- package/dist/browser/src/document-model/gen/schema/zod.d.ts +177 -177
- package/dist/browser/src/document-model/index.d.ts +3 -3
- package/dist/node/cjs/document-model.js +2 -2
- package/dist/node/cjs/document.js +2 -2
- package/dist/node/cjs/index.js +2 -2
- package/dist/node/cjs/internal/{index-WVYoLyly.js → index-aABa-Hb0.js} +5 -10
- package/dist/node/cjs/internal/{index-WVYoLyly.js.map → index-aABa-Hb0.js.map} +1 -1
- package/dist/{browser/cjs/internal/index-frw-qprx.js → node/cjs/internal/index-kI4cPPpE.js} +11 -3
- package/dist/node/cjs/internal/index-kI4cPPpE.js.map +1 -0
- package/dist/node/cjs/internal/{object-7GplcYr4.js → object-BMm0OLWL.js} +173 -60
- package/dist/node/cjs/internal/object-BMm0OLWL.js.map +1 -0
- package/dist/node/es/document-model.js +2 -2
- package/dist/node/es/document.js +8 -8
- package/dist/node/es/index.js +2 -2
- package/dist/node/es/internal/{index-BFRJ-0Rp.js → index-B0WPutmO.js} +5 -10
- package/dist/{browser/cjs/internal/index-BoiSedJ2.js.map → node/es/internal/index-B0WPutmO.js.map} +1 -1
- package/dist/node/es/internal/index-MkEgGMJR.js +58 -0
- package/dist/node/es/internal/index-MkEgGMJR.js.map +1 -0
- package/dist/node/es/internal/{object-Cu2Dz-iF.js → object-VZ_AS47_.js} +198 -85
- package/dist/node/es/internal/object-VZ_AS47_.js.map +1 -0
- package/dist/node/src/document/actions/creators.d.ts +1 -1
- package/dist/node/src/document/schema/zod.d.ts +18 -18
- package/dist/node/src/document/types.d.ts +12 -1
- package/dist/node/src/document/utils/base.d.ts +1 -1
- package/dist/node/src/document/utils/crypto.d.ts +10 -0
- package/dist/node/src/document/utils/document-helpers.d.ts +1 -0
- package/dist/node/src/document/utils/index.d.ts +1 -0
- package/dist/node/src/document/utils/node.d.ts +3 -2
- package/dist/node/src/document-model/gen/schema/zod.d.ts +177 -177
- package/dist/node/src/document-model/index.d.ts +3 -3
- package/package.json +2 -1
- package/dist/browser/cjs/internal/index-frw-qprx.js.map +0 -1
- package/dist/browser/cjs/internal/object-DldjPOTT.js.map +0 -1
- package/dist/browser/es/internal/index-D2kKzCXD.js +0 -50
- package/dist/browser/es/internal/index-D2kKzCXD.js.map +0 -1
- package/dist/browser/es/internal/object-I6vKsK3r.js.map +0 -1
- package/dist/node/cjs/internal/index-RX6RcsNg.js.map +0 -1
- package/dist/node/cjs/internal/object-7GplcYr4.js.map +0 -1
- package/dist/node/es/internal/index-NWZKlhKu.js +0 -50
- package/dist/node/es/internal/index-NWZKlhKu.js.map +0 -1
- package/dist/node/es/internal/object-Cu2Dz-iF.js.map +0 -1
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
const object = require("./object-
|
|
2
|
+
const object = require("./object-BMm0OLWL.js");
|
|
3
3
|
const index = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
4
4
|
__proto__: null,
|
|
5
|
+
ab2hex: object.ab2hex,
|
|
6
|
+
buildOperationSignature: object.buildOperationSignature,
|
|
7
|
+
buildOperationSignatureMessage: object.buildOperationSignatureMessage,
|
|
8
|
+
buildOperationSignatureParams: object.buildOperationSignatureParams,
|
|
9
|
+
buildSignedOperation: object.buildSignedOperation,
|
|
5
10
|
calculateSkipsLeft: object.calculateSkipsLeft,
|
|
6
11
|
createAction: object.createAction,
|
|
7
12
|
createDocument: object.createDocument,
|
|
@@ -12,8 +17,10 @@ const index = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.definePropert
|
|
|
12
17
|
documentHelpers: object.documentHelpers,
|
|
13
18
|
getLocalFile: object.getLocalFile,
|
|
14
19
|
getRemoteFile: object.getRemoteFile,
|
|
20
|
+
getUnixTimestamp: object.getUnixTimestamp,
|
|
15
21
|
hashDocument: object.hashDocument,
|
|
16
22
|
hashKey: object.hashKey,
|
|
23
|
+
hex2ab: object.hex2ab,
|
|
17
24
|
isBaseAction: object.isBaseAction,
|
|
18
25
|
isNoopOperation: object.isNoopOperation,
|
|
19
26
|
isSameDocument: object.isSameDocument,
|
|
@@ -29,7 +36,8 @@ const index = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.definePropert
|
|
|
29
36
|
saveToFileHandle: object.saveToFileHandle,
|
|
30
37
|
sortMappedOperations: object.sortMappedOperations,
|
|
31
38
|
sortOperations: object.sortOperations,
|
|
32
|
-
validateOperations: object.validateOperations
|
|
39
|
+
validateOperations: object.validateOperations,
|
|
40
|
+
verifyOperationSignature: object.verifyOperationSignature
|
|
33
41
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
34
42
|
const Document = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
35
43
|
__proto__: null,
|
|
@@ -46,4 +54,4 @@ const Document = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProp
|
|
|
46
54
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
47
55
|
exports.Document = Document;
|
|
48
56
|
exports.index = index;
|
|
49
|
-
//# sourceMappingURL=index-
|
|
57
|
+
//# sourceMappingURL=index-kI4cPPpE.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index-kI4cPPpE.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -1,17 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
3
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
4
|
-
var __publicField = (obj, key, value) =>
|
|
5
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
6
|
-
return value;
|
|
7
|
-
};
|
|
4
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
8
5
|
const mutative = require("mutative");
|
|
9
6
|
const zod$1 = require("zod");
|
|
10
|
-
const JSZip = require("jszip");
|
|
11
7
|
const crypto$1 = require("crypto");
|
|
12
8
|
const fs = require("fs");
|
|
13
9
|
const https = require("https");
|
|
14
10
|
const path = require("path");
|
|
11
|
+
const JSZip = require("jszip");
|
|
15
12
|
const isDefinedNonNullAny = (v) => v !== void 0 && v !== null;
|
|
16
13
|
const definedNonNullAnySchema = zod$1.z.any().refine((v) => isDefinedNonNullAny(v));
|
|
17
14
|
const Load_StateSchema = zod$1.z.enum(["LOAD_STATE"]);
|
|
@@ -275,8 +272,7 @@ var safeStableStringify = { exports: {} };
|
|
|
275
272
|
if (value) {
|
|
276
273
|
return (value2) => {
|
|
277
274
|
let message = `Object can not safely be stringified. Received type ${typeof value2}`;
|
|
278
|
-
if (typeof value2 !== "function")
|
|
279
|
-
message += ` (${value2.toString()})`;
|
|
275
|
+
if (typeof value2 !== "function") message += ` (${value2.toString()})`;
|
|
280
276
|
throw new Error(message);
|
|
281
277
|
};
|
|
282
278
|
}
|
|
@@ -925,13 +921,142 @@ const REDO = "REDO";
|
|
|
925
921
|
const PRUNE = "PRUNE";
|
|
926
922
|
const LOAD_STATE = "LOAD_STATE";
|
|
927
923
|
const NOOP = "NOOP";
|
|
924
|
+
function writeFile(path$1, name, data) {
|
|
925
|
+
const filePath = path.join(path$1, name);
|
|
926
|
+
fs.mkdirSync(path$1, { recursive: true });
|
|
927
|
+
return new Promise((resolve, reject) => {
|
|
928
|
+
try {
|
|
929
|
+
fs.writeFile(filePath, data, {}, (err) => {
|
|
930
|
+
if (err) {
|
|
931
|
+
reject(err);
|
|
932
|
+
} else {
|
|
933
|
+
resolve(filePath);
|
|
934
|
+
}
|
|
935
|
+
});
|
|
936
|
+
} catch (error) {
|
|
937
|
+
reject(error);
|
|
938
|
+
}
|
|
939
|
+
});
|
|
940
|
+
}
|
|
941
|
+
function readFile(path2) {
|
|
942
|
+
return fs.readFileSync(path2);
|
|
943
|
+
}
|
|
944
|
+
function fetchFile(url) {
|
|
945
|
+
return new Promise((resolve, reject) => {
|
|
946
|
+
https.get(url, (resp) => {
|
|
947
|
+
const data = [];
|
|
948
|
+
const mimeType = resp.headers["content-type"];
|
|
949
|
+
resp.on("data", (chunk) => {
|
|
950
|
+
data.push(chunk);
|
|
951
|
+
});
|
|
952
|
+
resp.on("end", () => {
|
|
953
|
+
resolve({ buffer: Buffer.concat(data), mimeType });
|
|
954
|
+
});
|
|
955
|
+
}).on("error", (err) => {
|
|
956
|
+
reject(err);
|
|
957
|
+
});
|
|
958
|
+
});
|
|
959
|
+
}
|
|
960
|
+
const getFile = async (file) => {
|
|
961
|
+
return readFile(file);
|
|
962
|
+
};
|
|
963
|
+
const hash = (data, algorithm = "sha1") => {
|
|
964
|
+
return crypto$1.createHash(algorithm).update(data).digest("base64");
|
|
965
|
+
};
|
|
966
|
+
function getUnixTimestamp(date) {
|
|
967
|
+
return (new Date(date).getTime() / 1e3).toFixed(0);
|
|
968
|
+
}
|
|
969
|
+
function buildOperationSignatureParams({
|
|
970
|
+
documentId,
|
|
971
|
+
signer,
|
|
972
|
+
operation,
|
|
973
|
+
previousStateHash
|
|
974
|
+
}) {
|
|
975
|
+
const { timestamp, scope, id, type } = operation;
|
|
976
|
+
return [
|
|
977
|
+
getUnixTimestamp(timestamp),
|
|
978
|
+
// timestamp,
|
|
979
|
+
signer.app.key,
|
|
980
|
+
// signer public key
|
|
981
|
+
hash(
|
|
982
|
+
// hash (docID, scope, operationID, operationName, operationInput)
|
|
983
|
+
[documentId, scope, id, type, cjsModule(operation.input)].join(
|
|
984
|
+
""
|
|
985
|
+
)
|
|
986
|
+
),
|
|
987
|
+
previousStateHash
|
|
988
|
+
// state hash that the operation was applied to
|
|
989
|
+
];
|
|
990
|
+
}
|
|
991
|
+
const textEncode = new TextEncoder();
|
|
992
|
+
function buildOperationSignatureMessage(params) {
|
|
993
|
+
const message = params.join("");
|
|
994
|
+
const prefix = "Signed Operation:\n" + message.length.toString();
|
|
995
|
+
return textEncode.encode(prefix + message);
|
|
996
|
+
}
|
|
997
|
+
function ab2hex(ab) {
|
|
998
|
+
return Array.prototype.map.call(
|
|
999
|
+
new Uint8Array(ab),
|
|
1000
|
+
(x) => ("00" + x.toString(16)).slice(-2)
|
|
1001
|
+
).join("");
|
|
1002
|
+
}
|
|
1003
|
+
function hex2ab(hex) {
|
|
1004
|
+
var _a;
|
|
1005
|
+
return new Uint8Array(
|
|
1006
|
+
((_a = hex.match(/[\da-f]{2}/gi)) == null ? void 0 : _a.map(function(h) {
|
|
1007
|
+
return parseInt(h, 16);
|
|
1008
|
+
})) ?? []
|
|
1009
|
+
);
|
|
1010
|
+
}
|
|
1011
|
+
async function buildOperationSignature(context, signMethod) {
|
|
1012
|
+
const params = buildOperationSignatureParams(context);
|
|
1013
|
+
const message = buildOperationSignatureMessage(params);
|
|
1014
|
+
const signature = await signMethod(message);
|
|
1015
|
+
return [...params, `0x${ab2hex(signature)}`];
|
|
1016
|
+
}
|
|
1017
|
+
async function buildSignedOperation(action, reducer, document, context, signHandler) {
|
|
1018
|
+
var _a, _b;
|
|
1019
|
+
const result = reducer(document, action, void 0, {
|
|
1020
|
+
reuseHash: true,
|
|
1021
|
+
reuseOperationResultingState: true
|
|
1022
|
+
});
|
|
1023
|
+
const operation = result.operations[action.scope].at(-1);
|
|
1024
|
+
if (!operation) {
|
|
1025
|
+
throw new Error("Action was not applied");
|
|
1026
|
+
}
|
|
1027
|
+
const previousStateHash = ((_a = result.operations[action.scope].at(-2)) == null ? void 0 : _a.hash) ?? "";
|
|
1028
|
+
const signature = await buildOperationSignature(
|
|
1029
|
+
{
|
|
1030
|
+
...context,
|
|
1031
|
+
operation,
|
|
1032
|
+
previousStateHash
|
|
1033
|
+
},
|
|
1034
|
+
signHandler
|
|
1035
|
+
);
|
|
1036
|
+
return {
|
|
1037
|
+
...operation,
|
|
1038
|
+
context: {
|
|
1039
|
+
...operation.context,
|
|
1040
|
+
signer: {
|
|
1041
|
+
...(_b = operation.context) == null ? void 0 : _b.signer,
|
|
1042
|
+
...context.signer,
|
|
1043
|
+
signatures: [...context.signer.signatures ?? [], signature]
|
|
1044
|
+
}
|
|
1045
|
+
}
|
|
1046
|
+
};
|
|
1047
|
+
}
|
|
1048
|
+
async function verifyOperationSignature(signature, signer, verifyHandler) {
|
|
1049
|
+
const publicKey = signer.app.key;
|
|
1050
|
+
const params = signature.slice(0, 4);
|
|
1051
|
+
const signatureBytes = hex2ab(signature[4]);
|
|
1052
|
+
const expectedMessage = buildOperationSignatureMessage(params);
|
|
1053
|
+
return verifyHandler(publicKey, signatureBytes, expectedMessage);
|
|
1054
|
+
}
|
|
928
1055
|
const types = { "application/andrew-inset": ["ez"], "application/appinstaller": ["appinstaller"], "application/applixware": ["aw"], "application/appx": ["appx"], "application/appxbundle": ["appxbundle"], "application/atom+xml": ["atom"], "application/atomcat+xml": ["atomcat"], "application/atomdeleted+xml": ["atomdeleted"], "application/atomsvc+xml": ["atomsvc"], "application/atsc-dwd+xml": ["dwd"], "application/atsc-held+xml": ["held"], "application/atsc-rsat+xml": ["rsat"], "application/automationml-aml+xml": ["aml"], "application/automationml-amlx+zip": ["amlx"], "application/bdoc": ["bdoc"], "application/calendar+xml": ["xcs"], "application/ccxml+xml": ["ccxml"], "application/cdfx+xml": ["cdfx"], "application/cdmi-capability": ["cdmia"], "application/cdmi-container": ["cdmic"], "application/cdmi-domain": ["cdmid"], "application/cdmi-object": ["cdmio"], "application/cdmi-queue": ["cdmiq"], "application/cpl+xml": ["cpl"], "application/cu-seeme": ["cu"], "application/cwl": ["cwl"], "application/dash+xml": ["mpd"], "application/dash-patch+xml": ["mpp"], "application/davmount+xml": ["davmount"], "application/docbook+xml": ["dbk"], "application/dssc+der": ["dssc"], "application/dssc+xml": ["xdssc"], "application/ecmascript": ["ecma"], "application/emma+xml": ["emma"], "application/emotionml+xml": ["emotionml"], "application/epub+zip": ["epub"], "application/exi": ["exi"], "application/express": ["exp"], "application/fdf": ["fdf"], "application/fdt+xml": ["fdt"], "application/font-tdpfr": ["pfr"], "application/geo+json": ["geojson"], "application/gml+xml": ["gml"], "application/gpx+xml": ["gpx"], "application/gxf": ["gxf"], "application/gzip": ["gz"], "application/hjson": ["hjson"], "application/hyperstudio": ["stk"], "application/inkml+xml": ["ink", "inkml"], "application/ipfix": ["ipfix"], "application/its+xml": ["its"], "application/java-archive": ["jar", "war", "ear"], "application/java-serialized-object": ["ser"], "application/java-vm": ["class"], "application/javascript": ["*js"], "application/json": ["json", "map"], "application/json5": ["json5"], "application/jsonml+json": ["jsonml"], "application/ld+json": ["jsonld"], "application/lgr+xml": ["lgr"], "application/lost+xml": ["lostxml"], "application/mac-binhex40": ["hqx"], "application/mac-compactpro": ["cpt"], "application/mads+xml": ["mads"], "application/manifest+json": ["webmanifest"], "application/marc": ["mrc"], "application/marcxml+xml": ["mrcx"], "application/mathematica": ["ma", "nb", "mb"], "application/mathml+xml": ["mathml"], "application/mbox": ["mbox"], "application/media-policy-dataset+xml": ["mpf"], "application/mediaservercontrol+xml": ["mscml"], "application/metalink+xml": ["metalink"], "application/metalink4+xml": ["meta4"], "application/mets+xml": ["mets"], "application/mmt-aei+xml": ["maei"], "application/mmt-usd+xml": ["musd"], "application/mods+xml": ["mods"], "application/mp21": ["m21", "mp21"], "application/mp4": ["*mp4", "*mpg4", "mp4s", "m4p"], "application/msix": ["msix"], "application/msixbundle": ["msixbundle"], "application/msword": ["doc", "dot"], "application/mxf": ["mxf"], "application/n-quads": ["nq"], "application/n-triples": ["nt"], "application/node": ["cjs"], "application/octet-stream": ["bin", "dms", "lrf", "mar", "so", "dist", "distz", "pkg", "bpk", "dump", "elc", "deploy", "exe", "dll", "deb", "dmg", "iso", "img", "msi", "msp", "msm", "buffer"], "application/oda": ["oda"], "application/oebps-package+xml": ["opf"], "application/ogg": ["ogx"], "application/omdoc+xml": ["omdoc"], "application/onenote": ["onetoc", "onetoc2", "onetmp", "onepkg"], "application/oxps": ["oxps"], "application/p2p-overlay+xml": ["relo"], "application/patch-ops-error+xml": ["xer"], "application/pdf": ["pdf"], "application/pgp-encrypted": ["pgp"], "application/pgp-keys": ["asc"], "application/pgp-signature": ["sig", "*asc"], "application/pics-rules": ["prf"], "application/pkcs10": ["p10"], "application/pkcs7-mime": ["p7m", "p7c"], "application/pkcs7-signature": ["p7s"], "application/pkcs8": ["p8"], "application/pkix-attr-cert": ["ac"], "application/pkix-cert": ["cer"], "application/pkix-crl": ["crl"], "application/pkix-pkipath": ["pkipath"], "application/pkixcmp": ["pki"], "application/pls+xml": ["pls"], "application/postscript": ["ai", "eps", "ps"], "application/provenance+xml": ["provx"], "application/pskc+xml": ["pskcxml"], "application/raml+yaml": ["raml"], "application/rdf+xml": ["rdf", "owl"], "application/reginfo+xml": ["rif"], "application/relax-ng-compact-syntax": ["rnc"], "application/resource-lists+xml": ["rl"], "application/resource-lists-diff+xml": ["rld"], "application/rls-services+xml": ["rs"], "application/route-apd+xml": ["rapd"], "application/route-s-tsid+xml": ["sls"], "application/route-usd+xml": ["rusd"], "application/rpki-ghostbusters": ["gbr"], "application/rpki-manifest": ["mft"], "application/rpki-roa": ["roa"], "application/rsd+xml": ["rsd"], "application/rss+xml": ["rss"], "application/rtf": ["rtf"], "application/sbml+xml": ["sbml"], "application/scvp-cv-request": ["scq"], "application/scvp-cv-response": ["scs"], "application/scvp-vp-request": ["spq"], "application/scvp-vp-response": ["spp"], "application/sdp": ["sdp"], "application/senml+xml": ["senmlx"], "application/sensml+xml": ["sensmlx"], "application/set-payment-initiation": ["setpay"], "application/set-registration-initiation": ["setreg"], "application/shf+xml": ["shf"], "application/sieve": ["siv", "sieve"], "application/smil+xml": ["smi", "smil"], "application/sparql-query": ["rq"], "application/sparql-results+xml": ["srx"], "application/sql": ["sql"], "application/srgs": ["gram"], "application/srgs+xml": ["grxml"], "application/sru+xml": ["sru"], "application/ssdl+xml": ["ssdl"], "application/ssml+xml": ["ssml"], "application/swid+xml": ["swidtag"], "application/tei+xml": ["tei", "teicorpus"], "application/thraud+xml": ["tfi"], "application/timestamped-data": ["tsd"], "application/toml": ["toml"], "application/trig": ["trig"], "application/ttml+xml": ["ttml"], "application/ubjson": ["ubj"], "application/urc-ressheet+xml": ["rsheet"], "application/urc-targetdesc+xml": ["td"], "application/voicexml+xml": ["vxml"], "application/wasm": ["wasm"], "application/watcherinfo+xml": ["wif"], "application/widget": ["wgt"], "application/winhlp": ["hlp"], "application/wsdl+xml": ["wsdl"], "application/wspolicy+xml": ["wspolicy"], "application/xaml+xml": ["xaml"], "application/xcap-att+xml": ["xav"], "application/xcap-caps+xml": ["xca"], "application/xcap-diff+xml": ["xdf"], "application/xcap-el+xml": ["xel"], "application/xcap-ns+xml": ["xns"], "application/xenc+xml": ["xenc"], "application/xfdf": ["xfdf"], "application/xhtml+xml": ["xhtml", "xht"], "application/xliff+xml": ["xlf"], "application/xml": ["xml", "xsl", "xsd", "rng"], "application/xml-dtd": ["dtd"], "application/xop+xml": ["xop"], "application/xproc+xml": ["xpl"], "application/xslt+xml": ["*xsl", "xslt"], "application/xspf+xml": ["xspf"], "application/xv+xml": ["mxml", "xhvml", "xvml", "xvm"], "application/yang": ["yang"], "application/yin+xml": ["yin"], "application/zip": ["zip"], "audio/3gpp": ["*3gpp"], "audio/aac": ["adts", "aac"], "audio/adpcm": ["adp"], "audio/amr": ["amr"], "audio/basic": ["au", "snd"], "audio/midi": ["mid", "midi", "kar", "rmi"], "audio/mobile-xmf": ["mxmf"], "audio/mp3": ["*mp3"], "audio/mp4": ["m4a", "mp4a"], "audio/mpeg": ["mpga", "mp2", "mp2a", "mp3", "m2a", "m3a"], "audio/ogg": ["oga", "ogg", "spx", "opus"], "audio/s3m": ["s3m"], "audio/silk": ["sil"], "audio/wav": ["wav"], "audio/wave": ["*wav"], "audio/webm": ["weba"], "audio/xm": ["xm"], "font/collection": ["ttc"], "font/otf": ["otf"], "font/ttf": ["ttf"], "font/woff": ["woff"], "font/woff2": ["woff2"], "image/aces": ["exr"], "image/apng": ["apng"], "image/avci": ["avci"], "image/avcs": ["avcs"], "image/avif": ["avif"], "image/bmp": ["bmp", "dib"], "image/cgm": ["cgm"], "image/dicom-rle": ["drle"], "image/dpx": ["dpx"], "image/emf": ["emf"], "image/fits": ["fits"], "image/g3fax": ["g3"], "image/gif": ["gif"], "image/heic": ["heic"], "image/heic-sequence": ["heics"], "image/heif": ["heif"], "image/heif-sequence": ["heifs"], "image/hej2k": ["hej2"], "image/hsj2": ["hsj2"], "image/ief": ["ief"], "image/jls": ["jls"], "image/jp2": ["jp2", "jpg2"], "image/jpeg": ["jpeg", "jpg", "jpe"], "image/jph": ["jph"], "image/jphc": ["jhc"], "image/jpm": ["jpm", "jpgm"], "image/jpx": ["jpx", "jpf"], "image/jxr": ["jxr"], "image/jxra": ["jxra"], "image/jxrs": ["jxrs"], "image/jxs": ["jxs"], "image/jxsc": ["jxsc"], "image/jxsi": ["jxsi"], "image/jxss": ["jxss"], "image/ktx": ["ktx"], "image/ktx2": ["ktx2"], "image/png": ["png"], "image/sgi": ["sgi"], "image/svg+xml": ["svg", "svgz"], "image/t38": ["t38"], "image/tiff": ["tif", "tiff"], "image/tiff-fx": ["tfx"], "image/webp": ["webp"], "image/wmf": ["wmf"], "message/disposition-notification": ["disposition-notification"], "message/global": ["u8msg"], "message/global-delivery-status": ["u8dsn"], "message/global-disposition-notification": ["u8mdn"], "message/global-headers": ["u8hdr"], "message/rfc822": ["eml", "mime"], "model/3mf": ["3mf"], "model/gltf+json": ["gltf"], "model/gltf-binary": ["glb"], "model/iges": ["igs", "iges"], "model/jt": ["jt"], "model/mesh": ["msh", "mesh", "silo"], "model/mtl": ["mtl"], "model/obj": ["obj"], "model/prc": ["prc"], "model/step+xml": ["stpx"], "model/step+zip": ["stpz"], "model/step-xml+zip": ["stpxz"], "model/stl": ["stl"], "model/u3d": ["u3d"], "model/vrml": ["wrl", "vrml"], "model/x3d+binary": ["*x3db", "x3dbz"], "model/x3d+fastinfoset": ["x3db"], "model/x3d+vrml": ["*x3dv", "x3dvz"], "model/x3d+xml": ["x3d", "x3dz"], "model/x3d-vrml": ["x3dv"], "text/cache-manifest": ["appcache", "manifest"], "text/calendar": ["ics", "ifb"], "text/coffeescript": ["coffee", "litcoffee"], "text/css": ["css"], "text/csv": ["csv"], "text/html": ["html", "htm", "shtml"], "text/jade": ["jade"], "text/javascript": ["js", "mjs"], "text/jsx": ["jsx"], "text/less": ["less"], "text/markdown": ["md", "markdown"], "text/mathml": ["mml"], "text/mdx": ["mdx"], "text/n3": ["n3"], "text/plain": ["txt", "text", "conf", "def", "list", "log", "in", "ini"], "text/richtext": ["rtx"], "text/rtf": ["*rtf"], "text/sgml": ["sgml", "sgm"], "text/shex": ["shex"], "text/slim": ["slim", "slm"], "text/spdx": ["spdx"], "text/stylus": ["stylus", "styl"], "text/tab-separated-values": ["tsv"], "text/troff": ["t", "tr", "roff", "man", "me", "ms"], "text/turtle": ["ttl"], "text/uri-list": ["uri", "uris", "urls"], "text/vcard": ["vcard"], "text/vtt": ["vtt"], "text/wgsl": ["wgsl"], "text/xml": ["*xml"], "text/yaml": ["yaml", "yml"], "video/3gpp": ["3gp", "3gpp"], "video/3gpp2": ["3g2"], "video/h261": ["h261"], "video/h263": ["h263"], "video/h264": ["h264"], "video/iso.segment": ["m4s"], "video/jpeg": ["jpgv"], "video/jpm": ["*jpm", "*jpgm"], "video/mj2": ["mj2", "mjp2"], "video/mp2t": ["ts"], "video/mp4": ["mp4", "mp4v", "mpg4"], "video/mpeg": ["mpeg", "mpg", "mpe", "m1v", "m2v"], "video/ogg": ["ogv"], "video/quicktime": ["qt", "mov"], "video/webm": ["webm"] };
|
|
929
1056
|
Object.freeze(types);
|
|
930
1057
|
var __classPrivateFieldGet = function(receiver, state, kind, f) {
|
|
931
|
-
if (kind === "a" && !f)
|
|
932
|
-
|
|
933
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
|
|
934
|
-
throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
1058
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
1059
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
935
1060
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
936
1061
|
};
|
|
937
1062
|
var _Mime_extensionToType, _Mime_typeToExtension, _Mime_typeToExtensions;
|
|
@@ -1014,48 +1139,6 @@ class Mime {
|
|
|
1014
1139
|
}
|
|
1015
1140
|
_Mime_extensionToType = /* @__PURE__ */ new WeakMap(), _Mime_typeToExtension = /* @__PURE__ */ new WeakMap(), _Mime_typeToExtensions = /* @__PURE__ */ new WeakMap();
|
|
1016
1141
|
const mime = new Mime(types)._freeze();
|
|
1017
|
-
function writeFile(path$1, name, data) {
|
|
1018
|
-
const filePath = path.join(path$1, name);
|
|
1019
|
-
fs.mkdirSync(path$1, { recursive: true });
|
|
1020
|
-
return new Promise((resolve, reject) => {
|
|
1021
|
-
try {
|
|
1022
|
-
fs.writeFile(filePath, data, {}, (err) => {
|
|
1023
|
-
if (err) {
|
|
1024
|
-
reject(err);
|
|
1025
|
-
} else {
|
|
1026
|
-
resolve(filePath);
|
|
1027
|
-
}
|
|
1028
|
-
});
|
|
1029
|
-
} catch (error) {
|
|
1030
|
-
reject(error);
|
|
1031
|
-
}
|
|
1032
|
-
});
|
|
1033
|
-
}
|
|
1034
|
-
function readFile(path2) {
|
|
1035
|
-
return fs.readFileSync(path2);
|
|
1036
|
-
}
|
|
1037
|
-
function fetchFile(url) {
|
|
1038
|
-
return new Promise((resolve, reject) => {
|
|
1039
|
-
https.get(url, (resp) => {
|
|
1040
|
-
const data = [];
|
|
1041
|
-
const mimeType = resp.headers["content-type"];
|
|
1042
|
-
resp.on("data", (chunk) => {
|
|
1043
|
-
data.push(chunk);
|
|
1044
|
-
});
|
|
1045
|
-
resp.on("end", () => {
|
|
1046
|
-
resolve({ buffer: Buffer.concat(data), mimeType });
|
|
1047
|
-
});
|
|
1048
|
-
}).on("error", (err) => {
|
|
1049
|
-
reject(err);
|
|
1050
|
-
});
|
|
1051
|
-
});
|
|
1052
|
-
}
|
|
1053
|
-
const getFile = async (file) => {
|
|
1054
|
-
return readFile(file);
|
|
1055
|
-
};
|
|
1056
|
-
const hash = (data, algorithm = "sha1") => {
|
|
1057
|
-
return crypto$1.createHash(algorithm).update(data).digest("base64");
|
|
1058
|
-
};
|
|
1059
1142
|
function validateOperations(operations) {
|
|
1060
1143
|
const errors = [];
|
|
1061
1144
|
const scopes = Object.keys(operations);
|
|
@@ -1125,8 +1208,7 @@ function garbageCollect(sortedOperations) {
|
|
|
1125
1208
|
function addUndo(sortedOperations) {
|
|
1126
1209
|
const operationsCopy = [...sortedOperations];
|
|
1127
1210
|
const latestOperation = operationsCopy[operationsCopy.length - 1];
|
|
1128
|
-
if (!latestOperation)
|
|
1129
|
-
return operationsCopy;
|
|
1211
|
+
if (!latestOperation) return operationsCopy;
|
|
1130
1212
|
if (latestOperation.type === "NOOP") {
|
|
1131
1213
|
operationsCopy.push({
|
|
1132
1214
|
...latestOperation,
|
|
@@ -1389,6 +1471,22 @@ function filterDuplicatedOperations(targetOperations, sourceOperations) {
|
|
|
1389
1471
|
return true;
|
|
1390
1472
|
});
|
|
1391
1473
|
}
|
|
1474
|
+
function filterDocumentOperationsResultingState(documentOperations) {
|
|
1475
|
+
if (!documentOperations) {
|
|
1476
|
+
return {};
|
|
1477
|
+
}
|
|
1478
|
+
const entries = Object.entries(documentOperations);
|
|
1479
|
+
return entries.reduce(
|
|
1480
|
+
(acc, [scope, operations]) => ({
|
|
1481
|
+
...acc,
|
|
1482
|
+
[scope]: operations.map((op) => {
|
|
1483
|
+
const { resultingState, ...restProps } = op;
|
|
1484
|
+
return restProps;
|
|
1485
|
+
})
|
|
1486
|
+
}),
|
|
1487
|
+
{}
|
|
1488
|
+
);
|
|
1489
|
+
}
|
|
1392
1490
|
const documentHelpers = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
1393
1491
|
__proto__: null,
|
|
1394
1492
|
IntegrityIssueSubType,
|
|
@@ -1397,6 +1495,7 @@ const documentHelpers = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.def
|
|
|
1397
1495
|
attachBranch,
|
|
1398
1496
|
checkCleanedOperationsIntegrity,
|
|
1399
1497
|
checkOperationsIntegrity,
|
|
1498
|
+
filterDocumentOperationsResultingState,
|
|
1400
1499
|
filterDuplicatedOperations,
|
|
1401
1500
|
garbageCollect,
|
|
1402
1501
|
garbageCollectDocumentOperations,
|
|
@@ -1428,7 +1527,14 @@ const createZip = async (document) => {
|
|
|
1428
1527
|
"state.json",
|
|
1429
1528
|
JSON.stringify(document.initialState || {}, null, 2)
|
|
1430
1529
|
);
|
|
1431
|
-
zip.file(
|
|
1530
|
+
zip.file(
|
|
1531
|
+
"operations.json",
|
|
1532
|
+
JSON.stringify(
|
|
1533
|
+
filterDocumentOperationsResultingState(document.operations),
|
|
1534
|
+
null,
|
|
1535
|
+
2
|
|
1536
|
+
)
|
|
1537
|
+
);
|
|
1432
1538
|
if (document.attachments) {
|
|
1433
1539
|
const attachments = Object.keys(document.attachments);
|
|
1434
1540
|
attachments.forEach((key) => {
|
|
@@ -1574,7 +1680,7 @@ function updateOperations(document, action, skip = 0) {
|
|
|
1574
1680
|
nextIndex = action.index;
|
|
1575
1681
|
operationId = action.id;
|
|
1576
1682
|
} else {
|
|
1577
|
-
operationId = v4();
|
|
1683
|
+
operationId = "id" in action ? action.id : v4();
|
|
1578
1684
|
}
|
|
1579
1685
|
operations.push({
|
|
1580
1686
|
...action,
|
|
@@ -1622,8 +1728,7 @@ function processUndoRedo(document, action, skip) {
|
|
|
1622
1728
|
function processSkipOperation(document, action, customReducer, skipValue, reuseOperationResultingState = false, resultingStateParser = parseResultingState) {
|
|
1623
1729
|
const scope = action.scope;
|
|
1624
1730
|
const latestOperation = document.operations[scope].at(-1);
|
|
1625
|
-
if (!latestOperation)
|
|
1626
|
-
return document;
|
|
1731
|
+
if (!latestOperation) return document;
|
|
1627
1732
|
const documentOperations = garbageCollectDocumentOperations(
|
|
1628
1733
|
{
|
|
1629
1734
|
...document.operations,
|
|
@@ -2300,8 +2405,13 @@ function applyMixins(derivedCtor, constructors) {
|
|
|
2300
2405
|
}
|
|
2301
2406
|
exports.BaseActions = BaseActions;
|
|
2302
2407
|
exports.BaseDocument = BaseDocument;
|
|
2408
|
+
exports.ab2hex = ab2hex;
|
|
2303
2409
|
exports.applyMixins = applyMixins;
|
|
2304
2410
|
exports.baseReducer = baseReducer;
|
|
2411
|
+
exports.buildOperationSignature = buildOperationSignature;
|
|
2412
|
+
exports.buildOperationSignatureMessage = buildOperationSignatureMessage;
|
|
2413
|
+
exports.buildOperationSignatureParams = buildOperationSignatureParams;
|
|
2414
|
+
exports.buildSignedOperation = buildSignedOperation;
|
|
2305
2415
|
exports.calculateSkipsLeft = calculateSkipsLeft;
|
|
2306
2416
|
exports.createAction = createAction;
|
|
2307
2417
|
exports.createDocument = createDocument;
|
|
@@ -2312,8 +2422,10 @@ exports.createZip = createZip;
|
|
|
2312
2422
|
exports.documentHelpers = documentHelpers;
|
|
2313
2423
|
exports.getLocalFile = getLocalFile;
|
|
2314
2424
|
exports.getRemoteFile = getRemoteFile;
|
|
2425
|
+
exports.getUnixTimestamp = getUnixTimestamp;
|
|
2315
2426
|
exports.hashDocument = hashDocument;
|
|
2316
2427
|
exports.hashKey = hashKey;
|
|
2428
|
+
exports.hex2ab = hex2ab;
|
|
2317
2429
|
exports.isBaseAction = isBaseAction;
|
|
2318
2430
|
exports.isNoopOperation = isNoopOperation;
|
|
2319
2431
|
exports.isSameDocument = isSameDocument;
|
|
@@ -2334,5 +2446,6 @@ exports.sortOperations = sortOperations;
|
|
|
2334
2446
|
exports.updateDocument = updateDocument;
|
|
2335
2447
|
exports.updateHeader = updateHeader;
|
|
2336
2448
|
exports.validateOperations = validateOperations;
|
|
2449
|
+
exports.verifyOperationSignature = verifyOperationSignature;
|
|
2337
2450
|
exports.zod = zod;
|
|
2338
|
-
//# sourceMappingURL=object-
|
|
2451
|
+
//# sourceMappingURL=object-BMm0OLWL.js.map
|