@milaboratories/pl-tree 1.8.47 → 1.8.49

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 (57) hide show
  1. package/dist/_virtual/_rolldown/runtime.cjs +29 -0
  2. package/dist/accessors.cjs +236 -273
  3. package/dist/accessors.cjs.map +1 -1
  4. package/dist/accessors.d.ts +93 -93
  5. package/dist/accessors.js +235 -271
  6. package/dist/accessors.js.map +1 -1
  7. package/dist/dump.cjs +79 -80
  8. package/dist/dump.cjs.map +1 -1
  9. package/dist/dump.d.ts +16 -18
  10. package/dist/dump.js +79 -79
  11. package/dist/dump.js.map +1 -1
  12. package/dist/index.cjs +31 -35
  13. package/dist/index.d.ts +10 -10
  14. package/dist/index.js +9 -8
  15. package/dist/snapshot.cjs +50 -71
  16. package/dist/snapshot.cjs.map +1 -1
  17. package/dist/snapshot.d.ts +36 -38
  18. package/dist/snapshot.js +49 -69
  19. package/dist/snapshot.js.map +1 -1
  20. package/dist/state.cjs +487 -624
  21. package/dist/state.cjs.map +1 -1
  22. package/dist/state.d.ts +117 -116
  23. package/dist/state.js +486 -622
  24. package/dist/state.js.map +1 -1
  25. package/dist/sync.cjs +113 -133
  26. package/dist/sync.cjs.map +1 -1
  27. package/dist/sync.d.ts +37 -33
  28. package/dist/sync.js +111 -131
  29. package/dist/sync.js.map +1 -1
  30. package/dist/synchronized_tree.cjs +167 -232
  31. package/dist/synchronized_tree.cjs.map +1 -1
  32. package/dist/synchronized_tree.d.ts +66 -68
  33. package/dist/synchronized_tree.js +165 -211
  34. package/dist/synchronized_tree.js.map +1 -1
  35. package/dist/traversal_ops.d.ts +42 -42
  36. package/dist/value_and_error.cjs +9 -12
  37. package/dist/value_and_error.cjs.map +1 -1
  38. package/dist/value_and_error.d.ts +8 -5
  39. package/dist/value_and_error.js +9 -11
  40. package/dist/value_and_error.js.map +1 -1
  41. package/dist/value_or_error.d.ts +8 -5
  42. package/package.json +9 -9
  43. package/src/synchronized_tree.ts +10 -5
  44. package/dist/accessors.d.ts.map +0 -1
  45. package/dist/dump.d.ts.map +0 -1
  46. package/dist/index.cjs.map +0 -1
  47. package/dist/index.d.ts.map +0 -1
  48. package/dist/index.js.map +0 -1
  49. package/dist/snapshot.d.ts.map +0 -1
  50. package/dist/state.d.ts.map +0 -1
  51. package/dist/sync.d.ts.map +0 -1
  52. package/dist/synchronized_tree.d.ts.map +0 -1
  53. package/dist/test_utils.d.ts +0 -25
  54. package/dist/test_utils.d.ts.map +0 -1
  55. package/dist/traversal_ops.d.ts.map +0 -1
  56. package/dist/value_and_error.d.ts.map +0 -1
  57. package/dist/value_or_error.d.ts.map +0 -1
package/dist/snapshot.cjs CHANGED
@@ -1,88 +1,67 @@
1
- 'use strict';
2
-
3
- var accessors = require('./accessors.cjs');
4
- var tsHelpers = require('@milaboratories/ts-helpers');
1
+ const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
2
+ const require_accessors = require('./accessors.cjs');
3
+ let _milaboratories_ts_helpers = require("@milaboratories/ts-helpers");
5
4
 
5
+ //#region src/snapshot.ts
6
6
  /** Creates ResourceSnapshotSchema. It converts an optional schema type to schema type. */
7
7
  function rsSchema(schema) {
8
- return schema;
8
+ return schema;
9
9
  }
10
10
  function makeResourceSnapshot(res, schema, ctx) {
11
- const node = res instanceof accessors.PlTreeEntry
12
- ? tsHelpers.notEmpty(ctx).accessor(res).node()
13
- : res instanceof accessors.PlTreeEntryAccessor
14
- ? res.node()
15
- : res;
16
- const info = node.resourceInfo;
17
- const result = { ...info };
18
- if (schema.data !== undefined) {
19
- if (schema.data === "raw")
20
- result.data = node.getData();
21
- else
22
- result.data = schema.data.parse(node.getDataAsJson());
23
- }
24
- if (schema.fields !== undefined) {
25
- const fields = {};
26
- // even if field is not defined, corresponding object field
27
- // with "undefined" value will still be added
28
- for (const [fieldName, required] of Object.entries(schema.fields))
29
- fields[fieldName] = node.traverse({
30
- field: fieldName,
31
- errorIfFieldNotSet: required,
32
- stableIfNotFound: !required,
33
- })?.id;
34
- result.fields = fields;
35
- }
36
- if (schema.kv !== undefined) {
37
- const kv = {};
38
- for (const [fieldName, type] of Object.entries(schema.kv)) {
39
- const value = node.getKeyValue(fieldName);
40
- if (value === undefined) {
41
- throw new Error(`Key not found ${fieldName}`);
42
- }
43
- else if (type === "raw") {
44
- kv[fieldName] = value;
45
- }
46
- else {
47
- kv[fieldName] = type.parse(JSON.parse(Buffer.from(value).toString("utf-8")));
48
- }
49
- }
50
- result.kv = kv;
51
- }
52
- return result;
11
+ const node = res instanceof require_accessors.PlTreeEntry ? (0, _milaboratories_ts_helpers.notEmpty)(ctx).accessor(res).node() : res instanceof require_accessors.PlTreeEntryAccessor ? res.node() : res;
12
+ const result = { ...node.resourceInfo };
13
+ if (schema.data !== void 0) if (schema.data === "raw") result.data = node.getData();
14
+ else result.data = schema.data.parse(node.getDataAsJson());
15
+ if (schema.fields !== void 0) {
16
+ const fields = {};
17
+ for (const [fieldName, required] of Object.entries(schema.fields)) fields[fieldName] = node.traverse({
18
+ field: fieldName,
19
+ errorIfFieldNotSet: required,
20
+ stableIfNotFound: !required
21
+ })?.id;
22
+ result.fields = fields;
23
+ }
24
+ if (schema.kv !== void 0) {
25
+ const kv = {};
26
+ for (const [fieldName, type] of Object.entries(schema.kv)) {
27
+ const value = node.getKeyValue(fieldName);
28
+ if (value === void 0) throw new Error(`Key not found ${fieldName}`);
29
+ else if (type === "raw") kv[fieldName] = value;
30
+ else kv[fieldName] = type.parse(JSON.parse(Buffer.from(value).toString("utf-8")));
31
+ }
32
+ result.kv = kv;
33
+ }
34
+ return result;
53
35
  }
54
36
  /** @deprecated */
55
37
  function treeEntryToResourceWithData(res, fields, ctx) {
56
- if (res instanceof accessors.PlTreeEntry) {
57
- const node = ctx.accessor(res).node();
58
- const info = node.resourceInfo;
59
- const fValues = fields.map((name) => [
60
- name,
61
- node.getField(name)?.value?.id,
62
- ]);
63
- return {
64
- ...info,
65
- fields: new Map(fValues),
66
- data: node.getData() ?? new Uint8Array(),
67
- };
68
- }
69
- return res;
38
+ if (res instanceof require_accessors.PlTreeEntry) {
39
+ const node = ctx.accessor(res).node();
40
+ const info = node.resourceInfo;
41
+ const fValues = fields.map((name) => [name, node.getField(name)?.value?.id]);
42
+ return {
43
+ ...info,
44
+ fields: new Map(fValues),
45
+ data: node.getData() ?? new Uint8Array()
46
+ };
47
+ }
48
+ return res;
70
49
  }
71
50
  /** @deprecated */
72
51
  function treeEntryToResourceWithMetadata(res, mdKeys, ctx) {
73
- if (!(res instanceof accessors.PlTreeEntry))
74
- return res;
75
- const node = ctx.accessor(res).node();
76
- const info = node.resourceInfo;
77
- const mdEntries = mdKeys.map((k) => [k, node.getKeyValue(k)]);
78
- return {
79
- ...info,
80
- metadata: Object.fromEntries(mdEntries),
81
- };
52
+ if (!(res instanceof require_accessors.PlTreeEntry)) return res;
53
+ const node = ctx.accessor(res).node();
54
+ const info = node.resourceInfo;
55
+ const mdEntries = mdKeys.map((k) => [k, node.getKeyValue(k)]);
56
+ return {
57
+ ...info,
58
+ metadata: Object.fromEntries(mdEntries)
59
+ };
82
60
  }
83
61
 
62
+ //#endregion
84
63
  exports.makeResourceSnapshot = makeResourceSnapshot;
85
64
  exports.rsSchema = rsSchema;
86
65
  exports.treeEntryToResourceWithData = treeEntryToResourceWithData;
87
66
  exports.treeEntryToResourceWithMetadata = treeEntryToResourceWithMetadata;
88
- //# sourceMappingURL=snapshot.cjs.map
67
+ //# sourceMappingURL=snapshot.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"snapshot.cjs","sources":["../src/snapshot.ts"],"sourcesContent":["import type { ResourceId, ResourceType } from \"@milaboratories/pl-client\";\nimport type { Optional, Writable } from \"utility-types\";\nimport type { ZodType, z } from \"zod\";\nimport type { PlTreeNodeAccessor } from \"./accessors\";\nimport { PlTreeEntry, PlTreeEntryAccessor } from \"./accessors\";\nimport type { ComputableCtx } from \"@milaboratories/computable\";\nimport { notEmpty } from \"@milaboratories/ts-helpers\";\n\n/**\n * A DTO that can be generated from a tree node to make a snapshot of specific parts of it's state.\n * Such snapshots can then be used in core that requires this information without the need of\n * retrieving state from the tree.\n */\nexport type ResourceSnapshot<\n Data = undefined,\n Fields extends Record<string, ResourceId | undefined> | undefined = undefined,\n KV extends Record<string, unknown> | undefined = undefined,\n> = {\n readonly id: ResourceId;\n readonly type: ResourceType;\n readonly data: Data;\n readonly fields: Fields;\n readonly kv: KV;\n};\n\n/** The most generic type of ResourceSnapshot. */\ntype ResourceSnapshotGeneric = ResourceSnapshot<\n unknown,\n Record<string, ResourceId | undefined> | undefined,\n Record<string, unknown> | undefined\n>;\n\n/** Request that we'll pass to getResourceSnapshot function. We infer the type of ResourceSnapshot from this. */\nexport type ResourceSnapshotSchema<\n Data extends ZodType | \"raw\" | undefined = undefined,\n Fields extends Record<string, boolean> | undefined = undefined,\n KV extends Record<string, ZodType | \"raw\"> | undefined = undefined,\n> = {\n readonly data: Data;\n readonly fields: Fields;\n readonly kv: KV;\n};\n\n/** Creates ResourceSnapshotSchema. It converts an optional schema type to schema type. */\nexport function rsSchema<\n const Data extends ZodType | \"raw\" | undefined = undefined,\n const Fields extends Record<string, boolean> | undefined = undefined,\n const KV extends Record<string, ZodType | \"raw\"> | undefined = undefined,\n>(\n schema: Optional<ResourceSnapshotSchema<Data, Fields, KV>>,\n): ResourceSnapshotSchema<Data, Fields, KV> {\n return schema as any;\n}\n\n/** The most generic type of ResourceSnapshotSchema. */\ntype ResourceSnapshotSchemaGeneric = ResourceSnapshotSchema<\n ZodType | \"raw\" | undefined,\n Record<string, boolean> | undefined,\n Record<string, ZodType | \"raw\"> | undefined\n>;\n\n/**\n * If Data is 'raw' in schema, we'll get bytes,\n * if it's Zod, we'll parse it via zod.\n * Or else we just got undefined in the field.\n */\ntype InferDataType<Data extends ZodType | \"raw\" | undefined> = Data extends \"raw\"\n ? Uint8Array\n : Data extends ZodType\n ? z.infer<Data>\n : undefined;\n\n/**\n * If Fields is a record of field names to booleans,\n * then if the value of the field is true, we'll require this field and throw a Error if it wasn't found.\n * If it's false and doesn't exist, we'll return undefined.\n * If Fields type is undefined, we won't set fields at all.\n */\ntype InferFieldsType<Fields extends Record<string, boolean> | undefined> = Fields extends undefined\n ? undefined\n : {\n [FieldName in keyof Fields]: Fields[FieldName] extends true\n ? ResourceId\n : ResourceId | undefined;\n };\n\n/**\n * If KV is undefined, won't set it.\n * If one of values is Zod, we'll get KV and converts it to Zod schema.\n * If the value is 'raw', just returns bytes.\n */\ntype InferKVType<KV extends Record<string, ZodType | \"raw\"> | undefined> = KV extends undefined\n ? undefined\n : {\n [FieldName in keyof KV]: KV[FieldName] extends ZodType ? z.infer<KV[FieldName]> : Uint8Array;\n };\n\n/** Infer ResourceSnapshot from ResourceShapshotSchema, S can be any ResourceSnapshotSchema. */\nexport type InferSnapshot<S extends ResourceSnapshotSchemaGeneric> = ResourceSnapshot<\n InferDataType<S[\"data\"]>,\n InferFieldsType<S[\"fields\"]>,\n InferKVType<S[\"kv\"]>\n>;\n\n/** Gets a ResourceSnapshot from PlTreeEntry. */\nexport function makeResourceSnapshot<Schema extends ResourceSnapshotSchemaGeneric>(\n res: PlTreeEntry,\n schema: Schema,\n ctx: ComputableCtx,\n): InferSnapshot<Schema>;\nexport function makeResourceSnapshot<Schema extends ResourceSnapshotSchemaGeneric>(\n res: PlTreeEntryAccessor | PlTreeNodeAccessor,\n schema: Schema,\n): InferSnapshot<Schema>;\nexport function makeResourceSnapshot<Schema extends ResourceSnapshotSchemaGeneric>(\n res: PlTreeEntry | PlTreeEntryAccessor | PlTreeNodeAccessor,\n schema: Schema,\n ctx?: ComputableCtx,\n): InferSnapshot<Schema> {\n const node =\n res instanceof PlTreeEntry\n ? notEmpty(ctx).accessor(res).node()\n : res instanceof PlTreeEntryAccessor\n ? res.node()\n : res;\n const info = node.resourceInfo;\n const result: Optional<Writable<ResourceSnapshotGeneric>, \"data\" | \"fields\" | \"kv\"> = { ...info };\n\n if (schema.data !== undefined) {\n if (schema.data === \"raw\") result.data = node.getData();\n else result.data = schema.data.parse(node.getDataAsJson());\n }\n\n if (schema.fields !== undefined) {\n const fields: Record<string, ResourceId | undefined> = {};\n // even if field is not defined, corresponding object field\n // with \"undefined\" value will still be added\n for (const [fieldName, required] of Object.entries(schema.fields))\n fields[fieldName] = node.traverse({\n field: fieldName,\n errorIfFieldNotSet: required,\n stableIfNotFound: !required,\n })?.id;\n result.fields = fields;\n }\n\n if (schema.kv !== undefined) {\n const kv: Record<string, unknown> = {};\n for (const [fieldName, type] of Object.entries(schema.kv)) {\n const value = node.getKeyValue(fieldName);\n\n if (value === undefined) {\n throw new Error(`Key not found ${fieldName}`);\n } else if (type === \"raw\") {\n kv[fieldName] = value;\n } else {\n kv[fieldName] = type.parse(JSON.parse(Buffer.from(value).toString(\"utf-8\")));\n }\n }\n result.kv = kv;\n }\n\n return result as any;\n}\n\n/** @deprecated */\nexport type ResourceWithData = {\n readonly id: ResourceId;\n readonly type: ResourceType;\n readonly fields: Map<string, ResourceId | undefined>;\n readonly data?: Uint8Array;\n};\n\n/** @deprecated */\nexport function treeEntryToResourceWithData(\n res: PlTreeEntry | ResourceWithData,\n fields: string[],\n ctx: ComputableCtx,\n): ResourceWithData {\n if (res instanceof PlTreeEntry) {\n const node = ctx.accessor(res).node();\n const info = node.resourceInfo;\n\n const fValues: [string, ResourceId | undefined][] = fields.map((name) => [\n name,\n node.getField(name)?.value?.id,\n ]);\n\n return {\n ...info,\n fields: new Map(fValues),\n data: node.getData() ?? new Uint8Array(),\n };\n }\n\n return res;\n}\n\n/** @deprecated */\nexport type ResourceWithMetadata = {\n readonly id: ResourceId;\n readonly type: ResourceType;\n readonly metadata: Record<string, any>;\n};\n\n/** @deprecated */\nexport function treeEntryToResourceWithMetadata(\n res: PlTreeEntry | ResourceWithMetadata,\n mdKeys: string[],\n ctx: ComputableCtx,\n): ResourceWithMetadata {\n if (!(res instanceof PlTreeEntry)) return res;\n\n const node = ctx.accessor(res).node();\n const info = node.resourceInfo;\n const mdEntries: [string, any][] = mdKeys.map((k) => [k, node.getKeyValue(k)]);\n\n return {\n ...info,\n metadata: Object.fromEntries(mdEntries),\n };\n}\n"],"names":["PlTreeEntry","notEmpty","PlTreeEntryAccessor"],"mappings":";;;;;AA2CA;AACM,SAAU,QAAQ,CAKtB,MAA0D,EAAA;AAE1D,IAAA,OAAO,MAAa;AACtB;SA8DgB,oBAAoB,CAClC,GAA2D,EAC3D,MAAc,EACd,GAAmB,EAAA;AAEnB,IAAA,MAAM,IAAI,GACR,GAAG,YAAYA;AACb,UAAEC,kBAAQ,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,IAAI;UAChC,GAAG,YAAYC;AACf,cAAE,GAAG,CAAC,IAAI;cACR,GAAG;AACX,IAAA,MAAM,IAAI,GAAG,IAAI,CAAC,YAAY;AAC9B,IAAA,MAAM,MAAM,GAA0E,EAAE,GAAG,IAAI,EAAE;AAEjG,IAAA,IAAI,MAAM,CAAC,IAAI,KAAK,SAAS,EAAE;AAC7B,QAAA,IAAI,MAAM,CAAC,IAAI,KAAK,KAAK;AAAE,YAAA,MAAM,CAAC,IAAI,GAAG,IAAI,CAAC,OAAO,EAAE;;AAClD,YAAA,MAAM,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,aAAa,EAAE,CAAC;IAC5D;AAEA,IAAA,IAAI,MAAM,CAAC,MAAM,KAAK,SAAS,EAAE;QAC/B,MAAM,MAAM,GAA2C,EAAE;;;AAGzD,QAAA,KAAK,MAAM,CAAC,SAAS,EAAE,QAAQ,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC;AAC/D,YAAA,MAAM,CAAC,SAAS,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC;AAChC,gBAAA,KAAK,EAAE,SAAS;AAChB,gBAAA,kBAAkB,EAAE,QAAQ;gBAC5B,gBAAgB,EAAE,CAAC,QAAQ;aAC5B,CAAC,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G,IAAI;AACP,YAAA,MAAM,EAAE,IAAI,GAAG,CAAC,OAAO,CAAC;YACxB,IAAI,EAAE,IAAI,CAAC,OAAO,EAAE,IAAI,IAAI,UAAU,EAAE;SACzC;IACH;AAEA,IAAA,OAAO,GAAG;AACZ;AASA;SACgB,+BAA+B,CAC7C,GAAuC,EACvC,MAAgB,EAChB,GAAkB,EAAA;AAElB,IAAA,IAAI,EAAE,GAAG,YAAYA,qBAAW,CAAC;AAAE,QAAA,OAAO,GAAG;IAE7C,MAAM,IAAI,GAAG,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE;AACrC,IAAA,MAAM,IAAI,GAAG,IAAI,CAAC,YAAY;IAC9B,MAAM,SAAS,GAAoB,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;IAE9E,OAAO;AACL,QAAA,GAAG,IAAI;AACP,QAAA,QAAQ,EAAE,MAAM,CAAC,WAAW,CAAC,SAAS,CAAC;KACxC;AACH;;;;;;;"}
1
+ {"version":3,"file":"snapshot.cjs","names":["PlTreeEntry","PlTreeEntryAccessor"],"sources":["../src/snapshot.ts"],"sourcesContent":["import type { ResourceId, ResourceType } from \"@milaboratories/pl-client\";\nimport type { Optional, Writable } from \"utility-types\";\nimport type { ZodType, z } from \"zod\";\nimport type { PlTreeNodeAccessor } from \"./accessors\";\nimport { PlTreeEntry, PlTreeEntryAccessor } from \"./accessors\";\nimport type { ComputableCtx } from \"@milaboratories/computable\";\nimport { notEmpty } from \"@milaboratories/ts-helpers\";\n\n/**\n * A DTO that can be generated from a tree node to make a snapshot of specific parts of it's state.\n * Such snapshots can then be used in core that requires this information without the need of\n * retrieving state from the tree.\n */\nexport type ResourceSnapshot<\n Data = undefined,\n Fields extends Record<string, ResourceId | undefined> | undefined = undefined,\n KV extends Record<string, unknown> | undefined = undefined,\n> = {\n readonly id: ResourceId;\n readonly type: ResourceType;\n readonly data: Data;\n readonly fields: Fields;\n readonly kv: KV;\n};\n\n/** The most generic type of ResourceSnapshot. */\ntype ResourceSnapshotGeneric = ResourceSnapshot<\n unknown,\n Record<string, ResourceId | undefined> | undefined,\n Record<string, unknown> | undefined\n>;\n\n/** Request that we'll pass to getResourceSnapshot function. We infer the type of ResourceSnapshot from this. */\nexport type ResourceSnapshotSchema<\n Data extends ZodType | \"raw\" | undefined = undefined,\n Fields extends Record<string, boolean> | undefined = undefined,\n KV extends Record<string, ZodType | \"raw\"> | undefined = undefined,\n> = {\n readonly data: Data;\n readonly fields: Fields;\n readonly kv: KV;\n};\n\n/** Creates ResourceSnapshotSchema. It converts an optional schema type to schema type. */\nexport function rsSchema<\n const Data extends ZodType | \"raw\" | undefined = undefined,\n const Fields extends Record<string, boolean> | undefined = undefined,\n const KV extends Record<string, ZodType | \"raw\"> | undefined = undefined,\n>(\n schema: Optional<ResourceSnapshotSchema<Data, Fields, KV>>,\n): ResourceSnapshotSchema<Data, Fields, KV> {\n return schema as any;\n}\n\n/** The most generic type of ResourceSnapshotSchema. */\ntype ResourceSnapshotSchemaGeneric = ResourceSnapshotSchema<\n ZodType | \"raw\" | undefined,\n Record<string, boolean> | undefined,\n Record<string, ZodType | \"raw\"> | undefined\n>;\n\n/**\n * If Data is 'raw' in schema, we'll get bytes,\n * if it's Zod, we'll parse it via zod.\n * Or else we just got undefined in the field.\n */\ntype InferDataType<Data extends ZodType | \"raw\" | undefined> = Data extends \"raw\"\n ? Uint8Array\n : Data extends ZodType\n ? z.infer<Data>\n : undefined;\n\n/**\n * If Fields is a record of field names to booleans,\n * then if the value of the field is true, we'll require this field and throw a Error if it wasn't found.\n * If it's false and doesn't exist, we'll return undefined.\n * If Fields type is undefined, we won't set fields at all.\n */\ntype InferFieldsType<Fields extends Record<string, boolean> | undefined> = Fields extends undefined\n ? undefined\n : {\n [FieldName in keyof Fields]: Fields[FieldName] extends true\n ? ResourceId\n : ResourceId | undefined;\n };\n\n/**\n * If KV is undefined, won't set it.\n * If one of values is Zod, we'll get KV and converts it to Zod schema.\n * If the value is 'raw', just returns bytes.\n */\ntype InferKVType<KV extends Record<string, ZodType | \"raw\"> | undefined> = KV extends undefined\n ? undefined\n : {\n [FieldName in keyof KV]: KV[FieldName] extends ZodType ? z.infer<KV[FieldName]> : Uint8Array;\n };\n\n/** Infer ResourceSnapshot from ResourceShapshotSchema, S can be any ResourceSnapshotSchema. */\nexport type InferSnapshot<S extends ResourceSnapshotSchemaGeneric> = ResourceSnapshot<\n InferDataType<S[\"data\"]>,\n InferFieldsType<S[\"fields\"]>,\n InferKVType<S[\"kv\"]>\n>;\n\n/** Gets a ResourceSnapshot from PlTreeEntry. */\nexport function makeResourceSnapshot<Schema extends ResourceSnapshotSchemaGeneric>(\n res: PlTreeEntry,\n schema: Schema,\n ctx: ComputableCtx,\n): InferSnapshot<Schema>;\nexport function makeResourceSnapshot<Schema extends ResourceSnapshotSchemaGeneric>(\n res: PlTreeEntryAccessor | PlTreeNodeAccessor,\n schema: Schema,\n): InferSnapshot<Schema>;\nexport function makeResourceSnapshot<Schema extends ResourceSnapshotSchemaGeneric>(\n res: PlTreeEntry | PlTreeEntryAccessor | PlTreeNodeAccessor,\n schema: Schema,\n ctx?: ComputableCtx,\n): InferSnapshot<Schema> {\n const node =\n res instanceof PlTreeEntry\n ? notEmpty(ctx).accessor(res).node()\n : res instanceof PlTreeEntryAccessor\n ? res.node()\n : res;\n const info = node.resourceInfo;\n const result: Optional<Writable<ResourceSnapshotGeneric>, \"data\" | \"fields\" | \"kv\"> = { ...info };\n\n if (schema.data !== undefined) {\n if (schema.data === \"raw\") result.data = node.getData();\n else result.data = schema.data.parse(node.getDataAsJson());\n }\n\n if (schema.fields !== undefined) {\n const fields: Record<string, ResourceId | undefined> = {};\n // even if field is not defined, corresponding object field\n // with \"undefined\" value will still be added\n for (const [fieldName, required] of Object.entries(schema.fields))\n fields[fieldName] = node.traverse({\n field: fieldName,\n errorIfFieldNotSet: required,\n stableIfNotFound: !required,\n })?.id;\n result.fields = fields;\n }\n\n if (schema.kv !== undefined) {\n const kv: Record<string, unknown> = {};\n for (const [fieldName, type] of Object.entries(schema.kv)) {\n const value = node.getKeyValue(fieldName);\n\n if (value === undefined) {\n throw new Error(`Key not found ${fieldName}`);\n } else if (type === \"raw\") {\n kv[fieldName] = value;\n } else {\n kv[fieldName] = type.parse(JSON.parse(Buffer.from(value).toString(\"utf-8\")));\n }\n }\n result.kv = kv;\n }\n\n return result as any;\n}\n\n/** @deprecated */\nexport type ResourceWithData = {\n readonly id: ResourceId;\n readonly type: ResourceType;\n readonly fields: Map<string, ResourceId | undefined>;\n readonly data?: Uint8Array;\n};\n\n/** @deprecated */\nexport function treeEntryToResourceWithData(\n res: PlTreeEntry | ResourceWithData,\n fields: string[],\n ctx: ComputableCtx,\n): ResourceWithData {\n if (res instanceof PlTreeEntry) {\n const node = ctx.accessor(res).node();\n const info = node.resourceInfo;\n\n const fValues: [string, ResourceId | undefined][] = fields.map((name) => [\n name,\n node.getField(name)?.value?.id,\n ]);\n\n return {\n ...info,\n fields: new Map(fValues),\n data: node.getData() ?? new Uint8Array(),\n };\n }\n\n return res;\n}\n\n/** @deprecated */\nexport type ResourceWithMetadata = {\n readonly id: ResourceId;\n readonly type: ResourceType;\n readonly metadata: Record<string, any>;\n};\n\n/** @deprecated */\nexport function treeEntryToResourceWithMetadata(\n res: PlTreeEntry | ResourceWithMetadata,\n mdKeys: string[],\n ctx: ComputableCtx,\n): ResourceWithMetadata {\n if (!(res instanceof PlTreeEntry)) return res;\n\n const node = ctx.accessor(res).node();\n const info = node.resourceInfo;\n const mdEntries: [string, any][] = mdKeys.map((k) => [k, node.getKeyValue(k)]);\n\n return {\n ...info,\n metadata: Object.fromEntries(mdEntries),\n };\n}\n"],"mappings":";;;;;;AA4CA,SAAgB,SAKd,QAC0C;AAC1C,QAAO;;AA+DT,SAAgB,qBACd,KACA,QACA,KACuB;CACvB,MAAM,OACJ,eAAeA,y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ACA,QACA,KACsB;AACtB,KAAI,EAAE,eAAeA,+BAAc,QAAO;CAE1C,MAAM,OAAO,IAAI,SAAS,IAAI,CAAC,MAAM;CACrC,MAAM,OAAO,KAAK;CAClB,MAAM,YAA6B,OAAO,KAAK,MAAM,CAAC,GAAG,KAAK,YAAY,EAAE,CAAC,CAAC;AAE9E,QAAO;EACL,GAAG;EACH,UAAU,OAAO,YAAY,UAAU;EACxC"}
@@ -1,29 +1,30 @@
1
- import type { ResourceId, ResourceType } from "@milaboratories/pl-client";
2
- import type { Optional } from "utility-types";
3
- import type { ZodType, z } from "zod";
4
- import type { PlTreeNodeAccessor } from "./accessors";
5
- import { PlTreeEntry, PlTreeEntryAccessor } from "./accessors";
6
- import type { ComputableCtx } from "@milaboratories/computable";
1
+ import { PlTreeEntry, PlTreeEntryAccessor, PlTreeNodeAccessor } from "./accessors.js";
2
+ import { ResourceId, ResourceType } from "@milaboratories/pl-client";
3
+ import { ComputableCtx } from "@milaboratories/computable";
4
+ import { Optional } from "utility-types";
5
+ import { ZodType, z } from "zod";
6
+
7
+ //#region src/snapshot.d.ts
7
8
  /**
8
9
  * A DTO that can be generated from a tree node to make a snapshot of specific parts of it's state.
9
10
  * Such snapshots can then be used in core that requires this information without the need of
10
11
  * retrieving state from the tree.
11
12
  */
12
- export type ResourceSnapshot<Data = undefined, Fields extends Record<string, ResourceId | undefined> | undefined = undefined, KV extends Record<string, unknown> | undefined = undefined> = {
13
- readonly id: ResourceId;
14
- readonly type: ResourceType;
15
- readonly data: Data;
16
- readonly fields: Fields;
17
- readonly kv: KV;
13
+ type ResourceSnapshot<Data = undefined, Fields extends Record<string, ResourceId | undefined> | undefined = undefined, KV extends Record<string, unknown> | undefined = undefined> = {
14
+ readonly id: ResourceId;
15
+ readonly type: ResourceType;
16
+ readonly data: Data;
17
+ readonly fields: Fields;
18
+ readonly kv: KV;
18
19
  };
19
20
  /** Request that we'll pass to getResourceSnapshot function. We infer the type of ResourceSnapshot from this. */
20
- export type ResourceSnapshotSchema<Data extends ZodType | "raw" | undefined = undefined, Fields extends Record<string, boolean> | undefined = undefined, KV extends Record<string, ZodType | "raw"> | undefined = undefined> = {
21
- readonly data: Data;
22
- readonly fields: Fields;
23
- readonly kv: KV;
21
+ type ResourceSnapshotSchema<Data extends ZodType | "raw" | undefined = undefined, Fields extends Record<string, boolean> | undefined = undefined, KV extends Record<string, ZodType | "raw"> | undefined = undefined> = {
22
+ readonly data: Data;
23
+ readonly fields: Fields;
24
+ readonly kv: KV;
24
25
  };
25
26
  /** Creates ResourceSnapshotSchema. It converts an optional schema type to schema type. */
26
- export declare function rsSchema<const Data extends ZodType | "raw" | undefined = undefined, const Fields extends Record<string, boolean> | undefined = undefined, const KV extends Record<string, ZodType | "raw"> | undefined = undefined>(schema: Optional<ResourceSnapshotSchema<Data, Fields, KV>>): ResourceSnapshotSchema<Data, Fields, KV>;
27
+ declare function rsSchema<const Data extends ZodType | "raw" | undefined = undefined, const Fields extends Record<string, boolean> | undefined = undefined, const KV extends Record<string, ZodType | "raw"> | undefined = undefined>(schema: Optional<ResourceSnapshotSchema<Data, Fields, KV>>): ResourceSnapshotSchema<Data, Fields, KV>;
27
28
  /** The most generic type of ResourceSnapshotSchema. */
28
29
  type ResourceSnapshotSchemaGeneric = ResourceSnapshotSchema<ZodType | "raw" | undefined, Record<string, boolean> | undefined, Record<string, ZodType | "raw"> | undefined>;
29
30
  /**
@@ -38,38 +39,35 @@ type InferDataType<Data extends ZodType | "raw" | undefined> = Data extends "raw
38
39
  * If it's false and doesn't exist, we'll return undefined.
39
40
  * If Fields type is undefined, we won't set fields at all.
40
41
  */
41
- type InferFieldsType<Fields extends Record<string, boolean> | undefined> = Fields extends undefined ? undefined : {
42
- [FieldName in keyof Fields]: Fields[FieldName] extends true ? ResourceId : ResourceId | undefined;
43
- };
42
+ type InferFieldsType<Fields extends Record<string, boolean> | undefined> = Fields extends undefined ? undefined : { [FieldName in keyof Fields]: Fields[FieldName] extends true ? ResourceId : ResourceId | undefined };
44
43
  /**
45
44
  * If KV is undefined, won't set it.
46
45
  * If one of values is Zod, we'll get KV and converts it to Zod schema.
47
46
  * If the value is 'raw', just returns bytes.
48
47
  */
49
- type InferKVType<KV extends Record<string, ZodType | "raw"> | undefined> = KV extends undefined ? undefined : {
50
- [FieldName in keyof KV]: KV[FieldName] extends ZodType ? z.infer<KV[FieldName]> : Uint8Array;
51
- };
48
+ type InferKVType<KV extends Record<string, ZodType | "raw"> | undefined> = KV extends undefined ? undefined : { [FieldName in keyof KV]: KV[FieldName] extends ZodType ? z.infer<KV[FieldName]> : Uint8Array };
52
49
  /** Infer ResourceSnapshot from ResourceShapshotSchema, S can be any ResourceSnapshotSchema. */
53
- export type InferSnapshot<S extends ResourceSnapshotSchemaGeneric> = ResourceSnapshot<InferDataType<S["data"]>, InferFieldsType<S["fields"]>, InferKVType<S["kv"]>>;
50
+ type InferSnapshot<S extends ResourceSnapshotSchemaGeneric> = ResourceSnapshot<InferDataType<S["data"]>, InferFieldsType<S["fields"]>, InferKVType<S["kv"]>>;
54
51
  /** Gets a ResourceSnapshot from PlTreeEntry. */
55
- export declare function makeResourceSnapshot<Schema extends ResourceSnapshotSchemaGeneric>(res: PlTreeEntry, schema: Schema, ctx: ComputableCtx): InferSnapshot<Schema>;
56
- export declare function makeResourceSnapshot<Schema extends ResourceSnapshotSchemaGeneric>(res: PlTreeEntryAccessor | PlTreeNodeAccessor, schema: Schema): InferSnapshot<Schema>;
52
+ declare function makeResourceSnapshot<Schema extends ResourceSnapshotSchemaGeneric>(res: PlTreeEntry, schema: Schema, ctx: ComputableCtx): InferSnapshot<Schema>;
53
+ declare function makeResourceSnapshot<Schema extends ResourceSnapshotSchemaGeneric>(res: PlTreeEntryAccessor | PlTreeNodeAccessor, schema: Schema): InferSnapshot<Schema>;
57
54
  /** @deprecated */
58
- export type ResourceWithData = {
59
- readonly id: ResourceId;
60
- readonly type: ResourceType;
61
- readonly fields: Map<string, ResourceId | undefined>;
62
- readonly data?: Uint8Array;
55
+ type ResourceWithData = {
56
+ readonly id: ResourceId;
57
+ readonly type: ResourceType;
58
+ readonly fields: Map<string, ResourceId | undefined>;
59
+ readonly data?: Uint8Array;
63
60
  };
64
61
  /** @deprecated */
65
- export declare function treeEntryToResourceWithData(res: PlTreeEntry | ResourceWithData, fields: string[], ctx: ComputableCtx): ResourceWithData;
62
+ declare function treeEntryToResourceWithData(res: PlTreeEntry | ResourceWithData, fields: string[], ctx: ComputableCtx): ResourceWithData;
66
63
  /** @deprecated */
67
- export type ResourceWithMetadata = {
68
- readonly id: ResourceId;
69
- readonly type: ResourceType;
70
- readonly metadata: Record<string, any>;
64
+ type ResourceWithMetadata = {
65
+ readonly id: ResourceId;
66
+ readonly type: ResourceType;
67
+ readonly metadata: Record<string, any>;
71
68
  };
72
69
  /** @deprecated */
73
- export declare function treeEntryToResourceWithMetadata(res: PlTreeEntry | ResourceWithMetadata, mdKeys: string[], ctx: ComputableCtx): ResourceWithMetadata;
74
- export {};
70
+ declare function treeEntryToResourceWithMetadata(res: PlTreeEntry | ResourceWithMetadata, mdKeys: string[], ctx: ComputableCtx): ResourceWithMetadata;
71
+ //#endregion
72
+ export { InferSnapshot, ResourceSnapshot, ResourceSnapshotSchema, ResourceWithData, ResourceWithMetadata, makeResourceSnapshot, rsSchema, treeEntryToResourceWithData, treeEntryToResourceWithMetadata };
75
73
  //# sourceMappingURL=snapshot.d.ts.map
package/dist/snapshot.js CHANGED
@@ -1,83 +1,63 @@
1
- import { PlTreeEntry, PlTreeEntryAccessor } from './accessors.js';
2
- import { notEmpty } from '@milaboratories/ts-helpers';
1
+ import { PlTreeEntry, PlTreeEntryAccessor } from "./accessors.js";
2
+ import { notEmpty } from "@milaboratories/ts-helpers";
3
3
 
4
+ //#region src/snapshot.ts
4
5
  /** Creates ResourceSnapshotSchema. It converts an optional schema type to schema type. */
5
6
  function rsSchema(schema) {
6
- return schema;
7
+ return schema;
7
8
  }
8
9
  function makeResourceSnapshot(res, schema, ctx) {
9
- const node = res instanceof PlTreeEntry
10
- ? notEmpty(ctx).accessor(res).node()
11
- : res instanceof PlTreeEntryAccessor
12
- ? res.node()
13
- : res;
14
- const info = node.resourceInfo;
15
- const result = { ...info };
16
- if (schema.data !== undefined) {
17
- if (schema.data === "raw")
18
- result.data = node.getData();
19
- else
20
- result.data = schema.data.parse(node.getDataAsJson());
21
- }
22
- if (schema.fields !== undefined) {
23
- const fields = {};
24
- // even if field is not defined, corresponding object field
25
- // with "undefined" value will still be added
26
- for (const [fieldName, required] of Object.entries(schema.fields))
27
- fields[fieldName] = node.traverse({
28
- field: fieldName,
29
- errorIfFieldNotSet: required,
30
- stableIfNotFound: !required,
31
- })?.id;
32
- result.fields = fields;
33
- }
34
- if (schema.kv !== undefined) {
35
- const kv = {};
36
- for (const [fieldName, type] of Object.entries(schema.kv)) {
37
- const value = node.getKeyValue(fieldName);
38
- if (value === undefined) {
39
- throw new Error(`Key not found ${fieldName}`);
40
- }
41
- else if (type === "raw") {
42
- kv[fieldName] = value;
43
- }
44
- else {
45
- kv[fieldName] = type.parse(JSON.parse(Buffer.from(value).toString("utf-8")));
46
- }
47
- }
48
- result.kv = kv;
49
- }
50
- return result;
10
+ const node = res instanceof PlTreeEntry ? notEmpty(ctx).accessor(res).node() : res instanceof PlTreeEntryAccessor ? res.node() : res;
11
+ const result = { ...node.resourceInfo };
12
+ if (schema.data !== void 0) if (schema.data === "raw") result.data = node.getData();
13
+ else result.data = schema.data.parse(node.getDataAsJson());
14
+ if (schema.fields !== void 0) {
15
+ const fields = {};
16
+ for (const [fieldName, required] of Object.entries(schema.fields)) fields[fieldName] = node.traverse({
17
+ field: fieldName,
18
+ errorIfFieldNotSet: required,
19
+ stableIfNotFound: !required
20
+ })?.id;
21
+ result.fields = fields;
22
+ }
23
+ if (schema.kv !== void 0) {
24
+ const kv = {};
25
+ for (const [fieldName, type] of Object.entries(schema.kv)) {
26
+ const value = node.getKeyValue(fieldName);
27
+ if (value === void 0) throw new Error(`Key not found ${fieldName}`);
28
+ else if (type === "raw") kv[fieldName] = value;
29
+ else kv[fieldName] = type.parse(JSON.parse(Buffer.from(value).toString("utf-8")));
30
+ }
31
+ result.kv = kv;
32
+ }
33
+ return result;
51
34
  }
52
35
  /** @deprecated */
53
36
  function treeEntryToResourceWithData(res, fields, ctx) {
54
- if (res instanceof PlTreeEntry) {
55
- const node = ctx.accessor(res).node();
56
- const info = node.resourceInfo;
57
- const fValues = fields.map((name) => [
58
- name,
59
- node.getField(name)?.value?.id,
60
- ]);
61
- return {
62
- ...info,
63
- fields: new Map(fValues),
64
- data: node.getData() ?? new Uint8Array(),
65
- };
66
- }
67
- return res;
37
+ if (res instanceof PlTreeEntry) {
38
+ const node = ctx.accessor(res).node();
39
+ const info = node.resourceInfo;
40
+ const fValues = fields.map((name) => [name, node.getField(name)?.value?.id]);
41
+ return {
42
+ ...info,
43
+ fields: new Map(fValues),
44
+ data: node.getData() ?? new Uint8Array()
45
+ };
46
+ }
47
+ return res;
68
48
  }
69
49
  /** @deprecated */
70
50
  function treeEntryToResourceWithMetadata(res, mdKeys, ctx) {
71
- if (!(res instanceof PlTreeEntry))
72
- return res;
73
- const node = ctx.accessor(res).node();
74
- const info = node.resourceInfo;
75
- const mdEntries = mdKeys.map((k) => [k, node.getKeyValue(k)]);
76
- return {
77
- ...info,
78
- metadata: Object.fromEntries(mdEntries),
79
- };
51
+ if (!(res instanceof PlTreeEntry)) return res;
52
+ const node = ctx.accessor(res).node();
53
+ const info = node.resourceInfo;
54
+ const mdEntries = mdKeys.map((k) => [k, node.getKeyValue(k)]);
55
+ return {
56
+ ...info,
57
+ metadata: Object.fromEntries(mdEntries)
58
+ };
80
59
  }
81
60
 
61
+ //#endregion
82
62
  export { makeResourceSnapshot, rsSchema, treeEntryToResourceWithData, treeEntryToResourceWithMetadata };
83
- //# sourceMappingURL=snapshot.js.map
63
+ //# sourceMappingURL=snapshot.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"snapshot.js","sources":["../src/snapshot.ts"],"sourcesContent":["import type { ResourceId, ResourceType } from \"@milaboratories/pl-client\";\nimport type { Optional, Writable } from \"utility-types\";\nimport type { ZodType, z } from \"zod\";\nimport type { PlTreeNodeAccessor } from \"./accessors\";\nimport { PlTreeEntry, PlTreeEntryAccessor } from \"./accessors\";\nimport type { ComputableCtx } from \"@milaboratories/computable\";\nimport { notEmpty } from \"@milaboratories/ts-helpers\";\n\n/**\n * A DTO that can be generated from a tree node to make a snapshot of specific parts of it's state.\n * Such snapshots can then be used in core that requires this information without the need of\n * retrieving state from the tree.\n */\nexport type ResourceSnapshot<\n Data = undefined,\n Fields extends Record<string, ResourceId | undefined> | undefined = undefined,\n KV extends Record<string, unknown> | undefined = undefined,\n> = {\n readonly id: ResourceId;\n readonly type: ResourceType;\n readonly data: Data;\n readonly fields: Fields;\n readonly kv: KV;\n};\n\n/** The most generic type of ResourceSnapshot. */\ntype ResourceSnapshotGeneric = ResourceSnapshot<\n unknown,\n Record<string, ResourceId | undefined> | undefined,\n Record<string, unknown> | undefined\n>;\n\n/** Request that we'll pass to getResourceSnapshot function. We infer the type of ResourceSnapshot from this. */\nexport type ResourceSnapshotSchema<\n Data extends ZodType | \"raw\" | undefined = undefined,\n Fields extends Record<string, boolean> | undefined = undefined,\n KV extends Record<string, ZodType | \"raw\"> | undefined = undefined,\n> = {\n readonly data: Data;\n readonly fields: Fields;\n readonly kv: KV;\n};\n\n/** Creates ResourceSnapshotSchema. It converts an optional schema type to schema type. */\nexport function rsSchema<\n const Data extends ZodType | \"raw\" | undefined = undefined,\n const Fields extends Record<string, boolean> | undefined = undefined,\n const KV extends Record<string, ZodType | \"raw\"> | undefined = undefined,\n>(\n schema: Optional<ResourceSnapshotSchema<Data, Fields, KV>>,\n): ResourceSnapshotSchema<Data, Fields, KV> {\n return schema as any;\n}\n\n/** The most generic type of ResourceSnapshotSchema. */\ntype ResourceSnapshotSchemaGeneric = ResourceSnapshotSchema<\n ZodType | \"raw\" | undefined,\n Record<string, boolean> | undefined,\n Record<string, ZodType | \"raw\"> | undefined\n>;\n\n/**\n * If Data is 'raw' in schema, we'll get bytes,\n * if it's Zod, we'll parse it via zod.\n * Or else we just got undefined in the field.\n */\ntype InferDataType<Data extends ZodType | \"raw\" | undefined> = Data extends \"raw\"\n ? Uint8Array\n : Data extends ZodType\n ? z.infer<Data>\n : undefined;\n\n/**\n * If Fields is a record of field names to booleans,\n * then if the value of the field is true, we'll require this field and throw a Error if it wasn't found.\n * If it's false and doesn't exist, we'll return undefined.\n * If Fields type is undefined, we won't set fields at all.\n */\ntype InferFieldsType<Fields extends Record<string, boolean> | undefined> = Fields extends undefined\n ? undefined\n : {\n [FieldName in keyof Fields]: Fields[FieldName] extends true\n ? ResourceId\n : ResourceId | undefined;\n };\n\n/**\n * If KV is undefined, won't set it.\n * If one of values is Zod, we'll get KV and converts it to Zod schema.\n * If the value is 'raw', just returns bytes.\n */\ntype InferKVType<KV extends Record<string, ZodType | \"raw\"> | undefined> = KV extends undefined\n ? undefined\n : {\n [FieldName in keyof KV]: KV[FieldName] extends ZodType ? z.infer<KV[FieldName]> : Uint8Array;\n };\n\n/** Infer ResourceSnapshot from ResourceShapshotSchema, S can be any ResourceSnapshotSchema. */\nexport type InferSnapshot<S extends ResourceSnapshotSchemaGeneric> = ResourceSnapshot<\n InferDataType<S[\"data\"]>,\n InferFieldsType<S[\"fields\"]>,\n InferKVType<S[\"kv\"]>\n>;\n\n/** Gets a ResourceSnapshot from PlTreeEntry. */\nexport function makeResourceSnapshot<Schema extends ResourceSnapshotSchemaGeneric>(\n res: PlTreeEntry,\n schema: Schema,\n ctx: ComputableCtx,\n): InferSnapshot<Schema>;\nexport function makeResourceSnapshot<Schema extends ResourceSnapshotSchemaGeneric>(\n res: PlTreeEntryAccessor | PlTreeNodeAccessor,\n schema: Schema,\n): InferSnapshot<Schema>;\nexport function makeResourceSnapshot<Schema extends ResourceSnapshotSchemaGeneric>(\n res: PlTreeEntry | PlTreeEntryAccessor | PlTreeNodeAccessor,\n schema: Schema,\n ctx?: ComputableCtx,\n): InferSnapshot<Schema> {\n const node =\n res instanceof PlTreeEntry\n ? notEmpty(ctx).accessor(res).node()\n : res instanceof PlTreeEntryAccessor\n ? res.node()\n : res;\n const info = node.resourceInfo;\n const result: Optional<Writable<ResourceSnapshotGeneric>, \"data\" | \"fields\" | \"kv\"> = { ...info };\n\n if (schema.data !== undefined) {\n if (schema.data === \"raw\") result.data = node.getData();\n else result.data = schema.data.parse(node.getDataAsJson());\n }\n\n if (schema.fields !== undefined) {\n const fields: Record<string, ResourceId | undefined> = {};\n // even if field is not defined, corresponding object field\n // with \"undefined\" value will still be added\n for (const [fieldName, required] of Object.entries(schema.fields))\n fields[fieldName] = node.traverse({\n field: fieldName,\n errorIfFieldNotSet: required,\n stableIfNotFound: !required,\n })?.id;\n result.fields = fields;\n }\n\n if (schema.kv !== undefined) {\n const kv: Record<string, unknown> = {};\n for (const [fieldName, type] of Object.entries(schema.kv)) {\n const value = node.getKeyValue(fieldName);\n\n if (value === undefined) {\n throw new Error(`Key not found ${fieldName}`);\n } else if (type === \"raw\") {\n kv[fieldName] = value;\n } else {\n kv[fieldName] = type.parse(JSON.parse(Buffer.from(value).toString(\"utf-8\")));\n }\n }\n result.kv = kv;\n }\n\n return result as any;\n}\n\n/** @deprecated */\nexport type ResourceWithData = {\n readonly id: ResourceId;\n readonly type: ResourceType;\n readonly fields: Map<string, ResourceId | undefined>;\n readonly data?: Uint8Array;\n};\n\n/** @deprecated */\nexport function treeEntryToResourceWithData(\n res: PlTreeEntry | ResourceWithData,\n fields: string[],\n ctx: ComputableCtx,\n): ResourceWithData {\n if (res instanceof PlTreeEntry) {\n const node = ctx.accessor(res).node();\n const info = node.resourceInfo;\n\n const fValues: [string, ResourceId | undefined][] = fields.map((name) => [\n name,\n node.getField(name)?.value?.id,\n ]);\n\n return {\n ...info,\n fields: new Map(fValues),\n data: node.getData() ?? new Uint8Array(),\n };\n }\n\n return res;\n}\n\n/** @deprecated */\nexport type ResourceWithMetadata = {\n readonly id: ResourceId;\n readonly type: ResourceType;\n readonly metadata: Record<string, any>;\n};\n\n/** @deprecated */\nexport function treeEntryToResourceWithMetadata(\n res: PlTreeEntry | ResourceWithMetadata,\n mdKeys: string[],\n ctx: ComputableCtx,\n): ResourceWithMetadata {\n if (!(res instanceof PlTreeEntry)) return res;\n\n const node = ctx.accessor(res).node();\n const info = node.resourceInfo;\n const mdEntries: [string, any][] = mdKeys.map((k) => [k, node.getKeyValue(k)]);\n\n return {\n ...info,\n metadata: Object.fromEntries(mdEntries),\n };\n}\n"],"names":[],"mappings":";;;AA2CA;AACM,SAAU,QAAQ,CAKtB,MAA0D,EAAA;AAE1D,IAAA,OAAO,MAAa;AACtB;SA8DgB,oBAAoB,CAClC,GAA2D,EAC3D,MAAc,EACd,GAAmB,EAAA;AAEnB,IAAA,MAAM,IAAI,GACR,GAAG,YAAY;AACb,UAAE,QAAQ,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,IAAI;UAChC,GAAG,YAAY;AACf,cAAE,GAAG,CAAC,IAAI;cACR,GAAG;AACX,IAAA,MAAM,IAAI,GAAG,IAAI,CAAC,YAAY;AAC9B,IAAA,MAAM,MAAM,GAA0E,EAAE,GAAG,IAAI,EAAE;AAEjG,IAAA,IAAI,MAAM,CAAC,IAAI,KAAK,SAAS,EAAE;AAC7B,QAAA,IAAI,MAAM,CAAC,IAAI,KAAK,KAAK;AAAE,YAAA,MAAM,CAAC,IAAI,GAAG,IAAI,CAAC,OAAO,EAAE;;AAClD,YAAA,MAAM,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,aAAa,EAAE,CAAC;IAC5D;AAEA,IAAA,IAAI,MAAM,CAAC,MAAM,KAAK,SAAS,EAAE;QAC/B,MAAM,MAAM,GAA2C,EAAE;;;AAGzD,QAAA,KAAK,MAAM,CAAC,SAAS,EAAE,QAAQ,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM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,YAAY;QAE9B,MAAM,OAAO,GAAuC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,KAAK;YACvE,IAAI;YACJ,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,EAAE;AAC/B,SAAA,CAAC;QAEF,OAAO;AACL,YAAA,GAAG,IAAI;AACP,YAAA,MAAM,EAAE,IAAI,GAAG,CAAC,OAAO,CAAC;YACxB,IAAI,EAAE,IAAI,CAAC,OAAO,EAAE,IAAI,IAAI,UAAU,EAAE;SACzC;IACH;AAEA,IAAA,OAAO,GAAG;AACZ;AASA;SACgB,+BAA+B,CAC7C,GAAuC,EACvC,MAAgB,EAChB,GAAkB,EAAA;AAElB,IAAA,IAAI,EAAE,GAAG,YAAY,WAAW,CAAC;AAAE,QAAA,OAAO,GAAG;IAE7C,MAAM,IAAI,GAAG,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE;AACrC,IAAA,MAAM,IAAI,GAAG,IAAI,CAAC,YAAY;IAC9B,MAAM,SAAS,GAAoB,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;IAE9E,OAAO;AACL,QAAA,GAAG,IAAI;AACP,QAAA,QAAQ,EAAE,MAAM,CAAC,WAAW,CAAC,SAAS,CAAC;KACxC;AACH;;;;"}
1
+ {"version":3,"file":"snapshot.js","names":[],"sources":["../src/snapshot.ts"],"sourcesContent":["import type { ResourceId, ResourceType } from \"@milaboratories/pl-client\";\nimport type { Optional, Writable } from \"utility-types\";\nimport type { ZodType, z } from \"zod\";\nimport type { PlTreeNodeAccessor } from \"./accessors\";\nimport { PlTreeEntry, PlTreeEntryAccessor } from \"./accessors\";\nimport type { ComputableCtx } from \"@milaboratories/computable\";\nimport { notEmpty } from \"@milaboratories/ts-helpers\";\n\n/**\n * A DTO that can be generated from a tree node to make a snapshot of specific parts of it's state.\n * Such snapshots can then be used in core that requires this information without the need of\n * retrieving state from the tree.\n */\nexport type ResourceSnapshot<\n Data = undefined,\n Fields extends Record<string, ResourceId | undefined> | undefined = undefined,\n KV extends Record<string, unknown> | undefined = undefined,\n> = {\n readonly id: ResourceId;\n readonly type: ResourceType;\n readonly data: Data;\n readonly fields: Fields;\n readonly kv: KV;\n};\n\n/** The most generic type of ResourceSnapshot. */\ntype ResourceSnapshotGeneric = ResourceSnapshot<\n unknown,\n Record<string, ResourceId | undefined> | undefined,\n Record<string, unknown> | undefined\n>;\n\n/** Request that we'll pass to getResourceSnapshot function. We infer the type of ResourceSnapshot from this. */\nexport type ResourceSnapshotSchema<\n Data extends ZodType | \"raw\" | undefined = undefined,\n Fields extends Record<string, boolean> | undefined = undefined,\n KV extends Record<string, ZodType | \"raw\"> | undefined = undefined,\n> = {\n readonly data: Data;\n readonly fields: Fields;\n readonly kv: KV;\n};\n\n/** Creates ResourceSnapshotSchema. It converts an optional schema type to schema type. */\nexport function rsSchema<\n const Data extends ZodType | \"raw\" | undefined = undefined,\n const Fields extends Record<string, boolean> | undefined = undefined,\n const KV extends Record<string, ZodType | \"raw\"> | undefined = undefined,\n>(\n schema: Optional<ResourceSnapshotSchema<Data, Fields, KV>>,\n): ResourceSnapshotSchema<Data, Fields, KV> {\n return schema as any;\n}\n\n/** The most generic type of ResourceSnapshotSchema. */\ntype ResourceSnapshotSchemaGeneric = ResourceSnapshotSchema<\n ZodType | \"raw\" | undefined,\n Record<string, boolean> | undefined,\n Record<string, ZodType | \"raw\"> | undefined\n>;\n\n/**\n * If Data is 'raw' in schema, we'll get bytes,\n * if it's Zod, we'll parse it via zod.\n * Or else we just got undefined in the field.\n */\ntype InferDataType<Data extends ZodType | \"raw\" | undefined> = Data extends \"raw\"\n ? Uint8Array\n : Data extends ZodType\n ? z.infer<Data>\n : undefined;\n\n/**\n * If Fields is a record of field names to booleans,\n * then if the value of the field is true, we'll require this field and throw a Error if it wasn't found.\n * If it's false and doesn't exist, we'll return undefined.\n * If Fields type is undefined, we won't set fields at all.\n */\ntype InferFieldsType<Fields extends Record<string, boolean> | undefined> = Fields extends undefined\n ? undefined\n : {\n [FieldName in keyof Fields]: Fields[FieldName] extends true\n ? ResourceId\n : ResourceId | undefined;\n };\n\n/**\n * If KV is undefined, won't set it.\n * If one of values is Zod, we'll get KV and converts it to Zod schema.\n * If the value is 'raw', just returns bytes.\n */\ntype InferKVType<KV extends Record<string, ZodType | \"raw\"> | undefined> = KV extends undefined\n ? undefined\n : {\n [FieldName in keyof KV]: KV[FieldName] extends ZodType ? z.infer<KV[FieldName]> : Uint8Array;\n };\n\n/** Infer ResourceSnapshot from ResourceShapshotSchema, S can be any ResourceSnapshotSchema. */\nexport type InferSnapshot<S extends ResourceSnapshotSchemaGeneric> = ResourceSnapshot<\n InferDataType<S[\"data\"]>,\n InferFieldsType<S[\"fields\"]>,\n InferKVType<S[\"kv\"]>\n>;\n\n/** Gets a ResourceSnapshot from PlTreeEntry. */\nexport function makeResourceSnapshot<Schema extends ResourceSnapshotSchemaGeneric>(\n res: PlTreeEntry,\n schema: Schema,\n ctx: ComputableCtx,\n): InferSnapshot<Schema>;\nexport function makeResourceSnapshot<Schema extends ResourceSnapshotSchemaGeneric>(\n res: PlTreeEntryAccessor | PlTreeNodeAccessor,\n schema: Schema,\n): InferSnapshot<Schema>;\nexport function makeResourceSnapshot<Schema extends ResourceSnapshotSchemaGeneric>(\n res: PlTreeEntry | PlTreeEntryAccessor | PlTreeNodeAccessor,\n schema: Schema,\n ctx?: ComputableCtx,\n): InferSnapshot<Schema> {\n const node =\n res instanceof PlTreeEntry\n ? notEmpty(ctx).accessor(res).node()\n : res instanceof PlTreeEntryAccessor\n ? res.node()\n : res;\n const info = node.resourceInfo;\n const result: Optional<Writable<ResourceSnapshotGeneric>, \"data\" | \"fields\" | \"kv\"> = { ...info };\n\n if (schema.data !== undefined) {\n if (schema.data === \"raw\") result.data = node.getData();\n else result.data = schema.data.parse(node.getDataAsJson());\n }\n\n if (schema.fields !== undefined) {\n const fields: Record<string, ResourceId | undefined> = {};\n // even if field is not defined, corresponding object field\n // with \"undefined\" value will still be added\n for (const [fieldName, required] of Object.entries(schema.fields))\n fields[fieldName] = node.traverse({\n field: fieldName,\n errorIfFieldNotSet: required,\n stableIfNotFound: !required,\n })?.id;\n result.fields = fields;\n }\n\n if (schema.kv !== undefined) {\n const kv: Record<string, unknown> = {};\n for (const [fieldName, type] of Object.entries(schema.kv)) {\n const value = node.getKeyValue(fieldName);\n\n if (value === undefined) {\n throw new Error(`Key not found ${fieldName}`);\n } else if (type === \"raw\") {\n kv[fieldName] = value;\n } else {\n kv[fieldName] = type.parse(JSON.parse(Buffer.from(value).toString(\"utf-8\")));\n }\n }\n result.kv = kv;\n }\n\n return result as any;\n}\n\n/** @deprecated */\nexport type ResourceWithData = {\n readonly id: ResourceId;\n readonly type: ResourceType;\n readonly fields: Map<string, ResourceId | undefined>;\n readonly data?: Uint8Array;\n};\n\n/** @deprecated */\nexport function treeEntryToResourceWithData(\n res: PlTreeEntry | ResourceWithData,\n fields: string[],\n ctx: ComputableCtx,\n): ResourceWithData {\n if (res instanceof PlTreeEntry) {\n const node = ctx.accessor(res).node();\n const info = node.resourceInfo;\n\n const fValues: [string, ResourceId | undefined][] = fields.map((name) => [\n name,\n node.getField(name)?.value?.id,\n ]);\n\n return {\n ...info,\n fields: new Map(fValues),\n data: node.getData() ?? new Uint8Array(),\n };\n }\n\n return res;\n}\n\n/** @deprecated */\nexport type ResourceWithMetadata = {\n readonly id: ResourceId;\n readonly type: ResourceType;\n readonly metadata: Record<string, any>;\n};\n\n/** @deprecated */\nexport function treeEntryToResourceWithMetadata(\n res: PlTreeEntry | ResourceWithMetadata,\n mdKeys: string[],\n ctx: ComputableCtx,\n): ResourceWithMetadata {\n if (!(res instanceof PlTreeEntry)) return res;\n\n const node = ctx.accessor(res).node();\n const info = node.resourceInfo;\n const mdEntries: [string, any][] = mdKeys.map((k) => [k, node.getKeyValue(k)]);\n\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