@dxos/echo 0.16.0 → 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/Annotation.mjs +2 -2
- package/dist/lib/Database.mjs +1 -1
- package/dist/lib/Error.mjs +1 -1
- package/dist/lib/Feed.mjs +1 -1
- package/dist/lib/Format.mjs +2 -2
- package/dist/lib/Migration.mjs +1 -1
- package/dist/lib/chunk-Annotation.mjs +14 -11
- package/dist/lib/chunk-Annotation.mjs.map +1 -1
- package/dist/lib/chunk-Blob.mjs +1 -1
- package/dist/lib/chunk-Collection.mjs +1 -1
- package/dist/lib/chunk-Database.mjs +93 -7
- package/dist/lib/chunk-Database.mjs.map +1 -1
- package/dist/lib/chunk-Dataset.mjs +1 -1
- package/dist/lib/chunk-Entity.mjs +2 -2
- package/dist/lib/chunk-Entity.mjs.map +1 -1
- package/dist/lib/chunk-Error.mjs +13 -1
- package/dist/lib/chunk-Error.mjs.map +1 -1
- package/dist/lib/chunk-Feed.mjs +311 -17
- package/dist/lib/chunk-Feed.mjs.map +1 -1
- package/dist/lib/chunk-Filter.mjs +4 -3
- package/dist/lib/chunk-Filter.mjs.map +1 -1
- package/dist/lib/chunk-Format.mjs +2 -1
- package/dist/lib/chunk-Hypergraph.mjs +1 -1
- package/dist/lib/chunk-Hypergraph.mjs.map +1 -1
- package/dist/lib/chunk-Migration.mjs +155 -5
- package/dist/lib/chunk-Migration.mjs.map +1 -1
- package/dist/lib/chunk-Obj.mjs +12 -5
- package/dist/lib/chunk-Obj.mjs.map +1 -1
- package/dist/lib/chunk-Query.mjs +2 -2
- package/dist/lib/chunk-QueryResult.mjs.map +1 -1
- package/dist/lib/chunk-Ref2.mjs +2 -2
- package/dist/lib/chunk-Registry.mjs +1 -1
- package/dist/lib/chunk-Registry.mjs.map +1 -1
- package/dist/lib/chunk-Relation.mjs +5 -5
- package/dist/lib/chunk-Relation.mjs.map +1 -1
- package/dist/lib/chunk-Scope.mjs +16 -2
- package/dist/lib/chunk-Scope.mjs.map +1 -1
- package/dist/lib/chunk-Tag.mjs +4 -4
- package/dist/lib/chunk-Tag.mjs.map +1 -1
- package/dist/lib/chunk-Text.mjs +2 -2
- package/dist/lib/chunk-Type.mjs +26 -7
- package/dist/lib/chunk-Type.mjs.map +1 -1
- package/dist/lib/chunk-View.mjs +1 -1
- package/dist/lib/chunk-atom-snapshot.mjs +29 -1
- package/dist/lib/chunk-atom-snapshot.mjs.map +1 -1
- package/dist/lib/chunk-entity-dictionary.mjs +28 -19
- package/dist/lib/chunk-entity-dictionary.mjs.map +1 -1
- package/dist/lib/chunk-internal.mjs +231 -79
- package/dist/lib/chunk-internal.mjs.map +1 -1
- package/dist/lib/chunk-json-schema.mjs +1 -1
- package/dist/lib/chunk-ref.mjs +38 -34
- package/dist/lib/chunk-ref.mjs.map +1 -1
- package/dist/lib/chunk-select.mjs +7 -3
- package/dist/lib/chunk-select.mjs.map +1 -1
- package/dist/lib/index.mjs +2 -2
- package/dist/lib/internal.mjs +6 -6
- package/dist/lib/testing.mjs +2 -2
- package/dist/lib/testing.mjs.map +1 -1
- package/dist/types/src/Annotation.d.ts +1 -1
- package/dist/types/src/Annotation.d.ts.map +1 -1
- package/dist/types/src/Database.d.ts +30 -13
- package/dist/types/src/Database.d.ts.map +1 -1
- package/dist/types/src/Entity.d.ts +3 -4
- package/dist/types/src/Entity.d.ts.map +1 -1
- package/dist/types/src/Error.d.ts +36 -0
- package/dist/types/src/Error.d.ts.map +1 -1
- package/dist/types/src/Feed.d.ts +261 -18
- package/dist/types/src/Feed.d.ts.map +1 -1
- package/dist/types/src/Filter.d.ts +7 -1
- package/dist/types/src/Filter.d.ts.map +1 -1
- package/dist/types/src/Hypergraph.d.ts +1 -1
- package/dist/types/src/Migration.d.ts +213 -2
- package/dist/types/src/Migration.d.ts.map +1 -1
- package/dist/types/src/Migration.test.d.ts +2 -0
- package/dist/types/src/Migration.test.d.ts.map +1 -0
- package/dist/types/src/Obj.d.ts +4 -4
- package/dist/types/src/Obj.d.ts.map +1 -1
- package/dist/types/src/QueryResult.d.ts +16 -0
- package/dist/types/src/QueryResult.d.ts.map +1 -1
- package/dist/types/src/Relation.d.ts +3 -4
- package/dist/types/src/Relation.d.ts.map +1 -1
- package/dist/types/src/Scope.d.ts +32 -1
- package/dist/types/src/Scope.d.ts.map +1 -1
- package/dist/types/src/Tag.d.ts.map +1 -1
- package/dist/types/src/Type.d.ts +27 -2
- package/dist/types/src/Type.d.ts.map +1 -1
- package/dist/types/src/internal/Annotation/annotations.d.ts +35 -1
- package/dist/types/src/internal/Annotation/annotations.d.ts.map +1 -1
- package/dist/types/src/internal/Annotation/atoms.d.ts +2 -2
- package/dist/types/src/internal/Annotation/atoms.d.ts.map +1 -1
- package/dist/types/src/internal/Entity/api.d.ts +11 -0
- package/dist/types/src/internal/Entity/api.d.ts.map +1 -1
- package/dist/types/src/internal/Entity/model.d.ts +3 -2
- package/dist/types/src/internal/Entity/model.d.ts.map +1 -1
- package/dist/types/src/internal/Format/string.d.ts +5 -1
- package/dist/types/src/internal/Format/string.d.ts.map +1 -1
- package/dist/types/src/internal/Obj/atoms.d.ts +1 -1
- package/dist/types/src/internal/Obj/atoms.d.ts.map +1 -1
- package/dist/types/src/internal/Obj/json-serializer.d.ts.map +1 -1
- package/dist/types/src/internal/Query/pretty.d.ts.map +1 -1
- package/dist/types/src/internal/Ref/ref.d.ts +5 -1
- package/dist/types/src/internal/Ref/ref.d.ts.map +1 -1
- package/dist/types/src/internal/Ref/strong-deps.d.ts +3 -1
- package/dist/types/src/internal/Ref/strong-deps.d.ts.map +1 -1
- package/dist/types/src/internal/common/api/meta.d.ts +4 -5
- package/dist/types/src/internal/common/api/meta.d.ts.map +1 -1
- package/dist/types/src/internal/common/atom-snapshot.d.ts +10 -0
- package/dist/types/src/internal/common/atom-snapshot.d.ts.map +1 -1
- package/dist/types/src/internal/common/proxy/change-context.d.ts +4 -0
- package/dist/types/src/internal/common/proxy/change-context.d.ts.map +1 -1
- package/dist/types/src/internal/common/proxy/ownership.d.ts +5 -0
- package/dist/types/src/internal/common/proxy/ownership.d.ts.map +1 -1
- package/dist/types/src/internal/common/proxy/proxy-utils.d.ts.map +1 -1
- package/dist/types/src/internal/common/proxy/schema-validator.d.ts +17 -2
- package/dist/types/src/internal/common/proxy/schema-validator.d.ts.map +1 -1
- package/dist/types/src/internal/common/proxy/symbols.d.ts +10 -0
- package/dist/types/src/internal/common/proxy/symbols.d.ts.map +1 -1
- package/dist/types/src/internal/common/proxy/typed-handler.d.ts +0 -1
- package/dist/types/src/internal/common/proxy/typed-handler.d.ts.map +1 -1
- package/dist/types/src/internal/common/types/meta.d.ts +8 -4
- package/dist/types/src/internal/common/types/meta.d.ts.map +1 -1
- package/dist/types/src/internal/common/types/model-symbols.d.ts +6 -0
- package/dist/types/src/internal/common/types/model-symbols.d.ts.map +1 -1
- package/dist/types/src/internal/index.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +19 -15
- package/src/Annotation.test.ts +34 -0
- package/src/Annotation.ts +3 -0
- package/src/Database.ts +46 -15
- package/src/Entity.ts +3 -4
- package/src/Error.ts +9 -0
- package/src/Feed.test.ts +160 -0
- package/src/Feed.ts +412 -29
- package/src/Filter.ts +8 -1
- package/src/Hypergraph.ts +1 -1
- package/src/Migration.test.ts +137 -0
- package/src/Migration.ts +376 -4
- package/src/Obj.test.ts +44 -4
- package/src/Obj.ts +19 -5
- package/src/QueryResult.ts +14 -0
- package/src/Relation.ts +3 -4
- package/src/Scope.ts +43 -1
- package/src/Tag.md +5 -6
- package/src/Tag.ts +3 -2
- package/src/Type.test.ts +52 -0
- package/src/Type.ts +75 -22
- package/src/Type.tst.ts +155 -0
- package/src/internal/Annotation/annotations.test.ts +19 -0
- package/src/internal/Annotation/annotations.ts +67 -1
- package/src/internal/Annotation/atoms.ts +10 -9
- package/src/internal/Entity/api.ts +20 -1
- package/src/internal/Entity/model.ts +3 -0
- package/src/internal/Filter/match.ts +2 -2
- package/src/internal/Format/string.ts +7 -2
- package/src/internal/JsonSchema/json-schema.test.ts +2 -2
- package/src/internal/Obj/atoms.ts +9 -5
- package/src/internal/Obj/json-serializer.test.ts +34 -7
- package/src/internal/Obj/json-serializer.ts +18 -3
- package/src/internal/Query/pretty.ts +3 -2
- package/src/internal/Ref/ref.test.ts +27 -2
- package/src/internal/Ref/ref.ts +18 -2
- package/src/internal/Ref/strong-deps.ts +21 -2
- package/src/internal/common/api/meta.ts +7 -8
- package/src/internal/common/atom-snapshot.ts +61 -0
- package/src/internal/common/proxy/change-context.ts +5 -0
- package/src/internal/common/proxy/change.test.ts +62 -31
- package/src/internal/common/proxy/json-serializer.ts +3 -2
- package/src/internal/common/proxy/ownership.ts +14 -1
- package/src/internal/common/proxy/proxy-utils.ts +7 -1
- package/src/internal/common/proxy/schema-validator.ts +116 -27
- package/src/internal/common/proxy/symbols.ts +12 -0
- package/src/internal/common/proxy/typed-handler.test.ts +43 -0
- package/src/internal/common/proxy/typed-handler.ts +105 -33
- package/src/internal/common/types/meta.ts +25 -20
- package/src/internal/common/types/model-symbols.ts +7 -0
- package/src/internal/index.ts +1 -2
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { c as getMetaChecked, d as EntityMetaSchema, f as SCALAR_META_FIELDS, g as getMeta, i as isEntity, u as ATTR_META } from "./chunk-entity-dictionary.mjs";
|
|
1
|
+
import { _ as isTagEntity, c as getMetaChecked, d as EntityMetaSchema, f as SCALAR_META_FIELDS, g as getMeta, i as isEntity, u as ATTR_META } from "./chunk-entity-dictionary.mjs";
|
|
2
2
|
import { d as SnapshotKindId, f as StaticTypeSchemaSlot, g as getStaticTypeSchema, l as KindId, n as makeTypeJsonSchemaAnnotation, o as EntityKind, u as SchemaKindId } from "./chunk-util.mjs";
|
|
3
|
-
import { $t as
|
|
4
|
-
import { A as
|
|
5
|
-
import {
|
|
3
|
+
import { $t as SchemaId, Bt as getTypeURI, Ft as getSchemaTypename, It as getSchemaURI, Jt as setTypename, L as getObjectEchoUri, N as getDatabase, Ot as getEntityKind, Qt as SchemaAstId, R as defineHiddenProperty, Rt as getTypeAnnotation, Vt as getTypename, Xt as ATTR_TYPE, Yt as ATTR_PARENT, Zt as ParentId, _n as RelationSourceDXNId, _t as SetParentAnnotation, an as setType, bn as RelationTargetId, cn as ATTR_RELATION_TARGET, ct as LabelAnnotation, en as TypeEntityId, fn as MetaId, gn as ObjectVersionId, hn as ObjectDeletedId, in as setSchema, jt as getLabel, kt as getFromAst, ln as ATTR_SELF_URI, mn as ObjectDatabaseId, nn as getSchema, on as ATTR_DELETED, ot as IconAnnotation, rn as getType, sn as ATTR_RELATION_SOURCE, tn as TypeId, un as ATTR_SELF_URI_LEGACY, vn as RelationSourceId, xn as SelfURIId, yn as RelationTargetDXNId, yt as TypeAnnotationId, zt as getTypeIdentifierAnnotation } from "./chunk-Database.mjs";
|
|
4
|
+
import { A as symbolReactivePrototype, B as EventId, D as isValidProxyTarget, E as isReactiveRecord, F as createTextMethodError, I as ChangeId, L as ChangeKeyId, M as createArrayMethodError, O as normalizeSpliceRange, R as EntityElementsId, S as getMutableProxy, T as isProxy, _ as loadRefTarget, b as canonicalOf, g as refArrayFamily, h as setRefResolver, i as RefTypeId, m as refFromEncodedReference, n as Ref, w as getProxyTarget, x as createProxy, y as subscribe } from "./chunk-ref.mjs";
|
|
5
|
+
import { i as snapshotForComparison, r as snapshotEquals } from "./chunk-atom-snapshot.mjs";
|
|
6
6
|
import { i as toJsonSchema, l as JsonSchemaFields, r as toEffectSchema, u as JsonSchemaType } from "./chunk-json-schema.mjs";
|
|
7
7
|
import { EncodedReference, EntityStructure, isEncodedReference } from "@dxos/echo-protocol";
|
|
8
8
|
import { DXN, EID, EntityId, URI } from "@dxos/keys";
|
|
@@ -14,13 +14,13 @@ import { assertArgument, failedInvariant, invariant } from "@dxos/invariant";
|
|
|
14
14
|
import * as Struct from "effect/Struct";
|
|
15
15
|
import * as SchemaEx from "@dxos/effect/SchemaEx";
|
|
16
16
|
import { assumeType, decodeUint8ArrayFromJson, deepMapValues, encodeUint8ArrayToJson, getDeep, isEncodedUint8Array, visitValues } from "@dxos/util";
|
|
17
|
+
import * as Atom from "effect/reactivity/Atom";
|
|
17
18
|
import * as Effect from "effect/Effect";
|
|
18
19
|
import * as Equal from "effect/Equal";
|
|
19
20
|
import * as Hash from "effect/Hash";
|
|
20
21
|
import * as SchemaIssue from "effect/SchemaIssue";
|
|
21
22
|
import { Event } from "@dxos/async";
|
|
22
23
|
import { inspectCustom, raise } from "@dxos/debug";
|
|
23
|
-
import * as Atom from "effect/reactivity/Atom";
|
|
24
24
|
import * as semver from "semver";
|
|
25
25
|
import * as AsyncResult from "effect/reactivity/AsyncResult";
|
|
26
26
|
//#region src/internal/common/types/base.ts
|
|
@@ -98,7 +98,7 @@ function assertObjectModel(obj) {
|
|
|
98
98
|
invariant(typeof obj === "object" && obj !== null, "Invalid object model: not an object", {
|
|
99
99
|
"~LogMeta": "~LogMeta",
|
|
100
100
|
F: __dxlog_file$11,
|
|
101
|
-
L:
|
|
101
|
+
L: 111,
|
|
102
102
|
S: this,
|
|
103
103
|
A: ["typeof obj === 'object' && obj !== null", "'Invalid object model: not an object'"]
|
|
104
104
|
});
|
|
@@ -106,21 +106,21 @@ function assertObjectModel(obj) {
|
|
|
106
106
|
invariant(EntityId.isValid(obj.id), "Invalid object model: invalid id", {
|
|
107
107
|
"~LogMeta": "~LogMeta",
|
|
108
108
|
F: __dxlog_file$11,
|
|
109
|
-
L:
|
|
109
|
+
L: 113,
|
|
110
110
|
S: this,
|
|
111
111
|
A: ["EntityId.isValid(obj.id)", "'Invalid object model: invalid id'"]
|
|
112
112
|
});
|
|
113
113
|
invariant(obj[TypeId] === void 0 || typeof obj[TypeId] === "string", "Invalid object model: invalid type", {
|
|
114
114
|
"~LogMeta": "~LogMeta",
|
|
115
115
|
F: __dxlog_file$11,
|
|
116
|
-
L:
|
|
116
|
+
L: 114,
|
|
117
117
|
S: this,
|
|
118
118
|
A: ["obj[TypeId] === undefined || typeof obj[TypeId] === 'string'", "'Invalid object model: invalid type'"]
|
|
119
119
|
});
|
|
120
120
|
invariant(obj["~@dxos/echo/Kind"] === EntityKind.Object || obj["~@dxos/echo/Kind"] === EntityKind.Relation || obj["~@dxos/echo/Kind"] === EntityKind.Type, "Invalid object model: invalid entity kind", {
|
|
121
121
|
"~LogMeta": "~LogMeta",
|
|
122
122
|
F: __dxlog_file$11,
|
|
123
|
-
L:
|
|
123
|
+
L: 115,
|
|
124
124
|
S: this,
|
|
125
125
|
A: ["obj[KindId] === EntityKind.Object || obj[KindId] === EntityKind.Relation || obj[KindId] === EntityKind.Type", "'Invalid object model: invalid entity kind'"]
|
|
126
126
|
});
|
|
@@ -128,28 +128,28 @@ function assertObjectModel(obj) {
|
|
|
128
128
|
invariant(EID.isEID(obj[RelationSourceDXNId]), "Invalid object model: invalid relation source", {
|
|
129
129
|
"~LogMeta": "~LogMeta",
|
|
130
130
|
F: __dxlog_file$11,
|
|
131
|
-
L:
|
|
131
|
+
L: 121,
|
|
132
132
|
S: this,
|
|
133
133
|
A: ["EID.isEID(obj[RelationSourceDXNId])", "'Invalid object model: invalid relation source'"]
|
|
134
134
|
});
|
|
135
135
|
invariant(EID.isEID(obj[RelationTargetDXNId]), "Invalid object model: invalid relation target", {
|
|
136
136
|
"~LogMeta": "~LogMeta",
|
|
137
137
|
F: __dxlog_file$11,
|
|
138
|
-
L:
|
|
138
|
+
L: 122,
|
|
139
139
|
S: this,
|
|
140
140
|
A: ["EID.isEID(obj[RelationTargetDXNId])", "'Invalid object model: invalid relation target'"]
|
|
141
141
|
});
|
|
142
142
|
invariant(!EID.isEID(obj[RelationSourceId]), "Invalid object model: source pointer is a DXN", {
|
|
143
143
|
"~LogMeta": "~LogMeta",
|
|
144
144
|
F: __dxlog_file$11,
|
|
145
|
-
L:
|
|
145
|
+
L: 123,
|
|
146
146
|
S: this,
|
|
147
147
|
A: ["!EID.isEID(obj[RelationSourceId])", "'Invalid object model: source pointer is a DXN'"]
|
|
148
148
|
});
|
|
149
149
|
invariant(!EID.isEID(obj[RelationTargetId]), "Invalid object model: target pointer is a DXN", {
|
|
150
150
|
"~LogMeta": "~LogMeta",
|
|
151
151
|
F: __dxlog_file$11,
|
|
152
|
-
L:
|
|
152
|
+
L: 124,
|
|
153
153
|
S: this,
|
|
154
154
|
A: ["!EID.isEID(obj[RelationTargetId])", "'Invalid object model: target pointer is a DXN'"]
|
|
155
155
|
});
|
|
@@ -187,7 +187,8 @@ var prettyFilter = (filter) => {
|
|
|
187
187
|
case "timestamp": return `Filter.${filter.field}.${filter.operator}(${filter.value})`;
|
|
188
188
|
case "feed-cursor": return `Filter.feedCursor(${JSON.stringify({
|
|
189
189
|
begin: filter.begin,
|
|
190
|
-
end: filter.end
|
|
190
|
+
end: filter.end,
|
|
191
|
+
positions: filter.positions
|
|
191
192
|
})})`;
|
|
192
193
|
case "child-of": return `Filter.childOf([${filter.parents.map((p) => JSON.stringify(p)).join(", ")}], { transitive: ${filter.transitive} })`;
|
|
193
194
|
case "mnemonic": return `Filter.mnemonic(${JSON.stringify(filter.mnemonic)})`;
|
|
@@ -245,7 +246,10 @@ var prettyQuery = (query) => {
|
|
|
245
246
|
if (query.from.scopes.length === 0) return `${prettyQuery(query.query)}.from('all-accessible-spaces')`;
|
|
246
247
|
const scopeStrs = query.from.scopes.map((scope) => {
|
|
247
248
|
if (scope._tag === "space") return scope.includeAllFeeds ? `{ space: ${JSON.stringify(scope.spaceId)}, includeAllFeeds: true }` : `{ space: ${JSON.stringify(scope.spaceId)} }`;
|
|
248
|
-
if (scope._tag === "feed")
|
|
249
|
+
if (scope._tag === "feed") {
|
|
250
|
+
const branches = scope.branches !== void 0 ? `, branches: ${JSON.stringify(scope.branches)}` : "";
|
|
251
|
+
return `{ feed: ${JSON.stringify(String(scope.feedUri))}${branches} }`;
|
|
252
|
+
}
|
|
249
253
|
return `{ registry: ${JSON.stringify(scope.location)} }`;
|
|
250
254
|
});
|
|
251
255
|
return `${prettyQuery(query.query)}.from([${scopeStrs.join(", ")}])`;
|
|
@@ -281,7 +285,7 @@ var prettyAggregateArg = (aggregate) => {
|
|
|
281
285
|
//#region src/internal/Ref/strong-deps.ts
|
|
282
286
|
/**
|
|
283
287
|
* Direct strong-dependency URIs of an entity: the schema (only when stored as an object), the
|
|
284
|
-
* relation source/target, and the
|
|
288
|
+
* relation source/target, the parent, and the tags. Returns URIs (cross-space `echo:` EIDs and queue-item
|
|
285
289
|
* EIDs included); a persisted schema is an `echo:` URI, a static/registry type is a `dxn:` URI.
|
|
286
290
|
*
|
|
287
291
|
* A static/registry type (`dxn:`) is intentionally NOT a strong dep: it is always synchronously
|
|
@@ -296,6 +300,7 @@ var getStrongDependencyUris = (refs, owningSpaceId) => {
|
|
|
296
300
|
if (refs.target != null) res.push(qualifyToSpace(refs.target, owningSpaceId));
|
|
297
301
|
}
|
|
298
302
|
if (refs.parent != null) res.push(qualifyToSpace(refs.parent, owningSpaceId));
|
|
303
|
+
for (const tag of refs.tags ?? []) res.push(qualifyToSpace(tag, owningSpaceId));
|
|
299
304
|
return res;
|
|
300
305
|
};
|
|
301
306
|
/**
|
|
@@ -313,6 +318,15 @@ var qualifyToSpace = (uri, owningSpaceId) => {
|
|
|
313
318
|
entityId
|
|
314
319
|
}) : uri;
|
|
315
320
|
};
|
|
321
|
+
/** URIs of the tags a decoded entity's meta holds, which are resolved entities like its parent. */
|
|
322
|
+
var getTagUris = (meta) => {
|
|
323
|
+
const tags = meta != null && typeof meta === "object" ? Reflect.get(meta, "tags") : void 0;
|
|
324
|
+
if (!Array.isArray(tags)) return [];
|
|
325
|
+
return tags.flatMap((tag) => {
|
|
326
|
+
const uri = getObjectEchoUri(tag);
|
|
327
|
+
return uri != null ? [uri] : [];
|
|
328
|
+
});
|
|
329
|
+
};
|
|
316
330
|
/**
|
|
317
331
|
* Direct strong-dependency URIs of a live (decoded) entity — a queue item, cross-space proxy, or
|
|
318
332
|
* snapshot. Reads the reference URIs off the entity's hidden model symbols. ECHO db cores compute
|
|
@@ -330,7 +344,8 @@ var getStrongDependencies = (entity) => {
|
|
|
330
344
|
type: typeof props[TypeId] === "string" ? props[TypeId] : void 0,
|
|
331
345
|
source: props[RelationSourceDXNId],
|
|
332
346
|
target: props[RelationTargetDXNId],
|
|
333
|
-
parent: parent != null ? getObjectEchoUri(parent) : void 0
|
|
347
|
+
parent: parent != null ? getObjectEchoUri(parent) : void 0,
|
|
348
|
+
tags: getTagUris(props[MetaId])
|
|
334
349
|
}, owningSpaceId);
|
|
335
350
|
};
|
|
336
351
|
//#endregion
|
|
@@ -391,7 +406,7 @@ var serializeMeta = (meta) => {
|
|
|
391
406
|
const { tags, annotations, ...rest } = meta;
|
|
392
407
|
return serializeData({
|
|
393
408
|
...rest,
|
|
394
|
-
...tags != null && tags.length > 0 ? { tags } : {},
|
|
409
|
+
...tags != null && tags.length > 0 ? { tags: tags.map((tag) => Ref.make(tag)) } : {},
|
|
395
410
|
...annotations != null && Object.keys(annotations).length > 0 ? { annotations } : {}
|
|
396
411
|
});
|
|
397
412
|
};
|
|
@@ -540,6 +555,10 @@ var isInChangeContext = (key) => {
|
|
|
540
555
|
return currentChangeContext === key;
|
|
541
556
|
};
|
|
542
557
|
/**
|
|
558
|
+
* Whether any object is in a change context; only one can be at a time, so a change entered now would end it.
|
|
559
|
+
*/
|
|
560
|
+
var isAnyChangeContextActive = () => currentChangeContext !== null;
|
|
561
|
+
/**
|
|
543
562
|
* Queue a notification for the given key to be fired when the change context exits.
|
|
544
563
|
*
|
|
545
564
|
* @param key - The key to queue a notification for.
|
|
@@ -634,6 +653,11 @@ var __dxlog_file$9 = "/__w/dxos/dxos/packages/core/echo/echo/src/internal/common
|
|
|
634
653
|
*/
|
|
635
654
|
var EchoOwner = Symbol.for("@dxos/echo/Owner");
|
|
636
655
|
/**
|
|
656
|
+
* Whether the array holds root entities by identity (see {@link EntityElementsId}); its elements are
|
|
657
|
+
* never owned, copied or walked as nested data.
|
|
658
|
+
*/
|
|
659
|
+
var hasEntityElements = (value) => Array.isArray(value) && Reflect.get(value, EntityElementsId) === true;
|
|
660
|
+
/**
|
|
637
661
|
* Get the raw target from a value, unwrapping proxy if needed.
|
|
638
662
|
*/
|
|
639
663
|
var getRawTarget = (value) => {
|
|
@@ -684,7 +708,7 @@ var setOwnerRecursive = (value, owner, options = {}) => {
|
|
|
684
708
|
if (!isRootEchoObject) invariant(existingOwner == null || existingOwner === owner || existingOwner === newAllowedPreviousOwner, "Cannot reassign ownership of a nested record to a different ECHO object. Use deep copy first.", {
|
|
685
709
|
"~LogMeta": "~LogMeta",
|
|
686
710
|
F: __dxlog_file$9,
|
|
687
|
-
L:
|
|
711
|
+
L: 108,
|
|
688
712
|
S: void 0,
|
|
689
713
|
A: ["ownershipAllowed", "'Cannot reassign ownership of a nested record to a different ECHO object. Use deep copy first.'"]
|
|
690
714
|
});
|
|
@@ -694,6 +718,7 @@ var setOwnerRecursive = (value, owner, options = {}) => {
|
|
|
694
718
|
depth: depth + 1,
|
|
695
719
|
allowedPreviousOwner: newAllowedPreviousOwner
|
|
696
720
|
};
|
|
721
|
+
if (hasEntityElements(actualValue)) return;
|
|
697
722
|
if (Array.isArray(actualValue)) {
|
|
698
723
|
for (const item of actualValue) if (isValidProxyTarget(item) || isProxy(item)) setOwnerRecursive(item, owner, recursiveOptions);
|
|
699
724
|
} else for (const key in actualValue) if (Object.prototype.hasOwnProperty.call(actualValue, key)) {
|
|
@@ -715,6 +740,7 @@ var traverseObjectGraph = (value, visitor, visited = /* @__PURE__ */ new Set())
|
|
|
715
740
|
if (visited.has(actualValue)) return false;
|
|
716
741
|
visited.add(actualValue);
|
|
717
742
|
if (visitor(actualValue)) return true;
|
|
743
|
+
if (hasEntityElements(actualValue)) return false;
|
|
718
744
|
if (Array.isArray(actualValue)) {
|
|
719
745
|
for (const item of actualValue) if (traverseObjectGraph(item, visitor, visited)) return true;
|
|
720
746
|
} else for (const key in actualValue) if (Object.prototype.hasOwnProperty.call(actualValue, key)) {
|
|
@@ -754,7 +780,7 @@ var getEchoRoot = (target, depth = 0) => {
|
|
|
754
780
|
invariant(depth < MAX_OWNER_DEPTH, "Owner chain too deep - possible circular ownership", {
|
|
755
781
|
"~LogMeta": "~LogMeta",
|
|
756
782
|
F: __dxlog_file$9,
|
|
757
|
-
L:
|
|
783
|
+
L: 233,
|
|
758
784
|
S: void 0,
|
|
759
785
|
A: ["depth < MAX_OWNER_DEPTH", "'Owner chain too deep - possible circular ownership'"]
|
|
760
786
|
});
|
|
@@ -836,15 +862,19 @@ var formatIssue = SchemaIssue.makeFormatterStandardSchemaV1();
|
|
|
836
862
|
* Asserts a value against a schema, naming the offending field.
|
|
837
863
|
*
|
|
838
864
|
* v4's `Schema.asserts` throws the fixed message "Schema validation failed" and puts the detail on
|
|
839
|
-
* the error's `cause`, which leaves nothing actionable in a stack trace or a UI toast.
|
|
865
|
+
* the error's `cause`, which leaves nothing actionable in a stack trace or a UI toast. `basePath` is
|
|
866
|
+
* where `value` sits in its object, for a caller that validates one property's value on its own.
|
|
840
867
|
*/
|
|
841
|
-
var assertsWithDetail = (schema, value) => {
|
|
868
|
+
var assertsWithDetail = (schema, value, basePath = []) => {
|
|
842
869
|
try {
|
|
843
870
|
Schema.asserts(schema, value);
|
|
844
871
|
} catch (err) {
|
|
845
872
|
const issue = err instanceof Error ? err.cause : void 0;
|
|
846
873
|
if (!SchemaIssue.isIssue(issue)) throw err;
|
|
847
|
-
const detail = formatIssue(issue).issues.map(({ message, path }) =>
|
|
874
|
+
const detail = formatIssue(issue).issues.map(({ message, path = [] }) => {
|
|
875
|
+
const fullPath = [...basePath, ...path];
|
|
876
|
+
return fullPath.length > 0 ? `${fullPath.map(String).join(".")}: ${message}` : message;
|
|
877
|
+
}).join("; ");
|
|
848
878
|
throw new Error(detail.length > 0 ? `Schema validation failed — ${detail}` : "Schema validation failed", { cause: issue });
|
|
849
879
|
}
|
|
850
880
|
};
|
|
@@ -866,6 +896,15 @@ var SchemaValidator = class {
|
|
|
866
896
|
}
|
|
867
897
|
}
|
|
868
898
|
static getPropertySchema(rootObjectSchema, propertyPath, getProperty = () => null) {
|
|
899
|
+
const ast = this.getPropertyAstChain(rootObjectSchema, propertyPath, getProperty).at(-1) ?? rootObjectSchema.ast;
|
|
900
|
+
return ast === rootObjectSchema.ast ? rootObjectSchema : Schema.make(ast);
|
|
901
|
+
}
|
|
902
|
+
/**
|
|
903
|
+
* The AST of every property along `propertyPath`, outermost first (one per path segment), so a caller
|
|
904
|
+
* can find an annotation set on an enclosing field rather than on the written leaf.
|
|
905
|
+
*/
|
|
906
|
+
static getPropertyAstChain(rootObjectSchema, propertyPath, getProperty = () => null) {
|
|
907
|
+
const chain = [];
|
|
869
908
|
let ast = rootObjectSchema.ast;
|
|
870
909
|
for (let i = 0; i < propertyPath.length; i++) {
|
|
871
910
|
const propertyName = propertyPath[i];
|
|
@@ -873,18 +912,16 @@ var SchemaValidator = class {
|
|
|
873
912
|
if (tupleAst != null) ast = getArrayElementAst(tupleAst, propertyName);
|
|
874
913
|
else {
|
|
875
914
|
const propertyType = getPropertyType(ast, propertyName.toString(), (propertyName) => getProperty([...propertyPath.slice(0, i), propertyName]));
|
|
876
|
-
if (propertyType
|
|
915
|
+
if (propertyType != null) ast = propertyType;
|
|
916
|
+
else {
|
|
877
917
|
const indexSignatureType = getIndexSignatureValueType(ast);
|
|
878
|
-
if (indexSignatureType
|
|
879
|
-
|
|
880
|
-
continue;
|
|
881
|
-
}
|
|
882
|
-
throw new TypeError(`Unknown property: ${formatPropertyPath([...propertyPath.slice(0, i), propertyName])}`);
|
|
918
|
+
if (indexSignatureType == null) throw new TypeError(`Unknown property: ${formatPropertyPath([...propertyPath.slice(0, i), propertyName])}`);
|
|
919
|
+
ast = indexSignatureType;
|
|
883
920
|
}
|
|
884
|
-
ast = propertyType;
|
|
885
921
|
}
|
|
922
|
+
chain.push(ast);
|
|
886
923
|
}
|
|
887
|
-
return
|
|
924
|
+
return chain;
|
|
888
925
|
}
|
|
889
926
|
/**
|
|
890
927
|
* Rejects properties not declared on the schema. Types with index signatures allow extra keys.
|
|
@@ -907,7 +944,7 @@ var SchemaValidator = class {
|
|
|
907
944
|
invariant(propertySignature, "Property signature must exist.", {
|
|
908
945
|
"~LogMeta": "~LogMeta",
|
|
909
946
|
F: __dxlog_file$8,
|
|
910
|
-
L:
|
|
947
|
+
L: 148,
|
|
911
948
|
S: this,
|
|
912
949
|
A: ["propertySignature", "'Property signature must exist.'"]
|
|
913
950
|
});
|
|
@@ -936,13 +973,24 @@ var SchemaValidator = class {
|
|
|
936
973
|
const property = SchemaAST.getPropertySignatures(ast).find((candidate) => candidate.name === prop);
|
|
937
974
|
return property != null && SchemaAST.isOptional(property.type);
|
|
938
975
|
}
|
|
976
|
+
/** What writing `undefined` at `propertyPath` deletes: an optional key, a union member's tag, or a key validated as a value. */
|
|
977
|
+
static getClearedKey(rootObjectSchema, propertyPath, getProperty) {
|
|
978
|
+
const propertyName = propertyPath.at(-1);
|
|
979
|
+
if (propertyName === void 0) return "other";
|
|
980
|
+
const parentPath = propertyPath.slice(0, -1);
|
|
981
|
+
const parentAst = this.getPropertyAstChain(rootObjectSchema, parentPath, getProperty).at(-1) ?? rootObjectSchema.ast;
|
|
982
|
+
const property = getPropertySignature(parentAst, propertyName.toString(), (name) => getProperty([...parentPath, name]));
|
|
983
|
+
if (property == null) return "other";
|
|
984
|
+
if (isUnionTag(parentAst, property.name)) return "union-tag";
|
|
985
|
+
return SchemaAST.isOptional(property.type) ? "optional" : "other";
|
|
986
|
+
}
|
|
939
987
|
/** The AST that property `prop` of a typed target follows. */
|
|
940
988
|
static getTargetPropertyAst(target, prop) {
|
|
941
989
|
const ast = getTargetAst(target);
|
|
942
990
|
invariant(ast, "target has no schema", {
|
|
943
991
|
"~LogMeta": "~LogMeta",
|
|
944
992
|
F: __dxlog_file$8,
|
|
945
|
-
L:
|
|
993
|
+
L: 218,
|
|
946
994
|
S: this,
|
|
947
995
|
A: ["ast", "'target has no schema'"]
|
|
948
996
|
});
|
|
@@ -990,7 +1038,7 @@ var getArrayElementAst = (tupleAst, property) => {
|
|
|
990
1038
|
invariant(property === "length", `invalid array property: ${String(property)}`, {
|
|
991
1039
|
"~LogMeta": "~LogMeta",
|
|
992
1040
|
F: __dxlog_file$8,
|
|
993
|
-
L:
|
|
1041
|
+
L: 292,
|
|
994
1042
|
S: void 0,
|
|
995
1043
|
A: ["property === 'length'", "`invalid array property: ${String(property)}`"]
|
|
996
1044
|
});
|
|
@@ -1005,12 +1053,11 @@ var getProperties = (typeAst, getTargetPropertyFn) => {
|
|
|
1005
1053
|
if (typeAstList.length === 0) return [];
|
|
1006
1054
|
if (typeAstList.length === 1) return SchemaAST.getPropertySignatures(typeAstList[0]);
|
|
1007
1055
|
const typeDiscriminators = getTypeDiscriminators(typeAstList);
|
|
1008
|
-
const
|
|
1009
|
-
const typeIndex = typeDiscriminators.findIndex((p) => targetPropertyValue === p.type.literal);
|
|
1056
|
+
const typeIndex = selectMember(typeDiscriminators, getTargetPropertyFn(String(typeDiscriminators[0].name)));
|
|
1010
1057
|
invariant(typeIndex !== -1, "discriminator field not set on target", {
|
|
1011
1058
|
"~LogMeta": "~LogMeta",
|
|
1012
1059
|
F: __dxlog_file$8,
|
|
1013
|
-
L:
|
|
1060
|
+
L: 321,
|
|
1014
1061
|
S: void 0,
|
|
1015
1062
|
A: ["typeIndex !== -1", "'discriminator field not set on target'"]
|
|
1016
1063
|
});
|
|
@@ -1018,17 +1065,30 @@ var getProperties = (typeAst, getTargetPropertyFn) => {
|
|
|
1018
1065
|
};
|
|
1019
1066
|
var getPropertyType = (ast, propertyName, getTargetPropertyFn) => {
|
|
1020
1067
|
if (unwrapAst(ast, (candidate) => SchemaAST.isAnyKeyword(candidate) || SchemaAST.isUnknownKeyword(candidate) || SchemaAST.isObjectKeyword(candidate)) != null) return ast;
|
|
1021
|
-
const
|
|
1022
|
-
return SchemaAST.isObjects(t) || SchemaAST.isUnion(t) && t.types.some((t) => SchemaAST.isObjects(t));
|
|
1023
|
-
});
|
|
1024
|
-
if (typeOrDiscriminatedUnion == null) return null;
|
|
1025
|
-
const targetProperty = getProperties(typeOrDiscriminatedUnion, getTargetPropertyFn).find((p) => p.name === propertyName);
|
|
1068
|
+
const targetProperty = getPropertySignature(ast, propertyName, getTargetPropertyFn);
|
|
1026
1069
|
if (targetProperty != null) return unwrapAst(targetProperty.type);
|
|
1027
1070
|
const indexSignatureType = unwrapAst(ast, SchemaAST.isObjects);
|
|
1028
1071
|
if (indexSignatureType && SchemaAST.isObjects(indexSignatureType) && indexSignatureType.indexSignatures.length > 0) return unwrapAst(indexSignatureType.indexSignatures[0].type);
|
|
1029
1072
|
return null;
|
|
1030
1073
|
};
|
|
1031
1074
|
/**
|
|
1075
|
+
* The signature of `propertyName` on a struct, or on the member of a discriminated union that the target's
|
|
1076
|
+
* current discriminator selects.
|
|
1077
|
+
*/
|
|
1078
|
+
var getPropertySignature = (ast, propertyName, getTargetPropertyFn) => {
|
|
1079
|
+
const typeOrDiscriminatedUnion = unwrapAst(ast, (t) => {
|
|
1080
|
+
return SchemaAST.isObjects(t) || SchemaAST.isUnion(t) && t.types.some((t) => SchemaAST.isObjects(t));
|
|
1081
|
+
});
|
|
1082
|
+
if (typeOrDiscriminatedUnion == null) return null;
|
|
1083
|
+
return getProperties(typeOrDiscriminatedUnion, getTargetPropertyFn).find((p) => p.name === propertyName) ?? null;
|
|
1084
|
+
};
|
|
1085
|
+
/** Whether `propertyName` is the tag selecting a member of the discriminated union at `ast`. */
|
|
1086
|
+
var isUnionTag = (ast, propertyName) => {
|
|
1087
|
+
const union = unwrapAst(ast, (t) => SchemaAST.isUnion(t) && t.types.some((member) => SchemaAST.isObjects(member)));
|
|
1088
|
+
const members = union == null ? [] : flattenUnion(union).filter((member) => SchemaAST.isObjects(member));
|
|
1089
|
+
return members.length > 1 && getTypeDiscriminators(members)[0].name === propertyName;
|
|
1090
|
+
};
|
|
1091
|
+
/**
|
|
1032
1092
|
* Unwraps the shapes a tag takes on after a JSON schema round-trip: optional (its constructor
|
|
1033
1093
|
* default leaves it out of `required`) and single-member union (a one-entry `anyOf`).
|
|
1034
1094
|
*/
|
|
@@ -1036,6 +1096,22 @@ var unwrapDiscriminator = (ast) => {
|
|
|
1036
1096
|
const unwrapped = SchemaEx.unwrapOptional(ast);
|
|
1037
1097
|
return SchemaAST.isUnion(unwrapped) && unwrapped.types.length === 1 ? unwrapDiscriminator(unwrapped.types[0]) : unwrapped;
|
|
1038
1098
|
};
|
|
1099
|
+
/** The tag a union member's discriminator property declares, seen through {@link unwrapDiscriminator}. */
|
|
1100
|
+
var discriminatorValue = (property) => {
|
|
1101
|
+
const tag = unwrapDiscriminator(property.type);
|
|
1102
|
+
return SchemaAST.isLiteral(tag) ? tag.literal : void 0;
|
|
1103
|
+
};
|
|
1104
|
+
/**
|
|
1105
|
+
* The index of the union member a target's tag selects; with no tag, the one member whose tag may be omitted (-1 when
|
|
1106
|
+
* none or several may be).
|
|
1107
|
+
*/
|
|
1108
|
+
var selectMember = (typeDiscriminators, tag) => {
|
|
1109
|
+
if (tag === void 0) {
|
|
1110
|
+
const omittable = typeDiscriminators.flatMap((property, index) => SchemaAST.isOptional(property.type) ? [index] : []);
|
|
1111
|
+
return omittable.length === 1 ? omittable[0] : -1;
|
|
1112
|
+
}
|
|
1113
|
+
return typeDiscriminators.findIndex((property) => tag === discriminatorValue(property));
|
|
1114
|
+
};
|
|
1039
1115
|
var getTypeDiscriminators = (typeAstList) => {
|
|
1040
1116
|
const discriminatorPropCandidates = typeAstList.flatMap(SchemaAST.getPropertySignatures).filter((p) => SchemaAST.isLiteral(unwrapDiscriminator(p.type)));
|
|
1041
1117
|
const propertyName = discriminatorPropCandidates[0]?.name;
|
|
@@ -1044,7 +1120,7 @@ var getTypeDiscriminators = (typeAstList) => {
|
|
|
1044
1120
|
invariant(isValidDiscriminator && everyTypeHasDiscriminator, "type ambiguity: every type in a union must have a single unique-literal field", {
|
|
1045
1121
|
"~LogMeta": "~LogMeta",
|
|
1046
1122
|
F: __dxlog_file$8,
|
|
1047
|
-
L:
|
|
1123
|
+
L: 422,
|
|
1048
1124
|
S: void 0,
|
|
1049
1125
|
A: ["isDiscriminatedUnion", "'type ambiguity: every type in a union must have a single unique-literal field'"]
|
|
1050
1126
|
});
|
|
@@ -1094,17 +1170,17 @@ var resolveTypeLiteral = (ast, getTargetPropertyFn) => {
|
|
|
1094
1170
|
const typeAstList = typeOrDiscriminatedUnion.types.filter((type) => SchemaAST.isObjects(type));
|
|
1095
1171
|
if (typeAstList.length === 1) return typeAstList[0];
|
|
1096
1172
|
const typeDiscriminators = getTypeDiscriminators(typeAstList);
|
|
1097
|
-
const
|
|
1098
|
-
const typeIndex = typeDiscriminators.findIndex((property) => targetPropertyValue === property.type.literal);
|
|
1173
|
+
const typeIndex = selectMember(typeDiscriminators, getTargetPropertyFn(String(typeDiscriminators[0].name)));
|
|
1099
1174
|
invariant(typeIndex !== -1, "discriminator field not set on target", {
|
|
1100
1175
|
"~LogMeta": "~LogMeta",
|
|
1101
1176
|
F: __dxlog_file$8,
|
|
1102
|
-
L:
|
|
1177
|
+
L: 513,
|
|
1103
1178
|
S: void 0,
|
|
1104
1179
|
A: ["typeIndex !== -1", "'discriminator field not set on target'"]
|
|
1105
1180
|
});
|
|
1106
1181
|
return typeAstList[typeIndex];
|
|
1107
1182
|
};
|
|
1183
|
+
/** True for an object literal (or `Object.create(null)`), as opposed to an array, byte array or class instance. */
|
|
1108
1184
|
var isPlainRecord = (value) => {
|
|
1109
1185
|
if (typeof value !== "object" || value === null || Array.isArray(value) || value instanceof Uint8Array) return false;
|
|
1110
1186
|
const proto = Object.getPrototypeOf(value);
|
|
@@ -1115,12 +1191,20 @@ var checkIdNotPresentOnSchema = (schema) => {
|
|
|
1115
1191
|
invariant(SchemaAST.isObjects(schema.ast), void 0, {
|
|
1116
1192
|
"~LogMeta": "~LogMeta",
|
|
1117
1193
|
F: __dxlog_file$8,
|
|
1118
|
-
L:
|
|
1194
|
+
L: 530,
|
|
1119
1195
|
S: void 0,
|
|
1120
1196
|
A: ["SchemaAST.isObjects(schema.ast)", ""]
|
|
1121
1197
|
});
|
|
1122
1198
|
if (SchemaAST.getPropertySignatures(schema.ast).find((prop) => prop.name === "id") != null) throw new Error("\"id\" property name is reserved");
|
|
1123
1199
|
};
|
|
1200
|
+
/**
|
|
1201
|
+
* Whether the AST describes an array of root entities held by identity (elements annotated with
|
|
1202
|
+
* {@link EntityValueAnnotationId}).
|
|
1203
|
+
*/
|
|
1204
|
+
var isEntityArrayAst = (ast) => {
|
|
1205
|
+
const elementAst = unwrapArray(ast)?.rest[0];
|
|
1206
|
+
return elementAst != null && SchemaAST.getAnnotation(elementAst, "@dxos/echo/annotation/EntityValue") === true;
|
|
1207
|
+
};
|
|
1124
1208
|
//#endregion
|
|
1125
1209
|
//#region src/internal/common/proxy/typed-handler.ts
|
|
1126
1210
|
var __dxlog_file$7 = "/__w/dxos/dxos/packages/core/echo/echo/src/internal/common/proxy/typed-handler.ts";
|
|
@@ -1142,6 +1226,12 @@ var deepCopy = (value, visited = /* @__PURE__ */ new Map()) => {
|
|
|
1142
1226
|
if (value == null || typeof value !== "object") return value;
|
|
1143
1227
|
const actualValue = getRawTarget(value);
|
|
1144
1228
|
if (visited.has(actualValue)) return visited.get(actualValue);
|
|
1229
|
+
if (hasEntityElements(actualValue)) {
|
|
1230
|
+
const copy = toEntityArray(actualValue);
|
|
1231
|
+
visited.set(actualValue, copy);
|
|
1232
|
+
copyHiddenProperties(actualValue, copy);
|
|
1233
|
+
return copy;
|
|
1234
|
+
}
|
|
1145
1235
|
if (actualValue instanceof ReactiveArray) {
|
|
1146
1236
|
const copy = new ReactiveArray();
|
|
1147
1237
|
visited.set(actualValue, copy);
|
|
@@ -1173,6 +1263,13 @@ var setDeepOnRawTargets = (target, path, value) => {
|
|
|
1173
1263
|
for (const key of path.slice(0, -1)) parent = getRawTarget(parent[key]);
|
|
1174
1264
|
parent[path[path.length - 1]] = value;
|
|
1175
1265
|
};
|
|
1266
|
+
/** A fresh reactive array of the given entities, marked so they stay held by identity. */
|
|
1267
|
+
var toEntityArray = (items) => {
|
|
1268
|
+
const array = new ReactiveArray();
|
|
1269
|
+
for (const item of items) array[array.length] = item;
|
|
1270
|
+
defineHiddenProperty(array, EntityElementsId, true);
|
|
1271
|
+
return array;
|
|
1272
|
+
};
|
|
1176
1273
|
/**
|
|
1177
1274
|
* Copy hidden properties (SchemaId, SchemaAstId, TypeId) from source to target.
|
|
1178
1275
|
*/
|
|
@@ -1182,11 +1279,23 @@ var copyHiddenProperties = (source, target) => {
|
|
|
1182
1279
|
if (TypeId in source) defineHiddenProperty(target, TypeId, source[TypeId]);
|
|
1183
1280
|
};
|
|
1184
1281
|
/**
|
|
1185
|
-
*
|
|
1282
|
+
* Node inspector for typed targets. Forces `showHidden: false` so a target's hidden metadata, including its owner and
|
|
1283
|
+
* through it unrelated fields of the root, never prints.
|
|
1284
|
+
*/
|
|
1285
|
+
function inspectTypedTarget(_depth, options, inspectFn) {
|
|
1286
|
+
return `Typed ${inspectFn(getRawTarget(this), {
|
|
1287
|
+
...options,
|
|
1288
|
+
showHidden: false,
|
|
1289
|
+
customInspect: false
|
|
1290
|
+
})}`;
|
|
1291
|
+
}
|
|
1292
|
+
/**
|
|
1293
|
+
* Behaviour prototype for typed reactive records. A root's per-object metadata is moved onto an
|
|
1186
1294
|
* intermediate instance-state object whose prototype is this, so that swapping the handler that
|
|
1187
1295
|
* backs an object (e.g. an in-memory object becoming database-backed) is a prototype re-point that
|
|
1188
|
-
* doesn't perturb the target's own-property shape.
|
|
1189
|
-
*
|
|
1296
|
+
* doesn't perturb the target's own-property shape. A nested record never swaps handler, so it points
|
|
1297
|
+
* here directly and keeps its metadata as own properties. Marked as a reactive prototype so the
|
|
1298
|
+
* "plain object" gates (`isValidProxyTarget` / `deepCopy`) still treat such targets as data records.
|
|
1190
1299
|
*/
|
|
1191
1300
|
var TypedObjectPrototype = Object.create(Object.prototype);
|
|
1192
1301
|
defineHiddenProperty(TypedObjectPrototype, symbolReactivePrototype, true);
|
|
@@ -1207,6 +1316,7 @@ Object.defineProperties(TypedObjectPrototype, {
|
|
|
1207
1316
|
const target = getRawTarget(this);
|
|
1208
1317
|
return isEntity(target) ? (that) => isEntity(that) && that.id === target.id : (that) => getRawTarget(that) === target;
|
|
1209
1318
|
} },
|
|
1319
|
+
[inspectCustom]: { value: inspectTypedTarget },
|
|
1210
1320
|
[StaticTypeSchemaSlot]: { get() {
|
|
1211
1321
|
const target = getRawTarget(this);
|
|
1212
1322
|
const jsonSchema = target.jsonSchema;
|
|
@@ -1237,6 +1347,17 @@ var compactMetadataToInstanceState = (target) => {
|
|
|
1237
1347
|
Object.setPrototypeOf(target, state);
|
|
1238
1348
|
};
|
|
1239
1349
|
/**
|
|
1350
|
+
* Point a nested record straight at {@link TypedObjectPrototype}, keeping its metadata as own properties.
|
|
1351
|
+
*
|
|
1352
|
+
* Unlike {@link compactMetadataToInstanceState} this keeps the record in V8's fast-property mode: deleting the moved
|
|
1353
|
+
* properties would turn the target into a dictionary, and so would making the per-record state a prototype. Both
|
|
1354
|
+
* cost ~0.5 KiB a record, which for an object holding JSON Schema (one record per schema node) is most of its heap.
|
|
1355
|
+
*/
|
|
1356
|
+
var shareTypedObjectPrototype = (target) => {
|
|
1357
|
+
if (Array.isArray(target) || Object.getPrototypeOf(target) !== Object.prototype) return;
|
|
1358
|
+
Object.setPrototypeOf(target, TypedObjectPrototype);
|
|
1359
|
+
};
|
|
1360
|
+
/**
|
|
1240
1361
|
* Typed in-memory reactive store (with Schema).
|
|
1241
1362
|
* Reactivity is based on Event subscriptions, not signals.
|
|
1242
1363
|
*/
|
|
@@ -1249,13 +1370,13 @@ var TypedReactiveHandler = class TypedReactiveHandler {
|
|
|
1249
1370
|
invariant(SchemaId in target || SchemaAstId in target, "Schema is not defined for the target", {
|
|
1250
1371
|
"~LogMeta": "~LogMeta",
|
|
1251
1372
|
F: __dxlog_file$7,
|
|
1252
|
-
L:
|
|
1373
|
+
L: 375,
|
|
1253
1374
|
S: this,
|
|
1254
1375
|
A: ["SchemaId in target || SchemaAstId in target", "'Schema is not defined for the target'"]
|
|
1255
1376
|
});
|
|
1256
1377
|
const hasOwner = !!getOwner(target);
|
|
1257
1378
|
if (!(EventId in target) && !hasOwner) defineHiddenProperty(target, EventId, new Event());
|
|
1258
|
-
if (!(ObjectDeletedId in target)) defineHiddenProperty(target, ObjectDeletedId, false);
|
|
1379
|
+
if (!hasOwner && !(ObjectDeletedId in target)) defineHiddenProperty(target, ObjectDeletedId, false);
|
|
1259
1380
|
if (!hasOwner) for (const key in target) {
|
|
1260
1381
|
if (isProxy(target)) continue;
|
|
1261
1382
|
let value = target[key];
|
|
@@ -1267,12 +1388,9 @@ var TypedReactiveHandler = class TypedReactiveHandler {
|
|
|
1267
1388
|
setOwnerRecursive(value, target);
|
|
1268
1389
|
}
|
|
1269
1390
|
}
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
value: this._inspect.bind(target)
|
|
1274
|
-
});
|
|
1275
|
-
compactMetadataToInstanceState(target);
|
|
1391
|
+
if (Array.isArray(target)) defineHiddenProperty(target, inspectCustom, inspectTypedTarget);
|
|
1392
|
+
else if (hasOwner) shareTypedObjectPrototype(target);
|
|
1393
|
+
else compactMetadataToInstanceState(target);
|
|
1276
1394
|
this._wrapNestedValues(target);
|
|
1277
1395
|
}
|
|
1278
1396
|
/**
|
|
@@ -1354,7 +1472,7 @@ var TypedReactiveHandler = class TypedReactiveHandler {
|
|
|
1354
1472
|
invariant(keyPath.length > 0, "Text path must be non-empty", {
|
|
1355
1473
|
"~LogMeta": "~LogMeta",
|
|
1356
1474
|
F: __dxlog_file$7,
|
|
1357
|
-
L:
|
|
1475
|
+
L: 546,
|
|
1358
1476
|
S: this,
|
|
1359
1477
|
A: ["keyPath.length > 0", "'Text path must be non-empty'"]
|
|
1360
1478
|
});
|
|
@@ -1377,6 +1495,19 @@ var TypedReactiveHandler = class TypedReactiveHandler {
|
|
|
1377
1495
|
echoRoot,
|
|
1378
1496
|
preparedValue: value
|
|
1379
1497
|
};
|
|
1498
|
+
if (hasEntityElements(target)) return {
|
|
1499
|
+
echoRoot,
|
|
1500
|
+
preparedValue: this._validateValue(target, prop, value)
|
|
1501
|
+
};
|
|
1502
|
+
if (Array.isArray(value) && isEntityArrayAst(SchemaValidator.getTargetPropertyAst(target, prop))) {
|
|
1503
|
+
const entities = toEntityArray(value);
|
|
1504
|
+
const validated = this._validateValue(target, prop, entities);
|
|
1505
|
+
setOwnerRecursive(validated, echoRoot);
|
|
1506
|
+
return {
|
|
1507
|
+
echoRoot,
|
|
1508
|
+
preparedValue: createProxy(validated, this)
|
|
1509
|
+
};
|
|
1510
|
+
}
|
|
1380
1511
|
if (isValidProxyTarget(value) || isProxy(value)) {
|
|
1381
1512
|
if (wouldCreateCycle(echoRoot, value)) throw new Error("Cannot create cycles in typed object graph. Consider using Ref for circular references.");
|
|
1382
1513
|
}
|
|
@@ -1405,13 +1536,6 @@ var TypedReactiveHandler = class TypedReactiveHandler {
|
|
|
1405
1536
|
if (isValidProxyTarget(value)) setNestedSchema(value, ast);
|
|
1406
1537
|
return value;
|
|
1407
1538
|
}
|
|
1408
|
-
_inspect(_, options, inspectFn) {
|
|
1409
|
-
return `Typed ${inspectFn(this, {
|
|
1410
|
-
...options,
|
|
1411
|
-
showHidden: false,
|
|
1412
|
-
customInspect: false
|
|
1413
|
-
})}`;
|
|
1414
|
-
}
|
|
1415
1539
|
};
|
|
1416
1540
|
/**
|
|
1417
1541
|
* Stamps a root target with its schema, and each nested proxy target below it with the AST it follows.
|
|
@@ -1444,6 +1568,7 @@ var setNestedSchema = (obj, ast) => {
|
|
|
1444
1568
|
setChildSchemas(obj, ast);
|
|
1445
1569
|
};
|
|
1446
1570
|
var setChildSchemas = (obj, ast) => {
|
|
1571
|
+
if (hasEntityElements(obj)) return;
|
|
1447
1572
|
if (Array.isArray(obj)) {
|
|
1448
1573
|
for (let index = 0; index < obj.length; index++) if (isValidProxyTarget(obj[index])) setNestedSchema(obj[index], SchemaValidator.getIndexedElementAst(ast, index) ?? Schema.Any.ast);
|
|
1449
1574
|
return;
|
|
@@ -1473,8 +1598,17 @@ var validateAndReactifyTarget = (target, schema, options) => {
|
|
|
1473
1598
|
assertsWithDetail(schema, target);
|
|
1474
1599
|
SchemaValidator.assertExactProperties(schema.ast, target, (path) => getDeep(target, path));
|
|
1475
1600
|
}
|
|
1601
|
+
markEntityArrays(target, schema.ast);
|
|
1476
1602
|
makeArraysReactive(target);
|
|
1477
1603
|
};
|
|
1604
|
+
/** Marks the target's top-level entity-array properties (e.g. `meta.tags`) as held by identity. */
|
|
1605
|
+
var markEntityArrays = (target, ast) => {
|
|
1606
|
+
if (!SchemaAST.isObjects(ast)) return;
|
|
1607
|
+
for (const property of ast.propertySignatures) {
|
|
1608
|
+
const value = target[property.name];
|
|
1609
|
+
if (Array.isArray(value) && !hasEntityElements(value) && isEntityArrayAst(property.type)) target[property.name] = toEntityArray(value);
|
|
1610
|
+
}
|
|
1611
|
+
};
|
|
1478
1612
|
/**
|
|
1479
1613
|
* Like {@link prepareTypedTarget}, for a target whose own `SchemaId`/`TypeId` are already stamped
|
|
1480
1614
|
* and locked `configurable: false` — e.g. an object decoded from JSON via `setSchema`/`setTypename`
|
|
@@ -1497,6 +1631,7 @@ var makeArraysReactive = (target) => {
|
|
|
1497
1631
|
for (const key in target) {
|
|
1498
1632
|
const value = target[key];
|
|
1499
1633
|
if (value == null || typeof value !== "object" || isProxy(value)) continue;
|
|
1634
|
+
if (hasEntityElements(value)) continue;
|
|
1500
1635
|
if (Array.isArray(value) && !(value instanceof ReactiveArray)) target[key] = ReactiveArray.from(value);
|
|
1501
1636
|
makeArraysReactive(target[key]);
|
|
1502
1637
|
}
|
|
@@ -2050,15 +2185,22 @@ var objectFromJSON = async (jsonData, { refResolver, uri, database, parent } = {
|
|
|
2050
2185
|
defineHiddenProperty(obj, KindId, annotationKind === EntityKind.Type ? EntityKind.Type : EntityKind.Object);
|
|
2051
2186
|
}
|
|
2052
2187
|
if (typeof jsonData["@meta"] === "object") {
|
|
2053
|
-
const
|
|
2188
|
+
const { tags: encodedTags, ...encodedMeta } = normalizeMeta(jsonData[ATTR_META]);
|
|
2189
|
+
const meta = await Schema.decodeUnknownPromise(EntityMetaSchema)({
|
|
2190
|
+
...encodedMeta,
|
|
2191
|
+
tags: []
|
|
2192
|
+
});
|
|
2054
2193
|
invariant(Array.isArray(meta.keys), void 0, {
|
|
2055
2194
|
"~LogMeta": "~LogMeta",
|
|
2056
2195
|
F: __dxlog_file$3,
|
|
2057
|
-
L:
|
|
2196
|
+
L: 159,
|
|
2058
2197
|
S: void 0,
|
|
2059
2198
|
A: ["Array.isArray(meta.keys)", ""]
|
|
2060
2199
|
});
|
|
2061
|
-
defineHiddenProperty(obj, MetaId,
|
|
2200
|
+
defineHiddenProperty(obj, MetaId, {
|
|
2201
|
+
...meta,
|
|
2202
|
+
tags: await resolveTags(encodedTags, refResolver)
|
|
2203
|
+
});
|
|
2062
2204
|
} else defineHiddenProperty(obj, MetaId, {
|
|
2063
2205
|
keys: [],
|
|
2064
2206
|
tags: [],
|
|
@@ -2076,55 +2218,63 @@ var objectFromJSON = async (jsonData, { refResolver, uri, database, parent } = {
|
|
|
2076
2218
|
invariant(obj[ATTR_TYPE] === void 0, "Invalid object model", {
|
|
2077
2219
|
"~LogMeta": "~LogMeta",
|
|
2078
2220
|
F: __dxlog_file$3,
|
|
2079
|
-
L:
|
|
2221
|
+
L: 190,
|
|
2080
2222
|
S: void 0,
|
|
2081
2223
|
A: ["(obj as any)[ATTR_TYPE] === undefined", "'Invalid object model'"]
|
|
2082
2224
|
});
|
|
2083
2225
|
invariant(obj[ATTR_META] === void 0, "Invalid object model", {
|
|
2084
2226
|
"~LogMeta": "~LogMeta",
|
|
2085
2227
|
F: __dxlog_file$3,
|
|
2086
|
-
L:
|
|
2228
|
+
L: 191,
|
|
2087
2229
|
S: void 0,
|
|
2088
2230
|
A: ["(obj as any)[ATTR_META] === undefined", "'Invalid object model'"]
|
|
2089
2231
|
});
|
|
2090
2232
|
invariant(obj[ATTR_DELETED] === void 0, "Invalid object model", {
|
|
2091
2233
|
"~LogMeta": "~LogMeta",
|
|
2092
2234
|
F: __dxlog_file$3,
|
|
2093
|
-
L:
|
|
2235
|
+
L: 192,
|
|
2094
2236
|
S: void 0,
|
|
2095
2237
|
A: ["(obj as any)[ATTR_DELETED] === undefined", "'Invalid object model'"]
|
|
2096
2238
|
});
|
|
2097
2239
|
invariant(obj[ATTR_SELF_URI] === void 0, "Invalid object model", {
|
|
2098
2240
|
"~LogMeta": "~LogMeta",
|
|
2099
2241
|
F: __dxlog_file$3,
|
|
2100
|
-
L:
|
|
2242
|
+
L: 193,
|
|
2101
2243
|
S: void 0,
|
|
2102
2244
|
A: ["(obj as any)[ATTR_SELF_URI] === undefined", "'Invalid object model'"]
|
|
2103
2245
|
});
|
|
2104
2246
|
invariant(obj[ATTR_SELF_URI_LEGACY] === void 0, "Invalid object model", {
|
|
2105
2247
|
"~LogMeta": "~LogMeta",
|
|
2106
2248
|
F: __dxlog_file$3,
|
|
2107
|
-
L:
|
|
2249
|
+
L: 194,
|
|
2108
2250
|
S: void 0,
|
|
2109
2251
|
A: ["(obj as any)[ATTR_SELF_URI_LEGACY] === undefined", "'Invalid object model'"]
|
|
2110
2252
|
});
|
|
2111
2253
|
invariant(obj[ATTR_RELATION_SOURCE] === void 0, "Invalid object model", {
|
|
2112
2254
|
"~LogMeta": "~LogMeta",
|
|
2113
2255
|
F: __dxlog_file$3,
|
|
2114
|
-
L:
|
|
2256
|
+
L: 195,
|
|
2115
2257
|
S: void 0,
|
|
2116
2258
|
A: ["(obj as any)[ATTR_RELATION_SOURCE] === undefined", "'Invalid object model'"]
|
|
2117
2259
|
});
|
|
2118
2260
|
invariant(obj[ATTR_RELATION_TARGET] === void 0, "Invalid object model", {
|
|
2119
2261
|
"~LogMeta": "~LogMeta",
|
|
2120
2262
|
F: __dxlog_file$3,
|
|
2121
|
-
L:
|
|
2263
|
+
L: 196,
|
|
2122
2264
|
S: void 0,
|
|
2123
2265
|
A: ["(obj as any)[ATTR_RELATION_TARGET] === undefined", "'Invalid object model'"]
|
|
2124
2266
|
});
|
|
2125
2267
|
return obj;
|
|
2126
2268
|
};
|
|
2127
2269
|
/**
|
|
2270
|
+
* Resolves the encoded tag references of a serialized meta to {@link Tag} entities. A tag the
|
|
2271
|
+
* resolver cannot supply is dropped, as an unresolved parent is: `meta.tags` holds entities only.
|
|
2272
|
+
*/
|
|
2273
|
+
var resolveTags = async (encodedTags, refResolver) => {
|
|
2274
|
+
if (refResolver == null || encodedTags.length === 0) return [];
|
|
2275
|
+
return (await Promise.all(encodedTags.map((tag) => isEncodedReference(tag) ? refResolver.resolveLegacy(URI.make(tag["/"])) : void 0))).filter(isTagEntity);
|
|
2276
|
+
};
|
|
2277
|
+
/**
|
|
2128
2278
|
* Backfills required meta fields and upgrades legacy `tags` (bare URI strings) to encoded references
|
|
2129
2279
|
* so serialized data produced before the tags-as-refs migration still decodes.
|
|
2130
2280
|
*/
|
|
@@ -2431,7 +2581,7 @@ var filterMatchEntity = makeFilterMatcher({
|
|
|
2431
2581
|
version: meta.version,
|
|
2432
2582
|
annotations: meta.annotations,
|
|
2433
2583
|
get tags() {
|
|
2434
|
-
return meta.tags.map((tag) =>
|
|
2584
|
+
return meta.tags.map((tag) => tag.id);
|
|
2435
2585
|
}
|
|
2436
2586
|
};
|
|
2437
2587
|
},
|
|
@@ -3002,12 +3152,14 @@ var makeLabelAtom = (entity) => {
|
|
|
3002
3152
|
return labelAtomFamily(entity);
|
|
3003
3153
|
};
|
|
3004
3154
|
var readTags = (entity) => [...getMeta(entity).tags];
|
|
3155
|
+
/** Tags are entities held by identity, so the list is unchanged while every element is the same entity. */
|
|
3156
|
+
var sameTags = (next, previous) => next.length === previous.length && next.every((tag, index) => tag === previous[index]);
|
|
3005
3157
|
var tagsAtomFamily = Atom.family((entity) => {
|
|
3006
3158
|
return Atom.make((get) => {
|
|
3007
3159
|
let previous = readTags(entity);
|
|
3008
3160
|
const unsubscribe = subscribe(entity, () => {
|
|
3009
3161
|
const next = readTags(entity);
|
|
3010
|
-
if (!
|
|
3162
|
+
if (!sameTags(next, previous)) {
|
|
3011
3163
|
previous = next;
|
|
3012
3164
|
get.setSelf(next);
|
|
3013
3165
|
}
|
|
@@ -3168,6 +3320,6 @@ var TypeSchema = Schema.Struct({
|
|
|
3168
3320
|
hue: "green"
|
|
3169
3321
|
}), EchoTypeKindSchema(TypeMetaSchemaDXN));
|
|
3170
3322
|
//#endregion
|
|
3171
|
-
export { validateAndReactifyTarget as $, objectToJSON as A,
|
|
3323
|
+
export { validateAndReactifyTarget as $, objectToJSON as A, sort as At, EchoRelationSchema as B, filterMatchValue as C, typedJsonSerializer as Ct, objectFromJSON as D, prettyQuery as Dt, matchesTag as E, prettyFilter as Et, encodeVersion as F, isProjection as Ft, normalizeSchema as G, makeRelationType as H, isVersion as I, makeProjection as It, makeDecodedEntityLive as J, TypeMetaSchemaDXN as K, version as L, RawObject as Lt, resolveMergeRedirect as M, sortByTypename as Mt, compareVersions as N, VersionTypeId as Nt, objectStructureFromJson as O, assertObjectModel as Ot, decodeVersion as P, ProjectionTypeId as Pt, prepareTypedTarget as Q, versionValid as R, filterMatchEntity as S, attachTypedJsonSerializer as St, matchMetaKey as T, getStrongDependencyUris as Tt, EchoObjectSchema as U, getDXNForRelationSchemaRef as V, makeObjectType as W, TypedReactiveHandler as X, makeObject as Y, prepareDecodedTypedTarget as Z, propagateParentAnnotations as _, batchEvents as _t, updateFieldsInSchema as a, ReactiveArray as at, makeTypedEntityClass as b, beginCommit as bt, makeEntity as c, assertMutable as ct, makeProperty as d, executeChange as dt, SchemaValidator as et, makeRelation as f, hasPendingNotifications as ft, setValue as g, queueOwnerNotification as gt, getSnapshot as h, queueNotification as ht, updateFieldNameInSchema as i, isPlainRecord as it, setRefResolverOnData as j, sortByLabel as jt, objectStructureToJson as k, compare as kt, makeLabelAtom as l, clearPendingNotifications as lt, makeWithReactive as m, isInChangeContext as mt, addFieldsToSchema as n, checkIdNotPresentOnSchema as nt, clone as o, getEchoRoot as ot, makeTagsAtom as p, isAnyChangeContextActive as pt, makeEchoTypeSchema as q, removeFieldsFromSchema as r, isEntityArrayAst as rt, makeAtom as s, setMetaOwner as st, TypeSchema as t, assertsWithDetail as tt, makeParentAtom as u, enterChangeContext as ut, isDeleted as v, emitEvent as vt, makeFilterMatcher as w, getStrongDependencies as wt, compareTypenameStrings as x, runInCommit as xt, createObject as y, afterCommit as yt, EchoTypeKindSchema as z };
|
|
3172
3324
|
|
|
3173
3325
|
//# sourceMappingURL=chunk-internal.mjs.map
|