@milaboratories/pl-tree 1.7.5 → 1.7.7
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/accessors.cjs +297 -0
- package/dist/accessors.cjs.map +1 -0
- package/dist/accessors.d.ts +6 -6
- package/dist/accessors.js +288 -0
- package/dist/accessors.js.map +1 -0
- package/dist/dump.cjs +86 -0
- package/dist/dump.cjs.map +1 -0
- package/dist/dump.d.ts +1 -1
- package/dist/dump.js +84 -0
- package/dist/dump.js.map +1 -0
- package/dist/index.cjs +36 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.js +7 -10
- package/dist/index.js.map +1 -1
- package/dist/snapshot.cjs +88 -0
- package/dist/snapshot.cjs.map +1 -0
- package/dist/snapshot.d.ts +6 -5
- package/dist/snapshot.js +83 -0
- package/dist/snapshot.js.map +1 -0
- package/dist/state.cjs +631 -0
- package/dist/state.cjs.map +1 -0
- package/dist/state.d.ts +7 -5
- package/dist/state.js +627 -0
- package/dist/state.js.map +1 -0
- package/dist/sync.cjs +156 -0
- package/dist/sync.cjs.map +1 -0
- package/dist/sync.d.ts +2 -2
- package/dist/sync.js +151 -0
- package/dist/sync.js.map +1 -0
- package/dist/synchronized_tree.cjs +235 -0
- package/dist/synchronized_tree.cjs.map +1 -0
- package/dist/synchronized_tree.d.ts +4 -4
- package/dist/synchronized_tree.js +214 -0
- package/dist/synchronized_tree.js.map +1 -0
- package/dist/test_utils.d.ts +2 -2
- package/dist/traversal_ops.d.ts +1 -1
- package/dist/value_and_error.cjs +20 -0
- package/dist/value_and_error.cjs.map +1 -0
- package/dist/value_and_error.js +17 -0
- package/dist/value_and_error.js.map +1 -0
- package/package.json +16 -14
- package/src/snapshot.test.ts +4 -3
- package/src/state.test.ts +6 -4
- package/dist/index.mjs +0 -904
- package/dist/index.mjs.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"accessors.js","sources":["../src/accessors.ts"],"sourcesContent":["import type { PlTreeResource, PlTreeState } from './state';\nimport type {\n AccessorProvider,\n ComputableCtx,\n ComputableHooks,\n UsageGuard,\n} from '@milaboratories/computable';\nimport type {\n ResourceId,\n ResourceType,\n OptionalResourceId } from '@milaboratories/pl-client';\nimport {\n resourceIdToString,\n resourceTypesEqual,\n resourceTypeToString,\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n NullResourceId,\n} from '@milaboratories/pl-client';\nimport type { ValueAndError } from './value_and_error';\nimport { mapValueAndError } from './value_and_error';\nimport type {\n CommonFieldTraverseOps,\n FieldTraversalStep,\n GetFieldStep,\n ResourceTraversalOps,\n} from './traversal_ops';\nimport type { ValueOrError } from './value_or_error';\nimport { parsePlError } from '@milaboratories/pl-errors';\nimport { notEmpty } from '@milaboratories/ts-helpers';\n/** Error encountered during traversal in field or resource. */\nexport class PlError extends Error {\n constructor(message: string) {\n super(message);\n }\n}\n\nexport type TreeAccessorData = {\n readonly treeProvider: () => PlTreeState;\n readonly hooks?: ComputableHooks;\n};\n\nexport type TreeAccessorInstanceData = {\n readonly guard: UsageGuard;\n readonly ctx: ComputableCtx;\n};\n\nexport function isPlTreeEntry(obj: unknown): obj is PlTreeEntry {\n return (\n typeof obj === 'object'\n && obj !== null\n && (obj as any)['__pl_tree_type_marker__'] === 'PlTreeEntry'\n );\n}\n\nexport function isPlTreeEntryAccessor(obj: unknown): obj is PlTreeEntryAccessor {\n return (\n typeof obj === 'object'\n && obj !== null\n && (obj as any)['__pl_tree_type_marker__'] === 'PlTreeEntryAccessor'\n );\n}\n\nexport function isPlTreeNodeAccessor(obj: unknown): obj is PlTreeNodeAccessor {\n return (\n typeof obj === 'object'\n && obj !== null\n && (obj as any)['__pl_tree_type_marker__'] === 'PlTreeNodeAccessor'\n );\n}\n\n/** Main entry point for using PlTree in reactive setting */\nexport class PlTreeEntry implements AccessorProvider<PlTreeEntryAccessor> {\n private readonly __pl_tree_type_marker__ = 'PlTreeEntry';\n\n constructor(\n private readonly accessorData: TreeAccessorData,\n public readonly rid: ResourceId,\n ) {}\n\n public createAccessor(ctx: ComputableCtx, guard: UsageGuard): PlTreeEntryAccessor {\n return new PlTreeEntryAccessor(this.accessorData, this.accessorData.treeProvider(), this.rid, {\n ctx,\n guard,\n });\n }\n\n public toJSON(): string {\n return this.toString();\n }\n\n public toString(): string {\n return `[ENTRY:${resourceIdToString(this.rid)}]`;\n }\n}\n\nfunction getResourceFromTree(\n accessorData: TreeAccessorData,\n tree: PlTreeState,\n instanceData: TreeAccessorInstanceData,\n rid: ResourceId,\n ops: ResourceTraversalOps,\n): PlTreeNodeAccessor {\n const acc = new PlTreeNodeAccessor(\n accessorData,\n tree,\n tree.get(instanceData.ctx.watcher, rid),\n instanceData,\n );\n\n if (!ops.ignoreError) {\n const err = acc.getError();\n if (err !== undefined)\n throw parsePlError(notEmpty(err.getDataAsString()), acc.id, acc.resourceType);\n }\n\n if (\n ops.assertResourceType !== undefined\n && (Array.isArray(ops.assertResourceType)\n ? ops.assertResourceType.findIndex((rt) => resourceTypesEqual(rt, acc.resourceType)) === -1\n : !resourceTypesEqual(ops.assertResourceType, acc.resourceType))\n )\n throw new Error(\n // eslint-disable-next-line @typescript-eslint/no-base-to-string\n `wrong resource type ${resourceTypeToString(acc.resourceType)} but expected ${ops.assertResourceType}`,\n );\n\n return acc;\n}\n\nexport class PlTreeEntryAccessor {\n private readonly __pl_tree_type_marker__ = 'PlTreeEntryAccessor';\n\n constructor(\n private readonly accessorData: TreeAccessorData,\n private readonly tree: PlTreeState,\n private readonly rid: ResourceId,\n private readonly instanceData: TreeAccessorInstanceData,\n ) {}\n\n node(ops: ResourceTraversalOps = {}): PlTreeNodeAccessor {\n this.instanceData.guard();\n\n // this is the only entry point to acquire a PlTreeNodeAccessor,\n // so this is the only point where we should attach the hooks\n if (this.accessorData.hooks !== undefined)\n this.instanceData.ctx.attacheHooks(this.accessorData.hooks);\n\n return getResourceFromTree(this.accessorData, this.tree, this.instanceData, this.rid, ops);\n }\n}\n\n/**\n * Helper type to simplify implementation of APIs requiring type information.\n * */\nexport type ResourceInfo = {\n readonly id: ResourceId;\n readonly type: ResourceType;\n};\n\n/**\n * Can be called only when a ctx is provided, because pl tree entry is a computable entity.\n * @deprecated\n * */\nexport function treeEntryToResourceInfo(res: PlTreeEntry | ResourceInfo, ctx: ComputableCtx) {\n if (res instanceof PlTreeEntry) return ctx.accessor(res).node().resourceInfo;\n\n return res;\n}\n\n/**\n * API contracts:\n * - API never return {@link NullResourceId}, absence of link is always modeled as `undefined`\n *\n * Important: never store instances of this class, always get fresh instance from {@link PlTreeState} accessor.\n * */\nexport class PlTreeNodeAccessor {\n private readonly __pl_tree_type_marker__ = 'PlTreeNodeAccessor';\n\n constructor(\n private readonly accessorData: TreeAccessorData,\n private readonly tree: PlTreeState,\n private readonly resource: PlTreeResource,\n private readonly instanceData: TreeAccessorInstanceData,\n ) {}\n\n public get id(): ResourceId {\n this.instanceData.guard();\n return this.resource.id;\n }\n\n public get originalId(): OptionalResourceId {\n this.instanceData.guard();\n return this.resource.originalResourceId;\n }\n\n public get resourceType(): ResourceType {\n this.instanceData.guard();\n return this.resource.type;\n }\n\n public get resourceInfo(): ResourceInfo {\n return { id: this.id, type: this.resourceType };\n }\n\n private getResourceFromTree(rid: ResourceId, ops: ResourceTraversalOps): PlTreeNodeAccessor {\n return getResourceFromTree(this.accessorData, this.tree, this.instanceData, rid, ops);\n }\n\n public traverse(\n ...steps: [\n Omit<FieldTraversalStep, 'errorIfFieldNotSet'> & {\n errorIfFieldNotSet: true;\n },\n ]\n ): PlTreeNodeAccessor;\n public traverse(...steps: (FieldTraversalStep | string)[]): PlTreeNodeAccessor | undefined;\n public traverse(...steps: (FieldTraversalStep | string)[]): PlTreeNodeAccessor | undefined {\n return this.traverseWithCommon({}, ...steps);\n }\n\n public traverseOrError(\n ...steps: [\n Omit<FieldTraversalStep, 'errorIfFieldNotSet'> & {\n errorIfFieldNotSet: true;\n },\n ]\n ): ValueOrError<PlTreeNodeAccessor, Error>;\n public traverseOrError(\n ...steps: (FieldTraversalStep | string)[]\n ): ValueOrError<PlTreeNodeAccessor, Error> | undefined;\n public traverseOrError(\n ...steps: (FieldTraversalStep | string)[]\n ): ValueOrError<PlTreeNodeAccessor, Error> | undefined {\n return this.traverseOrErrorWithCommon({}, ...steps);\n }\n\n public traverseWithCommon(\n commonOptions: CommonFieldTraverseOps,\n ...steps: (FieldTraversalStep | string)[]\n ): PlTreeNodeAccessor | undefined {\n const result = this.traverseOrErrorWithCommon(commonOptions, ...steps);\n if (result === undefined) return undefined;\n\n if (!result.ok) throw result.error;\n return result.value;\n }\n\n public traverseOrErrorWithCommon(\n commonOptions: CommonFieldTraverseOps,\n ...steps: (FieldTraversalStep | string)[]\n ): ValueOrError<PlTreeNodeAccessor, Error> | undefined {\n // eslint-disable-next-line @typescript-eslint/no-this-alias\n let current: PlTreeNodeAccessor = this;\n\n for (const _step of steps) {\n const step: FieldTraversalStep\n = typeof _step === 'string'\n ? {\n ...commonOptions,\n field: _step,\n }\n : { ...commonOptions, ..._step };\n\n const next = current.getField(_step);\n\n if (next === undefined) return undefined;\n\n if (step.pureFieldErrorToUndefined && next.value === undefined && next.error !== undefined)\n return undefined;\n\n if ((!step.ignoreError || next.value === undefined) && next.error !== undefined)\n return {\n ok: false,\n\n // FIXME: in next tickets we'll allow Errors to be thrown.\n error: parsePlError(\n notEmpty(next.error.getDataAsString()),\n current.id, current.resourceType, step.field,\n ),\n };\n\n if (next.value === undefined) {\n if (step.errorIfFieldNotSet)\n return {\n ok: false,\n error: new Error(`field have no assigned value ${step.field} of ${resourceIdToString(current.id)}`),\n };\n // existing but unpopulated field is unstable because it must be resolved at some point\n this.onUnstableLambda('unpopulated_field:' + step.field);\n return undefined;\n }\n\n current = next.value;\n }\n return { ok: true, value: current };\n }\n\n private readonly onUnstableLambda = (marker: string) => {\n this.instanceData.ctx.markUnstable(marker);\n };\n\n public getField(\n _step:\n | (Omit<GetFieldStep, 'errorIfFieldNotFound'> & { errorIfFieldNotFound: true })\n | (Omit<GetFieldStep, 'errorIfFieldNotSet'> & { errorIfFieldNotSet: true })\n ): ValueAndError<PlTreeNodeAccessor>;\n public getField(_step: GetFieldStep | string): ValueAndError<PlTreeNodeAccessor> | undefined;\n public getField(_step: GetFieldStep | string): ValueAndError<PlTreeNodeAccessor> | undefined {\n this.instanceData.guard();\n const step: GetFieldStep = typeof _step === 'string' ? { field: _step } : _step;\n\n const ve = this.resource.getField(this.instanceData.ctx.watcher, step, this.onUnstableLambda);\n\n if (ve === undefined) return undefined;\n\n return mapValueAndError(ve, (rid) => this.getResourceFromTree(rid, { ignoreError: true }));\n }\n\n public getInputsLocked(): boolean {\n this.instanceData.guard();\n const result = this.resource.getInputsLocked(this.instanceData.ctx.watcher);\n if (!result) this.instanceData.ctx.markUnstable('inputs_unlocked:' + this.resourceType.name);\n return result;\n }\n\n public getOutputsLocked(): boolean {\n this.instanceData.guard();\n const result = this.resource.getOutputsLocked(this.instanceData.ctx.watcher);\n if (!result) this.instanceData.ctx.markUnstable('outputs_unlocked:' + this.resourceType.name);\n return result;\n }\n\n public getIsReadyOrError(): boolean {\n this.instanceData.guard();\n const result = this.resource.getIsReadyOrError(this.instanceData.ctx.watcher);\n if (!result) this.instanceData.ctx.markUnstable('not_ready:' + this.resourceType.name);\n return result;\n }\n\n public getIsFinal() {\n this.instanceData.guard();\n return this.resource.getIsFinal(this.instanceData.ctx.watcher);\n }\n\n public getError(): PlTreeNodeAccessor | undefined {\n this.instanceData.guard();\n const rid = this.resource.getError(this.instanceData.ctx.watcher);\n if (rid === undefined)\n // absence of error always considered as stable\n return undefined;\n return this.getResourceFromTree(rid, {});\n }\n\n public getData(): Uint8Array | undefined {\n return this.resource.data;\n }\n\n public getDataAsString(): string | undefined {\n return this.resource.getDataAsString();\n }\n\n public getDataAsJson<T = unknown>(): T | undefined {\n return this.resource.getDataAsJson<T>();\n }\n\n public listInputFields(): string[] {\n this.instanceData.guard();\n this.getInputsLocked(); // will set unstable if not locked\n return this.resource.listInputFields(this.instanceData.ctx.watcher);\n }\n\n public listOutputFields(): string[] {\n this.instanceData.guard();\n this.getOutputsLocked(); // will set unstable if not locked\n return this.resource.listOutputFields(this.instanceData.ctx.watcher);\n }\n\n public listDynamicFields(): string[] {\n this.instanceData.guard();\n return this.resource.listDynamicFields(this.instanceData.ctx.watcher);\n }\n\n public getKeyValue(key: string, unstableIfNotFound: boolean = false): Uint8Array | undefined {\n this.instanceData.guard();\n const result = this.resource.getKeyValue(this.instanceData.ctx.watcher, key);\n if (result === undefined && unstableIfNotFound)\n this.instanceData.ctx.markUnstable('key_not_found_b:' + key);\n return result;\n }\n\n /** @deprecated */\n public getKeyValueString(key: string): string | undefined {\n return this.getKeyValueAsString(key);\n }\n\n public getKeyValueAsString(key: string, unstableIfNotFound: boolean = false): string | undefined {\n this.instanceData.guard();\n const result = this.resource.getKeyValueString(this.instanceData.ctx.watcher, key);\n if (result === undefined && unstableIfNotFound)\n this.instanceData.ctx.markUnstable('key_not_found_s:' + key);\n return result;\n }\n\n public getKeyValueAsJson<T = unknown>(\n key: string,\n unstableIfNotFound: boolean = false,\n ): T | undefined {\n const result = this.resource.getKeyValueAsJson<T>(this.instanceData.ctx.watcher, key);\n if (result === undefined) {\n if (unstableIfNotFound) this.instanceData.ctx.markUnstable('key_not_found_j:' + key);\n return undefined;\n }\n return result;\n }\n\n /**\n * Can be used to pass a higher level accessor that will wrap the resource and throw its\n * errors on node resolution.\n * */\n public toEntryAccessor(): PlTreeEntryAccessor {\n return new PlTreeEntryAccessor(this.accessorData, this.tree, this.id, this.instanceData);\n }\n\n /** Can be passed to nested computable. */\n public persist(): PlTreeEntry {\n return new PlTreeEntry(this.accessorData, this.resource.id);\n }\n}\n"],"names":[],"mappings":";;;;;AA6BA;AACM,MAAO,OAAQ,SAAQ,KAAK,CAAA;AAChC,IAAA,WAAA,CAAY,OAAe,EAAA;QACzB,KAAK,CAAC,OAAO,CAAC;IAChB;AACD;AAYK,SAAU,aAAa,CAAC,GAAY,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AAC;AAClF,QAAA,IAAI,MAAM,KAAK,SAAS,IAAI,kBAAkB;YAC5C,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,YAAY,CAAC,kBAAkB,GAAG,GAAG,CAAC;AAC9D,QAAA,OAAO,MAAM;IACf;AAEO,IAAA,iBAAiB,CACtB,GAAW,EACX,kBAAA,GAA8B,KAAK,EAAA;AAEnC,QAAA,MAAM,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAC,iBAAiB,CAAI,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,OAAO,EAAE,GAAG,CAAC;AACrF,QAAA,IAAI,MAAM,KAAK,SAAS,EAAE;AACxB,YAAA,IAAI,kBAAkB;gBAAE,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,YAAY,CAAC,kBAAkB,GAAG,GAAG,CAAC;AACpF,YAAA,OAAO,SAAS;QAClB;AACA,QAAA,OAAO,MAAM;IACf;AAEA;;;AAGK;IACE,eAAe,GAAA;AACpB,QAAA,OAAO,IAAI,mBAAmB,CAAC,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,EAAE,IAAI,CAAC,YAAY,CAAC;IAC1F;;IAGO,OAAO,GAAA;AACZ,QAAA,OAAO,IAAI,WAAW,CAAC,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC;IAC7D;AACD;;;;"}
|
package/dist/dump.cjs
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Analyzes a collection of resources and generates statistics grouped by resource type.
|
|
5
|
+
*
|
|
6
|
+
* This function processes an array of ExtendedResourceData and calculates various metrics
|
|
7
|
+
* for each unique resource type, including:
|
|
8
|
+
* - Count of resources
|
|
9
|
+
* - Total bytes in field names
|
|
10
|
+
* - Total number of fields
|
|
11
|
+
* - Total bytes in resource data
|
|
12
|
+
* - Total number of key-value records
|
|
13
|
+
* - Total bytes in key-value records
|
|
14
|
+
*
|
|
15
|
+
* The statistics are organized by resource type using a key in the format "typeName/version".
|
|
16
|
+
*
|
|
17
|
+
* @param dumpStats - Array of ExtendedResourceData objects to analyze
|
|
18
|
+
* @returns A DumpStats object containing statistics for each resource type
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* const resources = [...]; // Array of ExtendedResourceData
|
|
22
|
+
* const stats = treeDumpStats(resources);
|
|
23
|
+
* // stats = {
|
|
24
|
+
* // "MyResource/1": {
|
|
25
|
+
* // count: 5,
|
|
26
|
+
* // fieldNameBytes: 150,
|
|
27
|
+
* // fieldsCount: 10,
|
|
28
|
+
* // dataBytes: 1024,
|
|
29
|
+
* // kvCount: 3,
|
|
30
|
+
* // kvBytes: 256
|
|
31
|
+
* // },
|
|
32
|
+
* // ...
|
|
33
|
+
* // }
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
function treeDumpStats(dumpStats) {
|
|
37
|
+
const stats = {
|
|
38
|
+
total: {
|
|
39
|
+
count: 0,
|
|
40
|
+
fieldNameBytes: 0,
|
|
41
|
+
fieldsCount: 0,
|
|
42
|
+
dataBytes: 0,
|
|
43
|
+
kvCount: 0,
|
|
44
|
+
kvBytes: 0,
|
|
45
|
+
},
|
|
46
|
+
byResourceType: {},
|
|
47
|
+
};
|
|
48
|
+
for (const resource of dumpStats) {
|
|
49
|
+
const typeKey = `${resource.type.name}/${resource.type.version}`;
|
|
50
|
+
if (!stats.byResourceType[typeKey]) {
|
|
51
|
+
stats.byResourceType[typeKey] = {
|
|
52
|
+
count: 0,
|
|
53
|
+
fieldNameBytes: 0,
|
|
54
|
+
fieldsCount: 0,
|
|
55
|
+
dataBytes: 0,
|
|
56
|
+
kvCount: 0,
|
|
57
|
+
kvBytes: 0,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
const typeStats = stats.byResourceType[typeKey];
|
|
61
|
+
typeStats.count++;
|
|
62
|
+
stats.total.count++;
|
|
63
|
+
for (const field of resource.fields) {
|
|
64
|
+
typeStats.fieldNameBytes += field.name.length;
|
|
65
|
+
typeStats.fieldsCount++;
|
|
66
|
+
stats.total.fieldNameBytes += field.name.length;
|
|
67
|
+
stats.total.fieldsCount++;
|
|
68
|
+
}
|
|
69
|
+
if (resource.data) {
|
|
70
|
+
const dataLength = resource.data?.length ?? 0;
|
|
71
|
+
typeStats.dataBytes += dataLength;
|
|
72
|
+
stats.total.dataBytes += dataLength;
|
|
73
|
+
}
|
|
74
|
+
typeStats.kvCount += resource.kv.length;
|
|
75
|
+
stats.total.kvCount += resource.kv.length;
|
|
76
|
+
for (const kv of resource.kv) {
|
|
77
|
+
const kvLength = kv.key.length + kv.value.length;
|
|
78
|
+
typeStats.kvBytes += kvLength;
|
|
79
|
+
stats.total.kvBytes += kvLength;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return stats;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
exports.treeDumpStats = treeDumpStats;
|
|
86
|
+
//# sourceMappingURL=dump.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dump.cjs","sources":["../src/dump.ts"],"sourcesContent":["import type { ExtendedResourceData } from './state';\n\nexport type ResourceStats = {\n /** Number of resources of this type */\n count: number;\n /** Total number of bytes in the field names of all resources of this type */\n fieldNameBytes: number;\n /** Total number of fields in all resources of this type */\n fieldsCount: number;\n /** Total number of bytes in the data of all resources of this type */\n dataBytes: number;\n /** Total number of key-value records in all resources of this type */\n kvCount: number;\n /** Total number of bytes in the key-value records of all resources of this type */\n kvBytes: number;\n};\n\n/**\n * A map of resource type statistics, keyed by the resource type name and version.\n *\n * @type {Record<string, ResourceStats>}\n */\nexport type TreeDumpStats = {\n total: ResourceStats;\n byResourceType: Record<`${string}/${string}`, ResourceStats>;\n};\n\n/**\n * Analyzes a collection of resources and generates statistics grouped by resource type.\n *\n * This function processes an array of ExtendedResourceData and calculates various metrics\n * for each unique resource type, including:\n * - Count of resources\n * - Total bytes in field names\n * - Total number of fields\n * - Total bytes in resource data\n * - Total number of key-value records\n * - Total bytes in key-value records\n *\n * The statistics are organized by resource type using a key in the format \"typeName/version\".\n *\n * @param dumpStats - Array of ExtendedResourceData objects to analyze\n * @returns A DumpStats object containing statistics for each resource type\n * @example\n * ```typescript\n * const resources = [...]; // Array of ExtendedResourceData\n * const stats = treeDumpStats(resources);\n * // stats = {\n * // \"MyResource/1\": {\n * // count: 5,\n * // fieldNameBytes: 150,\n * // fieldsCount: 10,\n * // dataBytes: 1024,\n * // kvCount: 3,\n * // kvBytes: 256\n * // },\n * // ...\n * // }\n * ```\n */\nexport function treeDumpStats(dumpStats: ExtendedResourceData[]): TreeDumpStats {\n const stats: TreeDumpStats = {\n total: {\n count: 0,\n fieldNameBytes: 0,\n fieldsCount: 0,\n dataBytes: 0,\n kvCount: 0,\n kvBytes: 0,\n },\n byResourceType: {},\n };\n\n for (const resource of dumpStats) {\n const typeKey = `${resource.type.name}/${resource.type.version}` as const;\n if (!stats.byResourceType[typeKey]) {\n stats.byResourceType[typeKey] = {\n count: 0,\n fieldNameBytes: 0,\n fieldsCount: 0,\n dataBytes: 0,\n kvCount: 0,\n kvBytes: 0,\n };\n }\n\n const typeStats = stats.byResourceType[typeKey];\n typeStats.count++;\n stats.total.count++;\n\n for (const field of resource.fields) {\n typeStats.fieldNameBytes += field.name.length;\n typeStats.fieldsCount++;\n stats.total.fieldNameBytes += field.name.length;\n stats.total.fieldsCount++;\n }\n\n if (resource.data) {\n const dataLength = resource.data?.length ?? 0;\n typeStats.dataBytes += dataLength;\n stats.total.dataBytes += dataLength;\n }\n\n typeStats.kvCount += resource.kv.length;\n stats.total.kvCount += resource.kv.length;\n\n for (const kv of resource.kv) {\n const kvLength = kv.key.length + kv.value.length;\n typeStats.kvBytes += kvLength;\n stats.total.kvBytes += kvLength;\n }\n }\n\n return stats;\n}\n"],"names":[],"mappings":";;AA2BA;;;;;;;;;;;;;;;;;;;;;;;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E;QAC3B;AAEA,QAAA,IAAI,QAAQ,CAAC,IAAI,EAAE;YACjB,MAAM,UAAU,GAAG,QAAQ,CAAC,IAAI,EAAE,MAAM,IAAI,CAAC;AAC7C,YAAA,SAAS,CAAC,SAAS,IAAI,UAAU;AACjC,YAAA,KAAK,CAAC,KAAK,CAAC,SAAS,IAAI,UAAU;QACrC;QAEA,SAAS,CAAC,OAAO,IAAI,QAAQ,CAAC,EAAE,CAAC,MAAM;QACvC,KAAK,CAAC,KAAK,CAAC,OAAO,IAAI,QAAQ,CAAC,EAAE,CAAC,MAAM;AAEzC,QAAA,KAAK,MAAM,EAAE,IAAI,QAAQ,CAAC,EAAE,EAAE;AAC5B,YAAA,MAAM,QAAQ,GAAG,EAAE,CAAC,GAAG,CAAC,MAAM,GAAG,EAAE,CAAC,KAAK,CAAC,MAAM;AAChD,YAAA,SAAS,CAAC,OAAO,IAAI,QAAQ;AAC7B,YAAA,KAAK,CAAC,KAAK,CAAC,OAAO,IAAI,QAAQ;QACjC;IACF;AAEA,IAAA,OAAO,KAAK;AACd;;;;"}
|
package/dist/dump.d.ts
CHANGED
package/dist/dump.js
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Analyzes a collection of resources and generates statistics grouped by resource type.
|
|
3
|
+
*
|
|
4
|
+
* This function processes an array of ExtendedResourceData and calculates various metrics
|
|
5
|
+
* for each unique resource type, including:
|
|
6
|
+
* - Count of resources
|
|
7
|
+
* - Total bytes in field names
|
|
8
|
+
* - Total number of fields
|
|
9
|
+
* - Total bytes in resource data
|
|
10
|
+
* - Total number of key-value records
|
|
11
|
+
* - Total bytes in key-value records
|
|
12
|
+
*
|
|
13
|
+
* The statistics are organized by resource type using a key in the format "typeName/version".
|
|
14
|
+
*
|
|
15
|
+
* @param dumpStats - Array of ExtendedResourceData objects to analyze
|
|
16
|
+
* @returns A DumpStats object containing statistics for each resource type
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* const resources = [...]; // Array of ExtendedResourceData
|
|
20
|
+
* const stats = treeDumpStats(resources);
|
|
21
|
+
* // stats = {
|
|
22
|
+
* // "MyResource/1": {
|
|
23
|
+
* // count: 5,
|
|
24
|
+
* // fieldNameBytes: 150,
|
|
25
|
+
* // fieldsCount: 10,
|
|
26
|
+
* // dataBytes: 1024,
|
|
27
|
+
* // kvCount: 3,
|
|
28
|
+
* // kvBytes: 256
|
|
29
|
+
* // },
|
|
30
|
+
* // ...
|
|
31
|
+
* // }
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
function treeDumpStats(dumpStats) {
|
|
35
|
+
const stats = {
|
|
36
|
+
total: {
|
|
37
|
+
count: 0,
|
|
38
|
+
fieldNameBytes: 0,
|
|
39
|
+
fieldsCount: 0,
|
|
40
|
+
dataBytes: 0,
|
|
41
|
+
kvCount: 0,
|
|
42
|
+
kvBytes: 0,
|
|
43
|
+
},
|
|
44
|
+
byResourceType: {},
|
|
45
|
+
};
|
|
46
|
+
for (const resource of dumpStats) {
|
|
47
|
+
const typeKey = `${resource.type.name}/${resource.type.version}`;
|
|
48
|
+
if (!stats.byResourceType[typeKey]) {
|
|
49
|
+
stats.byResourceType[typeKey] = {
|
|
50
|
+
count: 0,
|
|
51
|
+
fieldNameBytes: 0,
|
|
52
|
+
fieldsCount: 0,
|
|
53
|
+
dataBytes: 0,
|
|
54
|
+
kvCount: 0,
|
|
55
|
+
kvBytes: 0,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
const typeStats = stats.byResourceType[typeKey];
|
|
59
|
+
typeStats.count++;
|
|
60
|
+
stats.total.count++;
|
|
61
|
+
for (const field of resource.fields) {
|
|
62
|
+
typeStats.fieldNameBytes += field.name.length;
|
|
63
|
+
typeStats.fieldsCount++;
|
|
64
|
+
stats.total.fieldNameBytes += field.name.length;
|
|
65
|
+
stats.total.fieldsCount++;
|
|
66
|
+
}
|
|
67
|
+
if (resource.data) {
|
|
68
|
+
const dataLength = resource.data?.length ?? 0;
|
|
69
|
+
typeStats.dataBytes += dataLength;
|
|
70
|
+
stats.total.dataBytes += dataLength;
|
|
71
|
+
}
|
|
72
|
+
typeStats.kvCount += resource.kv.length;
|
|
73
|
+
stats.total.kvCount += resource.kv.length;
|
|
74
|
+
for (const kv of resource.kv) {
|
|
75
|
+
const kvLength = kv.key.length + kv.value.length;
|
|
76
|
+
typeStats.kvBytes += kvLength;
|
|
77
|
+
stats.total.kvBytes += kvLength;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return stats;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export { treeDumpStats };
|
|
84
|
+
//# sourceMappingURL=dump.js.map
|
package/dist/dump.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dump.js","sources":["../src/dump.ts"],"sourcesContent":["import type { ExtendedResourceData } from './state';\n\nexport type ResourceStats = {\n /** Number of resources of this type */\n count: number;\n /** Total number of bytes in the field names of all resources of this type */\n fieldNameBytes: number;\n /** Total number of fields in all resources of this type */\n fieldsCount: number;\n /** Total number of bytes in the data of all resources of this type */\n dataBytes: number;\n /** Total number of key-value records in all resources of this type */\n kvCount: number;\n /** Total number of bytes in the key-value records of all resources of this type */\n kvBytes: number;\n};\n\n/**\n * A map of resource type statistics, keyed by the resource type name and version.\n *\n * @type {Record<string, ResourceStats>}\n */\nexport type TreeDumpStats = {\n total: ResourceStats;\n byResourceType: Record<`${string}/${string}`, ResourceStats>;\n};\n\n/**\n * Analyzes a collection of resources and generates statistics grouped by resource type.\n *\n * This function processes an array of ExtendedResourceData and calculates various metrics\n * for each unique resource type, including:\n * - Count of resources\n * - Total bytes in field names\n * - Total number of fields\n * - Total bytes in resource data\n * - Total number of key-value records\n * - Total bytes in key-value records\n *\n * The statistics are organized by resource type using a key in the format \"typeName/version\".\n *\n * @param dumpStats - Array of ExtendedResourceData objects to analyze\n * @returns A DumpStats object containing statistics for each resource type\n * @example\n * ```typescript\n * const resources = [...]; // Array of ExtendedResourceData\n * const stats = treeDumpStats(resources);\n * // stats = {\n * // \"MyResource/1\": {\n * // count: 5,\n * // fieldNameBytes: 150,\n * // fieldsCount: 10,\n * // dataBytes: 1024,\n * // kvCount: 3,\n * // kvBytes: 256\n * // },\n * // ...\n * // }\n * ```\n */\nexport function treeDumpStats(dumpStats: ExtendedResourceData[]): TreeDumpStats {\n const stats: TreeDumpStats = {\n total: {\n count: 0,\n fieldNameBytes: 0,\n fieldsCount: 0,\n dataBytes: 0,\n kvCount: 0,\n kvBytes: 0,\n },\n byResourceType: {},\n };\n\n for (const resource of dumpStats) {\n const typeKey = `${resource.type.name}/${resource.type.version}` as const;\n if (!stats.byResourceType[typeKey]) {\n stats.byResourceType[typeKey] = {\n count: 0,\n fieldNameBytes: 0,\n fieldsCount: 0,\n dataBytes: 0,\n kvCount: 0,\n kvBytes: 0,\n };\n }\n\n const typeStats = stats.byResourceType[typeKey];\n typeStats.count++;\n stats.total.count++;\n\n for (const field of resource.fields) {\n typeStats.fieldNameBytes += field.name.length;\n typeStats.fieldsCount++;\n stats.total.fieldNameBytes += field.name.length;\n stats.total.fieldsCount++;\n }\n\n if (resource.data) {\n const dataLength = resource.data?.length ?? 0;\n typeStats.dataBytes += dataLength;\n stats.total.dataBytes += dataLength;\n }\n\n typeStats.kvCount += resource.kv.length;\n stats.total.kvCount += resource.kv.length;\n\n for (const kv of resource.kv) {\n const kvLength = kv.key.length + kv.value.length;\n typeStats.kvBytes += kvLength;\n stats.total.kvBytes += kvLength;\n }\n }\n\n return stats;\n}\n"],"names":[],"mappings":"AA2BA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgCG;AACG,SAAU,aAAa,CAAC,SAAiC,EAAA;AAC7D,IAAA,MAAM,KAAK,GAAkB;AAC3B,QAAA,KAAK,EAAE;AACL,YAAA,KAAK,EAAE,CAAC;AACR,YAAA,cAAc,EAAE,CAAC;AACjB,YAAA,WAAW,EAAE,CAAC;AACd,YAAA,SAAS,EAA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rC;QAEA,SAAS,CAAC,OAAO,IAAI,QAAQ,CAAC,EAAE,CAAC,MAAM;QACvC,KAAK,CAAC,KAAK,CAAC,OAAO,IAAI,QAAQ,CAAC,EAAE,CAAC,MAAM;AAEzC,QAAA,KAAK,MAAM,EAAE,IAAI,QAAQ,CAAC,EAAE,EAAE;AAC5B,YAAA,MAAM,QAAQ,GAAG,EAAE,CAAC,GAAG,CAAC,MAAM,GAAG,EAAE,CAAC,KAAK,CAAC,MAAM;AAChD,YAAA,SAAS,CAAC,OAAO,IAAI,QAAQ;AAC7B,YAAA,KAAK,CAAC,KAAK,CAAC,OAAO,IAAI,QAAQ;QACjC;IACF;AAEA,IAAA,OAAO,KAAK;AACd;;;;"}
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var state = require('./state.cjs');
|
|
4
|
+
var sync = require('./sync.cjs');
|
|
5
|
+
var accessors = require('./accessors.cjs');
|
|
6
|
+
var snapshot = require('./snapshot.cjs');
|
|
7
|
+
var synchronized_tree = require('./synchronized_tree.cjs');
|
|
8
|
+
var value_and_error = require('./value_and_error.cjs');
|
|
9
|
+
var dump = require('./dump.cjs');
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
exports.PlTreeResource = state.PlTreeResource;
|
|
14
|
+
exports.PlTreeState = state.PlTreeState;
|
|
15
|
+
exports.TreeStateUpdateError = state.TreeStateUpdateError;
|
|
16
|
+
exports.constructTreeLoadingRequest = sync.constructTreeLoadingRequest;
|
|
17
|
+
exports.formatTreeLoadingStat = sync.formatTreeLoadingStat;
|
|
18
|
+
exports.initialTreeLoadingStat = sync.initialTreeLoadingStat;
|
|
19
|
+
exports.loadTreeState = sync.loadTreeState;
|
|
20
|
+
exports.PlError = accessors.PlError;
|
|
21
|
+
exports.PlTreeEntry = accessors.PlTreeEntry;
|
|
22
|
+
exports.PlTreeEntryAccessor = accessors.PlTreeEntryAccessor;
|
|
23
|
+
exports.PlTreeNodeAccessor = accessors.PlTreeNodeAccessor;
|
|
24
|
+
exports.isPlTreeEntry = accessors.isPlTreeEntry;
|
|
25
|
+
exports.isPlTreeEntryAccessor = accessors.isPlTreeEntryAccessor;
|
|
26
|
+
exports.isPlTreeNodeAccessor = accessors.isPlTreeNodeAccessor;
|
|
27
|
+
exports.treeEntryToResourceInfo = accessors.treeEntryToResourceInfo;
|
|
28
|
+
exports.makeResourceSnapshot = snapshot.makeResourceSnapshot;
|
|
29
|
+
exports.rsSchema = snapshot.rsSchema;
|
|
30
|
+
exports.treeEntryToResourceWithData = snapshot.treeEntryToResourceWithData;
|
|
31
|
+
exports.treeEntryToResourceWithMetadata = snapshot.treeEntryToResourceWithMetadata;
|
|
32
|
+
exports.SynchronizedTreeState = synchronized_tree.SynchronizedTreeState;
|
|
33
|
+
exports.mapValueAndError = value_and_error.mapValueAndError;
|
|
34
|
+
exports.mapValueAndErrorIfDefined = value_and_error.mapValueAndErrorIfDefined;
|
|
35
|
+
exports.treeDumpStats = dump.treeDumpStats;
|
|
36
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/index.js
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
"use strict";var K=Object.defineProperty;var W=(n,e,t)=>e in n?K(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var c=(n,e,t)=>W(n,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("@milaboratories/pl-client"),m=require("@milaboratories/computable"),_=require("@milaboratories/pl-errors"),p=require("@milaboratories/ts-helpers"),B=require("denque"),M=require("node:timers/promises");function U(n){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(n){for(const t in n)if(t!=="default"){const i=Object.getOwnPropertyDescriptor(n,t);Object.defineProperty(e,t,i.get?i:{enumerable:!0,get:()=>n[t]})}}return e.default=n,Object.freeze(e)}const q=U(M);function J(n,e){if(n!==void 0)return D(n,e)}function D(n,e){const t={};return n.value!==void 0&&(t.value=e(n.value)),n.error!==void 0&&(t.error=e(n.error)),t}class z extends Error{constructor(e){super(e)}}function j(n){return typeof n=="object"&&n!==null&&n.__pl_tree_type_marker__==="PlTreeEntry"}function H(n){return typeof n=="object"&&n!==null&&n.__pl_tree_type_marker__==="PlTreeEntryAccessor"}function Y(n){return typeof n=="object"&&n!==null&&n.__pl_tree_type_marker__==="PlTreeNodeAccessor"}class T{constructor(e,t){c(this,"__pl_tree_type_marker__","PlTreeEntry");this.accessorData=e,this.rid=t}createAccessor(e,t){return new w(this.accessorData,this.accessorData.treeProvider(),this.rid,{ctx:e,guard:t})}toJSON(){return this.toString()}toString(){return`[ENTRY:${u.resourceIdToString(this.rid)}]`}}function A(n,e,t,i,a){const d=new b(n,e,e.get(t.ctx.watcher,i),t);if(!a.ignoreError){const o=d.getError();if(o!==void 0)throw _.parsePlError(p.notEmpty(o.getDataAsString()),d.id,d.resourceType)}if(a.assertResourceType!==void 0&&(Array.isArray(a.assertResourceType)?a.assertResourceType.findIndex(o=>u.resourceTypesEqual(o,d.resourceType))===-1:!u.resourceTypesEqual(a.assertResourceType,d.resourceType)))throw new Error(`wrong resource type ${u.resourceTypeToString(d.resourceType)} but expected ${a.assertResourceType}`);return d}class w{constructor(e,t,i,a){c(this,"__pl_tree_type_marker__","PlTreeEntryAccessor");this.accessorData=e,this.tree=t,this.rid=i,this.instanceData=a}node(e={}){return this.instanceData.guard(),this.accessorData.hooks!==void 0&&this.instanceData.ctx.attacheHooks(this.accessorData.hooks),A(this.accessorData,this.tree,this.instanceData,this.rid,e)}}function G(n,e){return n instanceof T?e.accessor(n).node().resourceInfo:n}class b{constructor(e,t,i,a){c(this,"__pl_tree_type_marker__","PlTreeNodeAccessor");c(this,"onUnstableLambda",e=>{this.instanceData.ctx.markUnstable(e)});this.accessorData=e,this.tree=t,this.resource=i,this.instanceData=a}get id(){return this.instanceData.guard(),this.resource.id}get originalId(){return this.instanceData.guard(),this.resource.originalResourceId}get resourceType(){return this.instanceData.guard(),this.resource.type}get resourceInfo(){return{id:this.id,type:this.resourceType}}getResourceFromTree(e,t){return A(this.accessorData,this.tree,this.instanceData,e,t)}traverse(...e){return this.traverseWithCommon({},...e)}traverseOrError(...e){return this.traverseOrErrorWithCommon({},...e)}traverseWithCommon(e,...t){const i=this.traverseOrErrorWithCommon(e,...t);if(i!==void 0){if(!i.ok)throw i.error;return i.value}}traverseOrErrorWithCommon(e,...t){let i=this;for(const a of t){const d=typeof a=="string"?{...e,field:a}:{...e,...a},o=i.getField(a);if(o===void 0||d.pureFieldErrorToUndefined&&o.value===void 0&&o.error!==void 0)return;if((!d.ignoreError||o.value===void 0)&&o.error!==void 0)return{ok:!1,error:_.parsePlError(p.notEmpty(o.error.getDataAsString()),i.id,i.resourceType,d.field)};if(o.value===void 0){if(d.errorIfFieldNotSet)return{ok:!1,error:new Error(`field have no assigned value ${d.field} of ${u.resourceIdToString(i.id)}`)};this.onUnstableLambda("unpopulated_field:"+d.field);return}i=o.value}return{ok:!0,value:i}}getField(e){this.instanceData.guard();const t=typeof e=="string"?{field:e}:e,i=this.resource.getField(this.instanceData.ctx.watcher,t,this.onUnstableLambda);if(i!==void 0)return D(i,a=>this.getResourceFromTree(a,{ignoreError:!0}))}getInputsLocked(){this.instanceData.guard();const e=this.resource.getInputsLocked(this.instanceData.ctx.watcher);return e||this.instanceData.ctx.markUnstable("inputs_unlocked:"+this.resourceType.name),e}getOutputsLocked(){this.instanceData.guard();const e=this.resource.getOutputsLocked(this.instanceData.ctx.watcher);return e||this.instanceData.ctx.markUnstable("outputs_unlocked:"+this.resourceType.name),e}getIsReadyOrError(){this.instanceData.guard();const e=this.resource.getIsReadyOrError(this.instanceData.ctx.watcher);return e||this.instanceData.ctx.markUnstable("not_ready:"+this.resourceType.name),e}getIsFinal(){return this.instanceData.guard(),this.resource.getIsFinal(this.instanceData.ctx.watcher)}getError(){this.instanceData.guard();const e=this.resource.getError(this.instanceData.ctx.watcher);if(e!==void 0)return this.getResourceFromTree(e,{})}getData(){return this.resource.data}getDataAsString(){return this.resource.getDataAsString()}getDataAsJson(){return this.resource.getDataAsJson()}listInputFields(){return this.instanceData.guard(),this.getInputsLocked(),this.resource.listInputFields(this.instanceData.ctx.watcher)}listOutputFields(){return this.instanceData.guard(),this.getOutputsLocked(),this.resource.listOutputFields(this.instanceData.ctx.watcher)}listDynamicFields(){return this.instanceData.guard(),this.resource.listDynamicFields(this.instanceData.ctx.watcher)}getKeyValue(e,t=!1){this.instanceData.guard();const i=this.resource.getKeyValue(this.instanceData.ctx.watcher,e);return i===void 0&&t&&this.instanceData.ctx.markUnstable("key_not_found_b:"+e),i}getKeyValueString(e){return this.getKeyValueAsString(e)}getKeyValueAsString(e,t=!1){this.instanceData.guard();const i=this.resource.getKeyValueString(this.instanceData.ctx.watcher,e);return i===void 0&&t&&this.instanceData.ctx.markUnstable("key_not_found_s:"+e),i}getKeyValueAsJson(e,t=!1){const i=this.resource.getKeyValueAsJson(this.instanceData.ctx.watcher,e);if(i===void 0){t&&this.instanceData.ctx.markUnstable("key_not_found_j:"+e);return}return i}toEntryAccessor(){return new w(this.accessorData,this.tree,this.id,this.instanceData)}persist(){return new T(this.accessorData,this.resource.id)}}class R extends Error{constructor(e){super(e)}}class N{constructor(e,t,i,a,d,o,r){c(this,"change",new m.ChangeSource);this.name=e,this.type=t,this.value=i,this.error=a,this.status=d,this.valueIsFinal=o,this.resourceVersion=r}get state(){return{name:this.name,type:this.type,status:this.status,value:this.value,error:this.error,valueIsFinal:this.valueIsFinal}}}const C=0;class P{constructor(e,t){c(this,"refCount",0);c(this,"version",C);c(this,"dataVersion",C);c(this,"fieldsMap",new Map);c(this,"kv",new Map);c(this,"resourceRemoved",new m.ChangeSource);c(this,"finalChanged",new m.ChangeSource);c(this,"resourceStateChange",new m.ChangeSource);c(this,"lockedChange",new m.ChangeSource);c(this,"inputAndServiceFieldListChanged",new m.ChangeSource);c(this,"outputFieldListChanged",new m.ChangeSource);c(this,"dynamicFieldListChanged",new m.ChangeSource);c(this,"kvChangedPerKey",new m.KeyedChangeSource);c(this,"id");c(this,"originalResourceId");c(this,"kind");c(this,"type");c(this,"data");c(this,"dataAsString");c(this,"dataAsJson");c(this,"error");c(this,"inputsLocked");c(this,"outputsLocked");c(this,"resourceReady");c(this,"finalFlag");c(this,"_finalState",!1);c(this,"logger");this.id=e.id,this.originalResourceId=e.originalResourceId,this.kind=e.kind,this.type=e.type,this.data=e.data,this.error=e.error,this.inputsLocked=e.inputsLocked,this.outputsLocked=e.outputsLocked,this.resourceReady=e.resourceReady,this.finalFlag=e.final,this.logger=t}info(e){this.logger!==void 0&&this.logger.info(e)}warn(e){this.logger!==void 0&&this.logger.warn(e)}get final(){return this.finalFlag}get finalState(){return this._finalState}get fields(){return[...this.fieldsMap.values()]}getField(e,t,i=()=>{}){var o,r,g;const a=typeof t=="string"?{field:t}:t,d=this.fieldsMap.get(a.field);if(d===void 0){if(a.errorIfFieldNotFound||a.errorIfFieldNotSet)throw new Error(`Field "${a.field}" not found in resource ${u.resourceIdToString(this.id)}`);if(!this.inputsLocked)(o=this.inputAndServiceFieldListChanged)==null||o.attachWatcher(e);else if(a.assertFieldType==="Service"||a.assertFieldType==="Input"){if(a.allowPermanentAbsence)return;throw new Error(`Service or input field not found ${a.field}.`)}if(!this.outputsLocked)(r=this.outputFieldListChanged)==null||r.attachWatcher(e);else if(a.assertFieldType==="Output"){if(a.allowPermanentAbsence)return;throw new Error(`Output field not found ${a.field}.`)}(g=this.dynamicFieldListChanged)==null||g.attachWatcher(e),!this._finalState&&!a.stableIfNotFound&&i("field_not_found:"+a.field);return}else{if(a.assertFieldType!==void 0&&d.type!==a.assertFieldType)throw new Error(`Unexpected field type: expected ${a.assertFieldType} but got ${d.type} for the field name ${a.field}`);const f={};return u.isNotNullResourceId(d.value)&&(f.value=d.value),u.isNotNullResourceId(d.error)&&(f.error=d.error),f.value===void 0&&f.error===void 0&&i("field_not_resolved:"+a.field),d.change.attachWatcher(e),f}}getInputsLocked(e){var t;return this.inputsLocked||(t=this.resourceStateChange)==null||t.attachWatcher(e),this.inputsLocked}getOutputsLocked(e){var t;return this.outputsLocked||(t=this.resourceStateChange)==null||t.attachWatcher(e),this.outputsLocked}get isReadyOrError(){return this.error!==u.NullResourceId||this.resourceReady||this.originalResourceId!==u.NullResourceId}getIsFinal(e){var t;return(t=this.finalChanged)==null||t.attachWatcher(e),this._finalState}getIsReadyOrError(e){var t;return this.isReadyOrError||(t=this.resourceStateChange)==null||t.attachWatcher(e),this.isReadyOrError}getError(e){var t;if(u.isNullResourceId(this.error)){(t=this.resourceStateChange)==null||t.attachWatcher(e);return}else return this.error}listInputFields(e){var i;const t=[];return this.fieldsMap.forEach((a,d)=>{(a.type==="Input"||a.type==="Service")&&t.push(d)}),this.inputsLocked||(i=this.inputAndServiceFieldListChanged)==null||i.attachWatcher(e),t}listOutputFields(e){var i;const t=[];return this.fieldsMap.forEach((a,d)=>{a.type==="Output"&&t.push(d)}),this.outputsLocked||(i=this.outputFieldListChanged)==null||i.attachWatcher(e),t}listDynamicFields(e){var i;const t=[];return this.fieldsMap.forEach((a,d)=>{a.type!=="Input"&&a.type!=="Output"&&t.push(d)}),(i=this.dynamicFieldListChanged)==null||i.attachWatcher(e),t}getKeyValue(e,t){var i;return(i=this.kvChangedPerKey)==null||i.attachWatcher(t,e),this.kv.get(t)}getKeyValueString(e,t){const i=this.getKeyValue(e,t);if(i!==void 0)return p.cachedDecode(i)}getKeyValueAsJson(e,t){const i=this.getKeyValue(e,t);if(i!==void 0)return p.cachedDeserialize(i)}getDataAsString(){if(this.data!==void 0)return this.dataAsString===void 0&&(this.dataAsString=p.cachedDecode(this.data)),this.dataAsString}getDataAsJson(){if(this.data!==void 0)return this.dataAsJson===void 0&&(this.dataAsJson=p.cachedDeserialize(this.data)),this.dataAsJson}verifyReadyState(){if(this.resourceReady&&!this.inputsLocked)throw new Error(`ready without input or output lock: ${u.stringifyWithResourceId(this.basicState)}`)}get basicState(){return{id:this.id,kind:this.kind,type:this.type,data:this.data,resourceReady:this.resourceReady,inputsLocked:this.inputsLocked,outputsLocked:this.outputsLocked,error:this.error,originalResourceId:this.originalResourceId,final:this.finalFlag}}get extendedState(){return{...this.basicState,fields:this.fields,kv:Array.from(this.kv.entries()).map(([e,t])=>({key:e,value:t}))}}markFinal(){this._finalState||(this._finalState=!0,p.notEmpty(this.finalChanged).markChanged("marked final"),this.finalChanged=void 0,this.resourceStateChange=void 0,this.dynamicFieldListChanged=void 0,this.inputAndServiceFieldListChanged=void 0,this.outputFieldListChanged=void 0,this.lockedChange=void 0,this.kvChangedPerKey=void 0)}markAllChanged(){var e,t,i,a,d,o,r;this.fieldsMap.forEach(g=>g.change.markChanged("marked all changed")),(e=this.finalChanged)==null||e.markChanged("marked all changed"),(t=this.resourceStateChange)==null||t.markChanged("marked all changed"),(i=this.lockedChange)==null||i.markChanged("marked all changed"),(a=this.inputAndServiceFieldListChanged)==null||a.markChanged("marked all changed"),(d=this.outputFieldListChanged)==null||d.markChanged("marked all changed"),(o=this.dynamicFieldListChanged)==null||o.markChanged("marked all changed"),(r=this.kvChangedPerKey)==null||r.markAllChanged("marked all changed"),this.resourceRemoved.markChanged("marked all changed")}}class E{constructor(e,t){c(this,"resources",new Map);c(this,"resourcesAdded",new m.ChangeSource);c(this,"_isValid",!0);c(this,"invalidationMessage");this.root=e,this.isFinalPredicate=t}forEachResource(e){this.resources.forEach(t=>e(t))}checkValid(){if(!this._isValid)throw new Error(this.invalidationMessage??"tree is in invalid state")}get(e,t){this.checkValid();const i=this.resources.get(t);if(i===void 0)throw this.resourcesAdded.attachWatcher(e),new Error(`resource ${u.resourceIdToString(t)} not found in the tree`);return i.resourceRemoved.attachWatcher(e),i}updateFromResourceData(e,t=!1){this.checkValid();const i=[],a=[];for(const o of e){let r=this.resources.get(o.id);const g=r==null?void 0:r.basicState,f=h=>{const{fields:s,...l}=o;throw this.invalidateTree(),new R(`Unexpected resource state transition (${h}): ${u.stringifyWithResourceId(l)} -> ${u.stringifyWithResourceId(g)}`)};if(r!==void 0){r.finalState&&f("resource state can be updated after it is marked as final");let h=!1;r.version+=1,r.originalResourceId!==o.originalResourceId&&(r.originalResourceId!==u.NullResourceId&&f("originalResourceId can't change after it is set"),r.originalResourceId=o.originalResourceId,p.notEmpty(r.resourceStateChange).markChanged(`originalResourceId changed for ${u.resourceIdToString(r.id)}`),h=!0),r.error!==o.error&&(u.isNotNullResourceId(r.error)&&f("resource can't change attached error after it is set"),r.error=o.error,i.push(r.error),p.notEmpty(r.resourceStateChange).markChanged(`error changed for ${u.resourceIdToString(r.id)}`),h=!0);for(const s of o.fields){let l=r.fieldsMap.get(s.name);l?(l.type!==s.type&&(l.type!=="Dynamic"&&f(`field changed type ${l.type} -> ${s.type}`),p.notEmpty(r.dynamicFieldListChanged).markChanged(`field ${s.name} changed type from Dynamic to ${s.type} in ${u.resourceIdToString(r.id)}`),(l.type==="Input"||l.type==="Service")&&(r.inputsLocked&&f(`adding input field "${s.name}", while corresponding list is locked`),p.notEmpty(r.inputAndServiceFieldListChanged).markChanged(`field ${s.name} changed to type ${s.type} in ${u.resourceIdToString(r.id)}`)),l.type==="Output"&&(r.outputsLocked&&f(`adding output field "${s.name}", while corresponding list is locked`),p.notEmpty(r.outputFieldListChanged).markChanged(`field ${s.name} changed to type ${s.type} in ${u.resourceIdToString(r.id)}`)),l.type=s.type,l.change.markChanged(`field ${s.name} type changed to ${s.type} in ${u.resourceIdToString(r.id)}`),h=!0),l.value!==s.value&&(u.isNotNullResourceId(l.value)&&a.push(l.value),l.value=s.value,u.isNotNullResourceId(s.value)&&i.push(s.value),l.change.markChanged(`field ${s.name} value changed in ${u.resourceIdToString(r.id)}`),h=!0),l.error!==s.error&&(u.isNotNullResourceId(l.error)&&a.push(l.error),l.error=s.error,u.isNotNullResourceId(s.error)&&i.push(s.error),l.change.markChanged(`field ${s.name} error changed in ${u.resourceIdToString(r.id)}`),h=!0),l.status!==s.status&&(l.status=s.status,l.change.markChanged(`field ${s.name} status changed to ${s.status} in ${u.resourceIdToString(r.id)}`),h=!0),l.valueIsFinal!==s.valueIsFinal&&(l.valueIsFinal=s.valueIsFinal,l.change.markChanged(`field ${s.name} valueIsFinal changed to ${s.valueIsFinal} in ${u.resourceIdToString(r.id)}`),h=!0),l.resourceVersion=r.version):(l=new N(s.name,s.type,s.value,s.error,s.status,s.valueIsFinal,r.version),u.isNotNullResourceId(s.value)&&i.push(s.value),u.isNotNullResourceId(s.error)&&i.push(s.error),s.type==="Input"||s.type==="Service"?(r.inputsLocked&&f(`adding ${s.type} (${s.name}) field while inputs locked`),p.notEmpty(r.inputAndServiceFieldListChanged).markChanged(`new ${s.type} field ${s.name} added to ${u.resourceIdToString(r.id)}`)):s.type==="Output"?(r.outputsLocked&&f(`adding ${s.type} (${s.name}) field while outputs locked`),p.notEmpty(r.outputFieldListChanged).markChanged(`new ${s.type} field ${s.name} added to ${u.resourceIdToString(r.id)}`)):p.notEmpty(r.dynamicFieldListChanged).markChanged(`new ${s.type} field ${s.name} added to ${u.resourceIdToString(r.id)}`),r.fieldsMap.set(s.name,l),h=!0)}if(r.fieldsMap.forEach((s,l,k)=>{s.resourceVersion!==r.version&&((s.type==="Input"||s.type==="Service"||s.type==="Output")&&f(`removal of ${s.type} field ${l}`),s.change.markChanged(`dynamic field ${l} removed from ${u.resourceIdToString(r.id)}`),k.delete(l),u.isNotNullResourceId(s.value)&&a.push(s.value),u.isNotNullResourceId(s.error)&&a.push(s.error),p.notEmpty(r.dynamicFieldListChanged).markChanged(`dynamic field ${l} removed from ${u.resourceIdToString(r.id)}`))}),r.inputsLocked!==o.inputsLocked&&(r.inputsLocked&&f("inputs unlocking is not permitted"),r.inputsLocked=o.inputsLocked,p.notEmpty(r.lockedChange).markChanged(`inputs locked for ${u.resourceIdToString(r.id)}`),h=!0),r.outputsLocked!==o.outputsLocked&&(r.outputsLocked&&f("outputs unlocking is not permitted"),r.outputsLocked=o.outputsLocked,p.notEmpty(r.lockedChange).markChanged(`outputs locked for ${u.resourceIdToString(r.id)}`),h=!0),r.resourceReady!==o.resourceReady){const s=r.resourceReady;r.resourceReady=o.resourceReady,r.verifyReadyState(),r.isReadyOrError||f(`resource can't lose it's ready or error state (ready state before ${s})`),p.notEmpty(r.resourceStateChange).markChanged(`ready flag changed to ${o.resourceReady} for ${u.resourceIdToString(r.id)}`),h=!0}for(const s of o.kv){const l=r.kv.get(s.key);l===void 0?(r.kv.set(s.key,s.value),p.notEmpty(r.kvChangedPerKey).markChanged(s.key,`kv added for ${u.resourceIdToString(r.id)}: ${s.key}`)):Buffer.compare(l,s.value)!==0&&(r.kv.set(s.key,s.value),p.notEmpty(r.kvChangedPerKey).markChanged(s.key,`kv changed for ${u.resourceIdToString(r.id)}: ${s.key}`))}if(r.kv.size>o.kv.length){const s=new Set(o.kv.map(l=>l.key));r.kv.forEach((l,k,v)=>{s.has(k)||(v.delete(k),p.notEmpty(r.kvChangedPerKey).markChanged(k,`kv deleted for ${u.resourceIdToString(r.id)}: ${k}`))})}h&&(r.dataVersion=r.version,this.isFinalPredicate(r)&&r.markFinal())}else{r=new P(o),r.verifyReadyState(),u.isNotNullResourceId(r.error)&&i.push(r.error);for(const h of o.fields){const s=new N(h.name,h.type,h.value,h.error,h.status,h.valueIsFinal,C);u.isNotNullResourceId(h.value)&&i.push(h.value),u.isNotNullResourceId(h.error)&&i.push(h.error),r.fieldsMap.set(h.name,s)}for(const h of o.kv)r.kv.set(h.key,h.value);this.isFinalPredicate(r)&&r.markFinal(),this.resources.set(r.id,r),this.resourcesAdded.markChanged(`new resource ${u.resourceIdToString(r.id)} added`)}}for(const o of i){const r=this.resources.get(o);if(!r)throw this.invalidateTree(),new R(`orphan resource ${o}`);r.refCount++}let d=a;for(;d.length>0;){const o=[];for(const r of d){const g=this.resources.get(r);if(!g)throw this.invalidateTree(),new R(`orphan resource ${r}`);g.refCount--,g.refCount===0&&g.id!==this.root&&(g.fieldsMap.forEach(f=>{u.isNotNullResourceId(f.value)&&o.push(f.value),u.isNotNullResourceId(f.error)&&o.push(f.error),f.change.markChanged(`field ${f.name} removed during garbage collection of ${u.resourceIdToString(g.id)}`)}),u.isNotNullResourceId(g.error)&&o.push(g.error),g.resourceRemoved.markChanged(`resource removed during garbage collection: ${u.resourceIdToString(g.id)}`),this.resources.delete(r))}d=o}if(!t){for(const o of e)if(!this.resources.has(o.id))throw this.invalidateTree(),new R(`orphan input resource ${o.id}`)}}accessor(e=this.root){return this.checkValid(),this.entry(e)}entry(e=this.root){return this.checkValid(),new T({treeProvider:()=>this},e)}invalidateTree(e){this._isValid=!1,this.invalidationMessage=e,this.resources.forEach(t=>{t.markAllChanged()})}dumpState(){return Array.from(this.resources.values()).map(e=>e.extendedState)}}function O(n,e){const t=[],i=new Set;return n.forEachResource(a=>{a.finalState?i.add(a.id):t.push(a.id)}),t.length===0&&i.size===0&&t.push(n.root),{seedResources:t,finalResources:i,pruningFunction:e}}function I(){return{requests:0,roundTrips:0,retrievedResources:0,retrievedFields:0,retrievedKeyValues:0,retrievedResourceDataBytes:0,retrievedKeyValueBytes:0,prunedFields:0,finalResourcesSkipped:0,millisSpent:0}}function Q(n){let e=`Requests: ${n.requests}
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
`,e+=`KV Bytes: ${n.retrievedKeyValueBytes}
|
|
9
|
-
`,e+=`Pruned fields: ${n.prunedFields}
|
|
10
|
-
`,e+=`Final resources skipped: ${n.finalResourcesSkipped}`,e}async function x(n,e,t){var k;const i=Date.now();t&&t.requests++;const{seedResources:a,finalResources:d,pruningFunction:o}=e,r=new B;let g=!0,f=0;const h=new Set,s=v=>{if(u.isNullResourceId(v)||h.has(v))return;if(d.has(v)){t&&t.finalResourcesSkipped++;return}h.add(v);const y=n.getResourceDataIfExists(v,!0),S=n.listKeyValuesIfResourceExists(v),V=g;g&&(g=!1),r.push((async()=>{const[L,F]=await Promise.all([y,S]);if(V&&(f++,g=!0),L!==void 0){if(F===void 0)throw new Error("Inconsistent replies");return{...L,kv:F}}})())};a.forEach(v=>s(v));const l=[];for(;;){const v=r.shift();if(v===void 0)break;let y=await v;if(y!==void 0){if(o!==void 0){const S=o(y);t&&(t.prunedFields+=y.fields.length-S.length),y={...y,fields:S}}s(y.error);for(const S of y.fields)s(S.value),s(S.error);if(t){t.retrievedResources++,t.retrievedFields+=y.fields.length,t.retrievedKeyValues+=y.kv.length,t.retrievedResourceDataBytes+=((k=y.data)==null?void 0:k.length)??0;for(const S of y.kv)t.retrievedKeyValueBytes+=S.value.length}l.push(y)}}return t&&(t.millisSpent+=Date.now()-i,t.roundTrips+=f),l}function X(n){return n}function Z(n,e,t){var o;const i=n instanceof T?p.notEmpty(t).accessor(n).node():n instanceof w?n.node():n,d={...i.resourceInfo};if(e.data!==void 0&&(e.data==="raw"?d.data=i.getData():d.data=e.data.parse(i.getDataAsJson())),e.fields!==void 0){const r={};for(const[g,f]of Object.entries(e.fields))r[g]=(o=i.traverse({field:g,errorIfFieldNotSet:f,stableIfNotFound:!f}))==null?void 0:o.id;d.fields=r}if(e.kv!==void 0){const r={};for(const[g,f]of Object.entries(e.kv)){const h=i.getKeyValue(g);if(h===void 0)throw new Error(`Key not found ${g}`);f==="raw"?r[g]=h:r[g]=f.parse(JSON.parse(Buffer.from(h).toString("utf-8")))}d.kv=r}return d}function ee(n,e,t){if(n instanceof T){const i=t.accessor(n).node(),a=i.resourceInfo,d=e.map(o=>{var r,g;return[o,(g=(r=i.getField(o))==null?void 0:r.value)==null?void 0:g.id]});return{...a,fields:new Map(d),data:i.getData()??new Uint8Array}}return n}function te(n,e,t){if(!(n instanceof T))return n;const i=t.accessor(n).node(),a=i.resourceInfo,d=e.map(o=>[o,i.getKeyValue(o)]);return{...a,metadata:Object.fromEntries(d)}}class ${constructor(e,t,i,a){c(this,"finalPredicate");c(this,"state");c(this,"pollingInterval");c(this,"pruning");c(this,"logStat");c(this,"hooks");c(this,"abortController",new AbortController);c(this,"currentLoopDelayInterrupt");c(this,"scheduledOnNextState",[]);c(this,"keepRunning",!1);c(this,"currentLoop");c(this,"terminated",!1);this.pl=e,this.root=t,this.logger=a;const{finalPredicateOverride:d,pruning:o,pollingInterval:r,stopPollingDelay:g,logStat:f}=i;this.pruning=o,this.pollingInterval=r,this.finalPredicate=d??e.finalPredicate,this.logStat=f,this.state=new E(t,this.finalPredicate),this.hooks=new m.PollingComputableHooks(()=>this.startUpdating(),()=>this.stopUpdating(),{stopDebounce:g},(h,s)=>this.scheduleOnNextState(h,s))}accessor(e=this.root){if(this.terminated)throw new Error("tree synchronization is terminated");return this.entry(e)}entry(e=this.root){if(this.terminated)throw new Error("tree synchronization is terminated");return new T({treeProvider:()=>this.state,hooks:this.hooks},e)}async refreshState(){if(this.terminated)throw new Error("tree synchronization is terminated");await this.hooks.refreshState()}scheduleOnNextState(e,t){this.terminated?t(new Error("tree synchronization is terminated")):(this.scheduledOnNextState.push({resolve:e,reject:t}),this.currentLoopDelayInterrupt&&(this.currentLoopDelayInterrupt.abort(),this.currentLoopDelayInterrupt=void 0))}startUpdating(){this.terminated||(this.keepRunning=!0,this.currentLoop===void 0&&(this.currentLoop=this.mainLoop()))}stopUpdating(){this.keepRunning=!1}async refresh(e,t){if(this.terminated)throw new Error("tree synchronization is terminated");const i=O(this.state,this.pruning),a=await this.pl.withReadTx("ReadingTree",async d=>await x(d,i,e),t);this.state.updateFromResourceData(a,!0)}async mainLoop(){var i,a;let e=this.logStat?I():void 0,t=Date.now();for(;!(!this.keepRunning||this.terminated);){let d;this.scheduledOnNextState.length>0&&(d=this.scheduledOnNextState,this.scheduledOnNextState=[]);try{if(this.logStat==="per-request"&&(e=I()),await this.refresh(e),e&&this.logger&&this.logger.info(`Tree stat (success, after ${Date.now()-t}ms): ${JSON.stringify(e)}`),t=Date.now(),d!==void 0)for(const o of d)o.resolve()}catch(o){if(e&&this.logger&&this.logger.info(`Tree stat (error, after ${Date.now()-t}ms): ${JSON.stringify(e)}`),t=Date.now(),d!==void 0)for(const r of d)r.reject(o);if(o instanceof R){(i=this.logger)==null||i.error(o),this.state.invalidateTree("stat update error"),this.state=new E(this.root,this.finalPredicate);continue}else(a=this.logger)==null||a.warn(o)}if(!this.keepRunning||this.terminated)break;if(this.scheduledOnNextState.length===0)try{this.currentLoopDelayInterrupt=new AbortController,await q.setTimeout(this.pollingInterval,AbortSignal.any([this.abortController.signal,this.currentLoopDelayInterrupt.signal]))}catch(o){if(!u.isTimeoutOrCancelError(o))throw new Error("Unexpected error",{cause:o});break}finally{this.currentLoopDelayInterrupt=void 0}}this.currentLoop=void 0}dumpState(){return this.state.dumpState()}async terminate(){this.keepRunning=!1,this.terminated=!0,this.abortController.abort(),this.currentLoop!==void 0&&(await this.currentLoop,this.state.invalidateTree("synchronization terminated for the tree"))}async awaitSyncLoopTermination(){this.currentLoop!==void 0&&await this.currentLoop}static async init(e,t,i,a){const d=new $(e,t,i,a),o=i.logStat?I():void 0;let r=!1;try{await d.refresh(o,{timeout:i.initialTreeLoadingTimeout}),r=!0}finally{o&&a&&a.info(`Tree stat (initial load, ${r?"success":"failure"}): ${JSON.stringify(o)}`)}return d}}function re(n){var t;const e={total:{count:0,fieldNameBytes:0,fieldsCount:0,dataBytes:0,kvCount:0,kvBytes:0},byResourceType:{}};for(const i of n){const a=`${i.type.name}/${i.type.version}`;e.byResourceType[a]||(e.byResourceType[a]={count:0,fieldNameBytes:0,fieldsCount:0,dataBytes:0,kvCount:0,kvBytes:0});const d=e.byResourceType[a];d.count++,e.total.count++;for(const o of i.fields)d.fieldNameBytes+=o.name.length,d.fieldsCount++,e.total.fieldNameBytes+=o.name.length,e.total.fieldsCount++;if(i.data){const o=((t=i.data)==null?void 0:t.length)??0;d.dataBytes+=o,e.total.dataBytes+=o}d.kvCount+=i.kv.length,e.total.kvCount+=i.kv.length;for(const o of i.kv){const r=o.key.length+o.value.length;d.kvBytes+=r,e.total.kvBytes+=r}}return e}exports.PlError=z;exports.PlTreeEntry=T;exports.PlTreeEntryAccessor=w;exports.PlTreeNodeAccessor=b;exports.PlTreeResource=P;exports.PlTreeState=E;exports.SynchronizedTreeState=$;exports.TreeStateUpdateError=R;exports.constructTreeLoadingRequest=O;exports.formatTreeLoadingStat=Q;exports.initialTreeLoadingStat=I;exports.isPlTreeEntry=j;exports.isPlTreeEntryAccessor=H;exports.isPlTreeNodeAccessor=Y;exports.loadTreeState=x;exports.makeResourceSnapshot=Z;exports.mapValueAndError=D;exports.mapValueAndErrorIfDefined=J;exports.rsSchema=X;exports.treeDumpStats=re;exports.treeEntryToResourceInfo=G;exports.treeEntryToResourceWithData=ee;exports.treeEntryToResourceWithMetadata=te;
|
|
1
|
+
export { PlTreeResource, PlTreeState, TreeStateUpdateError } from './state.js';
|
|
2
|
+
export { constructTreeLoadingRequest, formatTreeLoadingStat, initialTreeLoadingStat, loadTreeState } from './sync.js';
|
|
3
|
+
export { PlError, PlTreeEntry, PlTreeEntryAccessor, PlTreeNodeAccessor, isPlTreeEntry, isPlTreeEntryAccessor, isPlTreeNodeAccessor, treeEntryToResourceInfo } from './accessors.js';
|
|
4
|
+
export { makeResourceSnapshot, rsSchema, treeEntryToResourceWithData, treeEntryToResourceWithMetadata } from './snapshot.js';
|
|
5
|
+
export { SynchronizedTreeState } from './synchronized_tree.js';
|
|
6
|
+
export { mapValueAndError, mapValueAndErrorIfDefined } from './value_and_error.js';
|
|
7
|
+
export { treeDumpStats } from './dump.js';
|
|
11
8
|
//# sourceMappingURL=index.js.map
|