jazz-tools 0.7.0-alpha.1 → 0.7.0-alpha.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. package/.turbo/turbo-build.log +79 -9
  2. package/CHANGELOG.md +68 -0
  3. package/dist/coValues/account.js +63 -30
  4. package/dist/coValues/account.js.map +1 -1
  5. package/dist/coValues/coList.js +143 -93
  6. package/dist/coValues/coList.js.map +1 -1
  7. package/dist/coValues/coMap.js +145 -159
  8. package/dist/coValues/coMap.js.map +1 -1
  9. package/dist/coValues/coStream.js +140 -66
  10. package/dist/coValues/coStream.js.map +1 -1
  11. package/dist/coValues/extensions/imageDef.js +9 -11
  12. package/dist/coValues/extensions/imageDef.js.map +1 -1
  13. package/dist/coValues/group.js +14 -39
  14. package/dist/coValues/group.js.map +1 -1
  15. package/dist/coValues/interfaces.js +6 -3
  16. package/dist/coValues/interfaces.js.map +1 -1
  17. package/dist/implementation/refs.js +13 -10
  18. package/dist/implementation/refs.js.map +1 -1
  19. package/dist/implementation/schema.js +36 -1
  20. package/dist/implementation/schema.js.map +1 -1
  21. package/dist/index.js +4 -19
  22. package/dist/index.js.map +1 -1
  23. package/dist/tests/coList.test.js +5 -9
  24. package/dist/tests/coList.test.js.map +1 -1
  25. package/dist/tests/coMap.test.js +107 -61
  26. package/dist/tests/coMap.test.js.map +1 -1
  27. package/dist/tests/coStream.test.js +51 -56
  28. package/dist/tests/coStream.test.js.map +1 -1
  29. package/package.json +2 -2
  30. package/src/coValues/account.ts +94 -64
  31. package/src/coValues/coList.ts +186 -115
  32. package/src/coValues/coMap.ts +226 -260
  33. package/src/coValues/coStream.ts +190 -111
  34. package/src/coValues/extensions/imageDef.ts +12 -16
  35. package/src/coValues/group.ts +27 -75
  36. package/src/coValues/interfaces.ts +9 -7
  37. package/src/implementation/refs.ts +43 -18
  38. package/src/implementation/schema.ts +86 -31
  39. package/src/index.ts +10 -25
  40. package/src/tests/coList.test.ts +5 -9
  41. package/src/tests/coMap.test.ts +86 -74
  42. package/src/tests/coStream.test.ts +66 -71
@@ -1,44 +1,41 @@
1
1
  import type { JsonValue, RawCoMap } from "cojson";
2
2
  import type { Simplify } from "effect/Types";
3
- import { Schema } from "@effect/schema";
3
+ import { Schema as EffectSchema } from "@effect/schema";
4
4
  import type {
5
5
  CoValue,
6
- Encoder,
7
- FieldDescriptor,
8
- FieldDescriptorFor,
6
+ Schema,
7
+ SchemaFor,
9
8
  Group,
10
9
  ID,
11
- RefField,
10
+ RefEncoded,
12
11
  EnsureCoValueNullable,
13
- CoValueClass,
12
+ IfCo,
14
13
  } from "../internal.js";
15
14
  import {
16
15
  Account,
17
16
  CoValueBase,
18
- ValueRef,
17
+ Ref,
18
+ SchemaInit,
19
19
  inspect,
20
20
  makeRefs,
21
21
  subscriptionsScopes,
22
- indexSignature,
22
+ ItemsSym,
23
+ InitValues,
24
+ isRefEncoded,
23
25
  } from "../internal.js";
24
26
 
25
- type EnsureValid<
26
- Fields extends { [key: string]: any; [indexSignature]?: any },
27
- > = {
28
- [Key in OwnKeys<Fields> as IfOptionalKey<
29
- Key,
30
- Fields
27
+ type ValidFields<Fields extends { [key: string]: any; [ItemsSym]?: any }> = {
28
+ [Key in keyof Fields & string as IfCo<
29
+ Fields[Key],
30
+ IfOptionalKey<Key, Fields>
31
31
  >]?: EnsureCoValueNullable<Fields[Key], Key>;
32
32
  } & {
33
- [Key in OwnKeys<Fields> as IfRequiredKey<
34
- Key,
35
- Fields
33
+ [Key in keyof Fields & string as IfCo<
34
+ Fields[Key],
35
+ IfRequiredKey<Key, Fields>
36
36
  >]: EnsureCoValueNullable<Fields[Key], Key>;
37
37
  } & {
38
- [Key in indexSignature]?: EnsureCoValueNullable<
39
- Fields[indexSignature],
40
- Key
41
- >;
38
+ [Key in ItemsSym]?: EnsureCoValueNullable<Fields[ItemsSym], Key>;
42
39
  };
43
40
 
44
41
  type IfOptionalKey<Key extends keyof Obj, Obj> = Pick<
@@ -56,36 +53,53 @@ type IfRequiredKey<Key extends keyof Obj, Obj> = Pick<
56
53
 
57
54
  type DefaultFields = {
58
55
  [key: string]: any;
59
- [indexSignature]?: any;
56
+ [ItemsSym]?: any;
57
+ };
58
+
59
+ type CoMapSchema<Fields extends object> = {
60
+ [Key in OwnKeys<Fields> as IfCo<Fields[Key], Key>]: SchemaFor<
61
+ Fields[Key]
62
+ >;
63
+ } & {
64
+ [ItemsSym]: ItemsSym extends keyof Fields
65
+ ? SchemaFor<Fields[ItemsSym]>
66
+ : never;
67
+ };
68
+
69
+ type CoMapEdit<V> = {
70
+ value?: V;
71
+ ref?: V extends CoValue ? Ref<V> : never;
72
+ by?: Account;
73
+ madeAt: Date;
60
74
  };
61
75
 
62
- export class CoMap<Fields extends EnsureValid<Fields> = DefaultFields>
76
+ type InitValuesFor<C extends CoMap> = {
77
+ init: Simplify<CoMapInit<C>>;
78
+ owner: Account | Group;
79
+ };
80
+
81
+ export class CoMap<Fields extends ValidFields<Fields> = DefaultFields>
63
82
  extends CoValueBase
64
83
  implements CoValue<"CoMap", RawCoMap>
65
84
  {
66
- id!: ID<this>;
67
- _type!: "CoMap";
85
+ declare id: ID<this>;
86
+ declare _type: "CoMap";
68
87
  static {
69
88
  this.prototype._type = "CoMap";
70
89
  }
71
- _raw!: RawCoMap;
90
+ declare _raw: RawCoMap;
72
91
 
73
92
  static _schema: any;
74
- get _schema(): {
75
- [Key in OwnKeys<Fields>]: FieldDescriptorFor<Fields[Key]>;
76
- } & {
77
- [indexSignature]: indexSignature extends keyof Fields
78
- ? FieldDescriptorFor<Fields[indexSignature]>
79
- : never;
80
- } {
81
- return (this.constructor as typeof CoMap)._schema;
93
+ get _schema() {
94
+ return (this.constructor as typeof CoMap)
95
+ ._schema as CoMapSchema<this>;
82
96
  }
83
97
 
84
98
  get _refs(): {
85
- [Key in OwnKeys<Fields> as NonNullable<Fields[Key]> extends CoValue
99
+ [Key in OwnKeys<this> as NonNullable<this[Key]> extends CoValue
86
100
  ? Key
87
- : never]: NonNullable<Fields[Key]> extends CoValue
88
- ? ValueRef<NonNullable<Fields[Key]>>
101
+ : never]: NonNullable<this[Key]> extends CoValue
102
+ ? Ref<NonNullable<this[Key]>>
89
103
  : never;
90
104
  } {
91
105
  return makeRefs<OwnKeys<Fields>>(
@@ -94,22 +108,15 @@ export class CoMap<Fields extends EnsureValid<Fields> = DefaultFields>
94
108
  Object.keys(this._schema).filter((key) => {
95
109
  const schema = this._schema[
96
110
  key as keyof typeof this._schema
97
- ] as FieldDescriptor;
98
- schema !== "json" && "ref" in schema;
111
+ ] as Schema;
112
+ schema !== "json" && isRefEncoded(schema);
99
113
  }) as OwnKeys<Fields>[],
100
114
  this._loadedAs,
101
- (key) => (this._schema[key] as RefField<CoValue>).ref()
115
+ (key) => this._schema[key] as RefEncoded<CoValue>
102
116
  ) as any;
103
117
  }
104
118
 
105
- get _edits(): {
106
- [Key in OwnKeys<Fields>]: {
107
- value?: Fields[Key];
108
- ref?: Fields[Key] extends CoValue ? ValueRef<Fields[Key]> : never;
109
- by?: Account;
110
- madeAt: Date;
111
- };
112
- } {
119
+ get _edits() {
113
120
  return new Proxy(this, {
114
121
  get(target, key) {
115
122
  const rawEdit = target._raw.lastEditAt(key as string);
@@ -117,32 +124,32 @@ export class CoMap<Fields extends EnsureValid<Fields> = DefaultFields>
117
124
 
118
125
  const descriptor = target._schema[
119
126
  key as keyof typeof target._schema
120
- ] as FieldDescriptor;
127
+ ] as Schema;
121
128
 
122
129
  return {
123
130
  value:
124
131
  descriptor === "json"
125
132
  ? rawEdit.value
126
133
  : "encoded" in descriptor
127
- ? Schema.decodeSync(descriptor.encoded)(
134
+ ? EffectSchema.decodeSync(descriptor.encoded)(
128
135
  rawEdit.value
129
136
  )
130
- : new ValueRef(
137
+ : new Ref(
131
138
  rawEdit.value as ID<CoValue>,
132
139
  target._loadedAs,
133
- descriptor.ref()
140
+ descriptor
134
141
  ).accessFrom(target),
135
142
  ref:
136
- descriptor !== "json" && "ref" in descriptor
137
- ? new ValueRef(
143
+ descriptor !== "json" && isRefEncoded(descriptor)
144
+ ? new Ref(
138
145
  rawEdit.value as ID<CoValue>,
139
146
  target._loadedAs,
140
- descriptor.ref()
147
+ descriptor
141
148
  )
142
149
  : undefined,
143
150
  by:
144
151
  rawEdit.by &&
145
- new ValueRef(
152
+ new Ref(
146
153
  rawEdit.by as ID<Account>,
147
154
  target._loadedAs,
148
155
  Account
@@ -150,13 +157,19 @@ export class CoMap<Fields extends EnsureValid<Fields> = DefaultFields>
150
157
  madeAt: rawEdit.at,
151
158
  };
152
159
  },
153
- }) as any;
160
+ }) as {
161
+ [Key in OwnKeys<this> as IfCo<this[Key], Key>]: CoMapEdit<
162
+ this[Key]
163
+ >;
164
+ };
154
165
  }
155
166
 
156
167
  get _loadedAs() {
157
168
  return Account.fromNode(this._raw.core.node);
158
169
  }
159
170
 
171
+ [InitValues]?: InitValuesFor<this>;
172
+
160
173
  constructor(_init: undefined, options: { fromRaw: RawCoMap });
161
174
  constructor(
162
175
  init: Simplify<CoMapInit<Fields>>,
@@ -168,39 +181,34 @@ export class CoMap<Fields extends EnsureValid<Fields> = DefaultFields>
168
181
  ) {
169
182
  super();
170
183
 
171
- if (!this._schema) {
172
- throw new Error(
173
- "No schema found in " +
174
- this.constructor.name +
175
- " - ensure that you have a `static { this.define({...}) }` block in the class definition."
176
- );
184
+ if (init && "owner" in options) {
185
+ this[InitValues] = {
186
+ init,
187
+ owner: options.owner,
188
+ } as InitValuesFor<this>;
189
+ } else if ("fromRaw" in options) {
190
+ Object.defineProperties(this, {
191
+ id: {
192
+ value: options.fromRaw.id as unknown as ID<this>,
193
+ enumerable: false,
194
+ },
195
+ _raw: { value: options.fromRaw, enumerable: false },
196
+ });
197
+ } else {
198
+ throw new Error("Invalid CoMap constructor arguments");
177
199
  }
178
200
 
179
- const raw: RawCoMap = this.rawFromInit<Fields>(options, init);
180
-
181
- Object.defineProperties(this, {
182
- id: {
183
- value: raw.id,
184
- enumerable: false,
185
- },
186
- _raw: { value: raw, enumerable: false },
187
- });
188
-
189
- this.definePropertiesFromSchema();
190
-
191
- if (this._schema[indexSignature]) {
192
- return new Proxy(this, CoMapProxyHandler<Fields>());
193
- }
201
+ return new Proxy(this, CoMapProxyHandler as ProxyHandler<this>);
194
202
  }
195
203
 
196
204
  toJSON() {
197
205
  const jsonedFields = this._raw.keys().map((key) => {
198
206
  const tKey = key as OwnKeys<Fields>;
199
- const descriptor = this._schema[tKey] as FieldDescriptor;
207
+ const descriptor = this._schema[tKey] as Schema;
200
208
 
201
209
  if (descriptor == "json" || "encode" in descriptor) {
202
210
  return [key, this._raw.get(key)];
203
- } else if ("ref" in descriptor) {
211
+ } else if (isRefEncoded(descriptor)) {
204
212
  const jsonedRef = (this as any)[tKey]?.toJSON();
205
213
  return [key, jsonedRef];
206
214
  } else {
@@ -220,144 +228,43 @@ export class CoMap<Fields extends EnsureValid<Fields> = DefaultFields>
220
228
  }
221
229
 
222
230
  rawFromInit<Fields extends object = Record<string, any>>(
223
- options: { owner: Account | Group } | { fromRaw: RawCoMap },
224
- init: Simplify<CoMapInit<Fields>> | undefined
231
+ init: Simplify<CoMapInit<Fields>> | undefined,
232
+ owner: Account | Group
225
233
  ) {
226
- let raw: RawCoMap;
234
+ const rawOwner = owner._raw;
227
235
 
228
- if ("fromRaw" in options) {
229
- raw = options.fromRaw;
230
- } else {
231
- const rawOwner = options.owner._raw;
236
+ const rawInit = {} as {
237
+ [key in keyof Fields]: JsonValue | undefined;
238
+ };
232
239
 
233
- const rawInit = {} as {
234
- [key in keyof Fields]: JsonValue | undefined;
235
- };
240
+ if (init)
241
+ for (const key of Object.keys(init) as (keyof Fields)[]) {
242
+ const initValue = init[key as keyof typeof init];
236
243
 
237
- if (init)
238
- for (const key of Object.keys(init) as (keyof Fields)[]) {
239
- const initValue = init[key as keyof typeof init];
244
+ const descriptor = (this._schema[
245
+ key as keyof typeof this._schema
246
+ ] || this._schema[ItemsSym]) as Schema;
240
247
 
241
- const descriptor = (this._schema[
242
- key as keyof typeof this._schema
243
- ] || this._schema[indexSignature]) as FieldDescriptor;
244
-
245
- if (descriptor === "json") {
246
- rawInit[key] = initValue as JsonValue;
247
- } else if ("ref" in descriptor) {
248
- if (initValue) {
249
- rawInit[key] = (initValue as unknown as CoValue).id;
250
- }
251
- } else if ("encoded" in descriptor) {
252
- rawInit[key] = Schema.encodeSync(descriptor.encoded)(
253
- initValue as any
254
- );
248
+ if (descriptor === "json") {
249
+ rawInit[key] = initValue as JsonValue;
250
+ } else if (isRefEncoded(descriptor)) {
251
+ if (initValue) {
252
+ rawInit[key] = (initValue as unknown as CoValue).id;
255
253
  }
254
+ } else if ("encoded" in descriptor) {
255
+ rawInit[key] = EffectSchema.encodeSync(descriptor.encoded)(
256
+ initValue as any
257
+ );
256
258
  }
257
-
258
- raw = rawOwner.createMap(rawInit);
259
- }
260
- return raw;
261
- }
262
-
263
- static encoding<V extends CoMap>(
264
- this: { new (...args: any): V } & typeof CoMap,
265
- fields: Simplify<{
266
- [Key in keyof V["_schema"] as V["_schema"][Key] extends never
267
- ? never
268
- : Key]: Simplify<V["_schema"][Key]>;
269
- }>
270
- ) {
271
- this._schema ||= {};
272
- Object.assign(this._schema, fields);
273
- }
274
-
275
- private definePropertiesFromSchema() {
276
- for (const [key, fieldSchema] of Object.entries(this._schema)) {
277
- if (key === "indexSignature") continue;
278
- const descriptor = fieldSchema as FieldDescriptor;
279
- if (descriptor === "json") {
280
- Object.defineProperty(
281
- this,
282
- key,
283
- this.primitivePropDef(key as string)
284
- );
285
- } else if ("encoded" in descriptor) {
286
- Object.defineProperty(
287
- this,
288
- key,
289
- this.encodedPropDef(key as string, descriptor.encoded)
290
- );
291
- } else if ("ref" in descriptor) {
292
- Object.defineProperty(
293
- this,
294
- key,
295
- this.refPropDef(
296
- key as string,
297
- (descriptor as RefField<CoValue>).ref
298
- )
299
- );
300
259
  }
301
- }
302
- }
303
-
304
- private primitivePropDef(key: string): PropertyDescriptor {
305
- return {
306
- get: () => {
307
- return this._raw.get(key);
308
- },
309
- set(this: CoMap, value: JsonValue) {
310
- this._raw.set(key, value);
311
- },
312
- enumerable: true,
313
- configurable: true,
314
- };
315
- }
316
260
 
317
- private encodedPropDef(key: string, arg: Encoder<any>): PropertyDescriptor {
318
- return {
319
- get: () => {
320
- const raw = this._raw.get(key);
321
- return raw === undefined
322
- ? undefined
323
- : Schema.decodeSync(arg)(raw);
324
- },
325
- set(this: CoMap, value: unknown) {
326
- this._raw.set(key, Schema.encodeSync(arg)(value));
327
- },
328
- enumerable: true,
329
- configurable: true,
330
- };
331
- }
332
-
333
- private refPropDef(
334
- key: string,
335
- ref: () => CoValueClass<CoValue>
336
- ): PropertyDescriptor {
337
- return {
338
- get: () => {
339
- const rawID = this._raw.get(key);
340
- return rawID === undefined
341
- ? undefined
342
- : new ValueRef(
343
- rawID as unknown as ID<CoValue>,
344
- this._loadedAs,
345
- ref()
346
- ).accessFrom(this);
347
- },
348
- set: (value: CoValue) => {
349
- this._raw.set(key, value.id);
350
- subscriptionsScopes.get(this)?.onRefAccessedOrSet(value.id);
351
- },
352
- enumerable: true,
353
- configurable: true,
354
- };
261
+ return rawOwner.createMap(rawInit);
355
262
  }
356
263
  }
357
264
 
358
265
  export type OwnKeys<Fields extends object> = Exclude<
359
266
  keyof Fields & string,
360
- keyof CoMap<Record<string, never>> | `_${string}`
267
+ keyof CoMap<Record<string, never>>
361
268
  >;
362
269
 
363
270
  export type CoMapInit<Fields extends object> = {
@@ -365,21 +272,44 @@ export type CoMapInit<Fields extends object> = {
365
272
  ? never
366
273
  : null extends Fields[Key]
367
274
  ? never
368
- : Key]: Fields[Key];
369
- } & { [Key in OwnKeys<Fields>]?: Fields[Key] };
275
+ : IfCo<Fields[Key], Key>]: Fields[Key];
276
+ } & { [Key in OwnKeys<Fields> as IfCo<Fields[Key], Key>]?: Fields[Key] };
277
+
278
+ function tryInit(map: CoMap) {
279
+ if (
280
+ map[InitValues] &&
281
+ (map._schema[ItemsSym] ||
282
+ Object.keys(map[InitValues].init).every(
283
+ (key) => (map._schema as any)[key]
284
+ ))
285
+ ) {
286
+ const raw = map.rawFromInit(
287
+ map[InitValues].init,
288
+ map[InitValues].owner
289
+ );
290
+ Object.defineProperties(map, {
291
+ id: {
292
+ value: raw.id,
293
+ enumerable: false,
294
+ },
295
+ _raw: { value: raw, enumerable: false },
296
+ });
297
+ delete map[InitValues];
298
+ }
299
+ }
370
300
 
371
301
  // TODO: cache handlers per descriptor for performance?
372
- function CoMapProxyHandler<Fields extends EnsureValid<Fields>>(): ProxyHandler<
373
- CoMap<Fields>
374
- > {
375
- return {
376
- get(target, key, receiver) {
377
- const descriptor = target._schema[
378
- indexSignature
379
- ] as FieldDescriptor;
380
- if (key in target || typeof key === "symbol") {
381
- return Reflect.get(target, key, receiver);
382
- } else {
302
+ const CoMapProxyHandler: ProxyHandler<CoMap> = {
303
+ get(target, key, receiver) {
304
+ if (key === "_schema") {
305
+ return Reflect.get(target, key);
306
+ } else if (key in target) {
307
+ return Reflect.get(target, key, receiver);
308
+ } else {
309
+ const descriptor = (target._schema[
310
+ key as keyof CoMap["_schema"]
311
+ ] || target._schema[ItemsSym]) as Schema;
312
+ if (descriptor && typeof key === "string") {
383
313
  const raw = target._raw.get(key);
384
314
 
385
315
  if (descriptor === "json") {
@@ -387,61 +317,97 @@ function CoMapProxyHandler<Fields extends EnsureValid<Fields>>(): ProxyHandler<
387
317
  } else if ("encoded" in descriptor) {
388
318
  return raw === undefined
389
319
  ? undefined
390
- : Schema.decodeSync(descriptor.encoded)(raw);
391
- } else if ("ref" in descriptor) {
320
+ : EffectSchema.decodeSync(descriptor.encoded)(raw);
321
+ } else if (isRefEncoded(descriptor)) {
392
322
  return raw === undefined
393
323
  ? undefined
394
- : new ValueRef(
324
+ : new Ref(
395
325
  raw as unknown as ID<CoValue>,
396
326
  target._loadedAs,
397
- descriptor.ref()
398
- ).accessFrom(target);
327
+ descriptor
328
+ ).accessFrom(receiver);
399
329
  }
400
- }
401
- },
402
- set(target, key, value, receiver) {
403
- const descriptor = target._schema[
404
- indexSignature
405
- ] as FieldDescriptor;
406
- if (key in target || typeof key === "symbol") {
407
- return Reflect.set(target, key, value, receiver);
408
330
  } else {
409
- if (descriptor === "json") {
410
- target._raw.set(key, value);
411
- } else if ("encoded" in descriptor) {
412
- target._raw.set(
413
- key,
414
- Schema.encodeSync(descriptor.encoded)(value)
415
- );
416
- } else if ("ref" in descriptor) {
417
- target._raw.set(key, value.id);
418
- subscriptionsScopes
419
- .get(target)
420
- ?.onRefAccessedOrSet(value.id);
421
- }
422
- return true;
331
+ return undefined;
423
332
  }
424
- },
425
- ownKeys(target) {
426
- const keys = Reflect.ownKeys(target);
427
- for (const key of target._raw.keys()) {
428
- if (!keys.includes(key)) {
429
- keys.push(key);
430
- }
333
+ }
334
+ },
335
+ set(target, key, value, receiver) {
336
+ if (
337
+ (typeof key === "string" || ItemsSym) &&
338
+ typeof value === "object" &&
339
+ SchemaInit in value
340
+ ) {
341
+ (target.constructor as typeof CoMap)._schema ||= {};
342
+ (target.constructor as typeof CoMap)._schema[key] =
343
+ value[SchemaInit];
344
+ tryInit(target);
345
+ return true;
346
+ }
347
+
348
+ const descriptor = (target._schema[key as keyof CoMap["_schema"]] ||
349
+ target._schema[ItemsSym]) as Schema;
350
+ if (descriptor && typeof key === "string") {
351
+ if (descriptor === "json") {
352
+ target._raw.set(key, value);
353
+ } else if ("encoded" in descriptor) {
354
+ target._raw.set(
355
+ key,
356
+ EffectSchema.encodeSync(descriptor.encoded)(value)
357
+ );
358
+ } else if (isRefEncoded(descriptor)) {
359
+ target._raw.set(key, value.id);
360
+ subscriptionsScopes.get(target)?.onRefAccessedOrSet(value.id);
431
361
  }
362
+ return true;
363
+ } else {
364
+ return Reflect.set(target, key, value, receiver);
365
+ }
366
+ },
367
+ defineProperty(target, key, attributes) {
368
+ if (
369
+ "value" in attributes &&
370
+ typeof attributes.value === "object" &&
371
+ SchemaInit in attributes.value
372
+ ) {
373
+ (target.constructor as typeof CoMap)._schema ||= {};
374
+ (target.constructor as typeof CoMap)._schema[key as string] =
375
+ attributes.value[SchemaInit];
376
+ tryInit(target);
377
+ return true;
378
+ } else {
379
+ return Reflect.defineProperty(target, key, attributes);
380
+ }
381
+ },
382
+ ownKeys(target) {
383
+ const keys = Reflect.ownKeys(target).filter((k) => k !== ItemsSym);
384
+ for (const key of Reflect.ownKeys(target._schema)) {
385
+ if (key !== ItemsSym && !keys.includes(key)) {
386
+ keys.push(key);
387
+ }
388
+ }
389
+ for (const key of target._raw.keys()) {
390
+ if (!keys.includes(key)) {
391
+ keys.push(key);
392
+ }
393
+ }
432
394
 
433
- return keys;
434
- },
435
- getOwnPropertyDescriptor(target, key) {
436
- if (key in target) {
437
- return Reflect.getOwnPropertyDescriptor(target, key);
438
- } else if (key in target._raw.ops) {
395
+ return keys;
396
+ },
397
+ getOwnPropertyDescriptor(target, key) {
398
+ if (key in target) {
399
+ return Reflect.getOwnPropertyDescriptor(target, key);
400
+ } else {
401
+ const descriptor = (target._schema[
402
+ key as keyof CoMap["_schema"]
403
+ ] || target._schema[ItemsSym]) as Schema;
404
+ if (descriptor || key in target._raw.ops) {
439
405
  return {
440
406
  enumerable: true,
441
407
  configurable: true,
442
408
  writable: true,
443
409
  };
444
410
  }
445
- },
446
- };
447
- }
411
+ }
412
+ },
413
+ };