@warp-drive/core 5.6.0 → 5.7.0-alpha.1

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.
@@ -3,7 +3,7 @@ import type { SchemaService as SchemaServiceInterface } from "../../types.js";
3
3
  import type { StableRecordIdentifier } from "../../types/identifier.js";
4
4
  import type { ObjectValue, Value } from "../../types/json/raw.js";
5
5
  import type { Derivation, HashFn } from "../../types/schema/concepts.js";
6
- import { type ArrayField, type DerivedField, type FieldSchema, type GenericField, type HashField, type LegacyAttributeField, type LegacyBelongsToField, type LegacyHasManyField, type LegacyRelationshipField, type ObjectField, type ObjectSchema, type PolarisResourceSchema, type ResourceSchema } from "../../types/schema/fields.js";
6
+ import { type ArrayField, type DerivedField, type FieldSchema, type GenericField, type HashField, type LegacyAttributeField, type LegacyBelongsToField, type LegacyHasManyField, type LegacyRelationshipField, type ObjectField, type ObjectSchema, type PolarisResourceSchema, type ResourceSchema, type Trait } from "../../types/schema/fields.js";
7
7
  import { Type } from "../../types/symbols.js";
8
8
  import type { WithPartial } from "../../types/utils.js";
9
9
  import type { ReactiveResource } from "./record.js";
@@ -138,6 +138,7 @@ export declare const fromIdentity: FromIdentityDerivation;
138
138
  export declare function registerDerivations(schema: SchemaServiceInterface): void;
139
139
  interface InternalSchema {
140
140
  original: ResourceSchema | ObjectSchema;
141
+ finalized: boolean;
141
142
  traits: Set<string>;
142
143
  fields: Map<string, FieldSchema>;
143
144
  attributes: Record<string, LegacyAttributeField>;
@@ -172,6 +173,12 @@ export interface SchemaService {
172
173
  type: string;
173
174
  }): InternalSchema["relationships"];
174
175
  }
176
+ interface InternalTrait {
177
+ name: string;
178
+ mode: "legacy" | "polaris";
179
+ fields: Map<string, FieldSchema>;
180
+ traits: string[];
181
+ }
175
182
  /**
176
183
  * A SchemaService designed to work with dynamically registered schemas.
177
184
  *
@@ -189,7 +196,7 @@ export declare class SchemaService implements SchemaServiceInterface {
189
196
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
190
197
  _derivations: Map<string, Derivation<any, any, any>>;
191
198
  /** @internal */
192
- _traits: Set<string>;
199
+ _traits: Map<string, InternalTrait>;
193
200
  /** @internal */
194
201
  _modes: Map<string, KindFns>;
195
202
  /** @internal */
@@ -221,6 +228,35 @@ export declare class SchemaService implements SchemaServiceInterface {
221
228
  }): ResourceSchema | ObjectSchema;
222
229
  registerResources(schemas: Array<ResourceSchema | ObjectSchema>): void;
223
230
  registerResource(schema: ResourceSchema | ObjectSchema): void;
231
+ /**
232
+ * Registers a {@link Trait} for use by resource schemas.
233
+ *
234
+ * Traits are re-usable collections of fields that can be composed to
235
+ * build up a resource schema. Often they represent polymorphic behaviors
236
+ * a resource should exhibit.
237
+ *
238
+ * When we finalize a resource, we walk its traits and apply their fields
239
+ * to the resource's fields. All specified traits must be registered by
240
+ * this time or an error will be thrown.
241
+ *
242
+ * Traits are applied left-to-right, with traits of traits being applied in the same
243
+ * way. Thus for the most part, application of traits is a post-order graph traversal
244
+ * problem.
245
+ *
246
+ * A trait is only ever processed once. If multiple traits (A, B, C) have the same
247
+ * trait (D) as a dependency, D will be included only once when first encountered by
248
+ * A.
249
+ *
250
+ * If a cycle exists such that trait A has trait B which has Trait A, trait A will
251
+ * be applied *after* trait B in production. In development a cycle error will be thrown.
252
+ *
253
+ * Fields are finalized on a "last wins principle". Thus traits appearing higher in
254
+ * the tree and further to the right of a traits array take precedence, with the
255
+ * resource's fields always being applied last and winning out.
256
+ *
257
+ * @public
258
+ */
259
+ registerTrait(trait: Trait): void;
224
260
  registerTransformation<
225
261
  T extends Value = string,
226
262
  PT = unknown
@@ -236,6 +272,10 @@ export declare class SchemaService implements SchemaServiceInterface {
236
272
  }): null | ProcessedExtension["features"];
237
273
  CAUTION_MEGA_DANGER_ZONE_objectExtensions(field: ExtensibleField): null | ProcessedExtension["features"];
238
274
  CAUTION_MEGA_DANGER_ZONE_arrayExtensions(field: ExtensibleField): null | ProcessedExtension["features"];
275
+ CAUTION_MEGA_DANGER_ZONE_hasExtension(ext: {
276
+ kind: "object" | "array";
277
+ name: string;
278
+ }): boolean;
239
279
  /**
240
280
  * This is an internal method used to register behaviors for legacy mode.
241
281
  * It is not intended for public use.
@@ -1,10 +1,8 @@
1
1
  import { ReactiveDocument } from "../../../reactive/-private/document.js";
2
2
  import type { Cache } from "../../../types/cache.js";
3
3
  import type { StableDocumentIdentifier, StableRecordIdentifier } from "../../../types/identifier.js";
4
- import type { Value } from "../../../types/json/raw.js";
5
4
  import type { TypedRecordInstance, TypeFromInstance } from "../../../types/record.js";
6
5
  import type { OpaqueRecordInstance } from "../../-types/q/record-instance.js";
7
- import RecordReference from "../legacy-model-support/record-reference.js";
8
6
  import { CacheCapabilitiesManager } from "../managers/cache-capabilities-manager.js";
9
7
  import type { CacheManager } from "../managers/cache-manager.js";
10
8
  import type { CreateRecordProperties, Store } from "../store-service.js";
@@ -36,9 +34,8 @@ export declare const StoreMap: Map<unknown, Store>;
36
34
  * @internal
37
35
  */
38
36
  export declare function storeFor(record: OpaqueRecordInstance): Store | undefined;
39
- type Caches = {
37
+ export type Caches = {
40
38
  record: Map<StableRecordIdentifier, OpaqueRecordInstance>;
41
- reference: WeakMap<StableRecordIdentifier, RecordReference>;
42
39
  document: Map<StableDocumentIdentifier, ReactiveDocument<OpaqueRecordInstance | OpaqueRecordInstance[] | null | undefined>>;
43
40
  };
44
41
  export declare class InstanceCache {
@@ -51,7 +48,6 @@ export declare class InstanceCache {
51
48
  peek(identifier: StableRecordIdentifier): Cache | OpaqueRecordInstance | undefined;
52
49
  getDocument<T>(identifier: StableDocumentIdentifier): ReactiveDocument<T>;
53
50
  getRecord(identifier: StableRecordIdentifier, properties?: CreateRecordProperties): OpaqueRecordInstance;
54
- getReference(identifier: StableRecordIdentifier): RecordReference;
55
51
  recordIsLoaded(identifier: StableRecordIdentifier, filterDeleted?: boolean): boolean;
56
52
  disconnect(identifier: StableRecordIdentifier): void;
57
53
  unloadRecord(identifier: StableRecordIdentifier): void;
@@ -59,7 +55,4 @@ export declare class InstanceCache {
59
55
  // TODO this should move into something coordinating operations
60
56
  setRecordId(identifier: StableRecordIdentifier, id: string): void;
61
57
  }
62
- export declare function resourceIsFullyDeleted(instanceCache: InstanceCache, identifier: StableRecordIdentifier): boolean;
63
- export declare function preloadData(store: Store, identifier: StableRecordIdentifier, preload: Record<string, Value>): void;
64
58
  export declare function _clearCaches(): void;
65
- export {};