@mearie/core 0.3.0 → 0.4.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/index.cjs CHANGED
@@ -501,18 +501,6 @@ const mergeFields = (target, source) => {
501
501
  const makeFieldKeyFromArgs = (field, args) => {
502
502
  return `${field}@${args && Object.keys(args).length > 0 ? stringify(args) : "{}"}`;
503
503
  };
504
- /**
505
- * Converts an EntityId to an EntityKey.
506
- * @internal
507
- * @param typename - The GraphQL typename of the entity.
508
- * @param id - The entity identifier (string, number, or composite key record).
509
- * @param keyFields - Optional ordered list of key field names for composite keys.
510
- * @returns An EntityKey.
511
- */
512
- const resolveEntityKey = (typename, id, keyFields) => {
513
- if (typeof id === "string" || typeof id === "number") return makeEntityKey(typename, [id]);
514
- return makeEntityKey(typename, keyFields ? keyFields.map((f) => id[f]) : Object.values(id));
515
- };
516
504
 
517
505
  //#endregion
518
506
  //#region src/cache/normalize.ts
@@ -762,8 +750,8 @@ var Cache = class {
762
750
  */
763
751
  invalidate(...targets) {
764
752
  const subscriptions = /* @__PURE__ */ new Set();
765
- for (const target of targets) if (target.__typename === "Query") if ("field" in target) {
766
- const fieldKey = makeFieldKeyFromArgs(target.field, target.args);
753
+ for (const target of targets) if (target.__typename === "Query") if ("$field" in target) {
754
+ const fieldKey = makeFieldKeyFromArgs(target.$field, target.$args);
767
755
  const depKey = makeDependencyKey(RootFieldKey, fieldKey);
768
756
  this.#stale.add(depKey);
769
757
  this.#collectSubscriptions(RootFieldKey, fieldKey, subscriptions);
@@ -771,32 +759,39 @@ var Cache = class {
771
759
  this.#stale.add(RootFieldKey);
772
760
  this.#collectSubscriptions(RootFieldKey, void 0, subscriptions);
773
761
  }
774
- else if ("id" in target) {
775
- const entityKey = resolveEntityKey(target.__typename, target.id, this.#schemaMeta.entities[target.__typename]?.keyFields);
776
- if ("field" in target) {
777
- const fieldKey = makeFieldKeyFromArgs(target.field, target.args);
778
- this.#stale.add(makeDependencyKey(entityKey, fieldKey));
779
- this.#collectSubscriptions(entityKey, fieldKey, subscriptions);
780
- } else {
781
- this.#stale.add(entityKey);
782
- this.#collectSubscriptions(entityKey, void 0, subscriptions);
783
- }
784
- } else {
785
- const prefix = `${target.__typename}:`;
786
- for (const key of Object.keys(this.#storage)) if (key.startsWith(prefix)) {
787
- const entityKey = key;
788
- if ("field" in target) {
789
- const fieldKey = makeFieldKeyFromArgs(target.field, target.args);
762
+ else {
763
+ const keyFields = this.#schemaMeta.entities[target.__typename]?.keyFields;
764
+ if (keyFields && this.#hasKeyFields(target, keyFields)) {
765
+ const keyValues = keyFields.map((f) => target[f]);
766
+ const entityKey = makeEntityKey(target.__typename, keyValues);
767
+ if ("$field" in target) {
768
+ const fieldKey = makeFieldKeyFromArgs(target.$field, target.$args);
790
769
  this.#stale.add(makeDependencyKey(entityKey, fieldKey));
791
770
  this.#collectSubscriptions(entityKey, fieldKey, subscriptions);
792
771
  } else {
793
772
  this.#stale.add(entityKey);
794
773
  this.#collectSubscriptions(entityKey, void 0, subscriptions);
795
774
  }
775
+ } else {
776
+ const prefix = `${target.__typename}:`;
777
+ for (const key of Object.keys(this.#storage)) if (key.startsWith(prefix)) {
778
+ const entityKey = key;
779
+ if ("$field" in target) {
780
+ const fieldKey = makeFieldKeyFromArgs(target.$field, target.$args);
781
+ this.#stale.add(makeDependencyKey(entityKey, fieldKey));
782
+ this.#collectSubscriptions(entityKey, fieldKey, subscriptions);
783
+ } else {
784
+ this.#stale.add(entityKey);
785
+ this.#collectSubscriptions(entityKey, void 0, subscriptions);
786
+ }
787
+ }
796
788
  }
797
789
  }
798
790
  for (const subscription of subscriptions) subscription.listener();
799
791
  }
792
+ #hasKeyFields(target, keyFields) {
793
+ return keyFields.every((f) => f in target);
794
+ }
800
795
  #collectSubscriptions(storageKey, fieldKey, out) {
801
796
  if (fieldKey === void 0) {
802
797
  const prefix = `${storageKey}.`;
package/dist/index.d.cts CHANGED
@@ -106,9 +106,9 @@ declare class Client<TMeta extends SchemaMeta$1 = SchemaMeta$1> {
106
106
  * @param name - The exchange name.
107
107
  * @returns The extension object provided by the exchange.
108
108
  */
109
- extension<TName extends keyof ExchangeExtensionMap>(name: TName): ExchangeExtensionMap[TName];
109
+ extension<TName extends keyof ExchangeExtensionMap<TMeta>>(name: TName): ExchangeExtensionMap<TMeta>[TName];
110
110
  extension(name: string): unknown;
111
- maybeExtension<TName extends keyof ExchangeExtensionMap>(name: TName): ExchangeExtensionMap[TName] | undefined;
111
+ maybeExtension<TName extends keyof ExchangeExtensionMap<TMeta>>(name: TName): ExchangeExtensionMap<TMeta>[TName] | undefined;
112
112
  maybeExtension(name: string): unknown;
113
113
  dispose(): void;
114
114
  }
@@ -143,14 +143,14 @@ type ExchangeInput<TMeta extends SchemaMeta$1 = SchemaMeta$1> = {
143
143
  client: Client<TMeta>;
144
144
  };
145
145
  type ExchangeIO = (operations: Source<Operation>) => Source<OperationResult>;
146
- interface ExchangeExtensionMap {}
147
- type ExchangeResult<TName extends keyof ExchangeExtensionMap | (string & {}) = string> = {
146
+ interface ExchangeExtensionMap<TMeta extends SchemaMeta$1 = SchemaMeta$1> {}
147
+ type ExchangeResult<TName extends keyof ExchangeExtensionMap | (string & {}) = string, TMeta extends SchemaMeta$1 = SchemaMeta$1> = {
148
148
  name: TName;
149
149
  io: ExchangeIO;
150
- } & (TName extends keyof ExchangeExtensionMap ? {
151
- extension: ExchangeExtensionMap[TName];
150
+ } & (TName extends keyof ExchangeExtensionMap<TMeta> ? {
151
+ extension: ExchangeExtensionMap<TMeta>[TName];
152
152
  } : {});
153
- type Exchange<TName extends keyof ExchangeExtensionMap | (string & {}) = string> = <TMeta extends SchemaMeta$1 = SchemaMeta$1>(input: ExchangeInput<TMeta>) => ExchangeResult<TName>;
153
+ type Exchange<TName extends keyof ExchangeExtensionMap | (string & {}) = string> = <TMeta extends SchemaMeta$1 = SchemaMeta$1>(input: ExchangeInput<TMeta>) => ExchangeResult<TName, TMeta>;
154
154
  //#endregion
155
155
  //#region src/exchanges/http.d.ts
156
156
  declare module '@mearie/core' {
@@ -195,34 +195,38 @@ declare module '@mearie/core' {
195
195
  declare const dedupExchange: () => Exchange;
196
196
  //#endregion
197
197
  //#region src/cache/types.d.ts
198
- /**
199
- * Identifier for a single entity, supporting simple or composite keys.
200
- */
201
- type EntityId = string | number | Record<string, string | number>;
202
- /**
203
- * Target specification for cache invalidation operations.
204
- */
205
- type InvalidateTarget = {
206
- __typename: string;
207
- id: EntityId;
208
- } | {
209
- __typename: string;
210
- id: EntityId;
211
- field: string;
212
- args?: Record<string, unknown>;
213
- } | {
198
+ type EntityTypes<TMeta extends SchemaMeta$1> = NonNullable<TMeta[' $entityTypes']>;
199
+ type QueryFields<TMeta extends SchemaMeta$1> = NonNullable<TMeta[' $queryFields']>;
200
+ type KeyFieldsOf<E> = E extends {
201
+ keyFields: infer KF;
202
+ } ? KF : Record<string, unknown>;
203
+ type FieldsOf<E> = E extends {
204
+ fields: infer F extends string;
205
+ } ? F : string;
206
+ type EntityInvalidateTarget<Entities> = { [K in keyof Entities & string]: {
207
+ __typename: K;
208
+ } | ({
209
+ __typename: K;
210
+ } & KeyFieldsOf<Entities[K]>) | {
211
+ __typename: K;
212
+ $field: FieldsOf<Entities[K]>;
213
+ $args?: Record<string, unknown>;
214
+ } | ({
215
+ __typename: K;
216
+ $field: FieldsOf<Entities[K]>;
217
+ $args?: Record<string, unknown>;
218
+ } & KeyFieldsOf<Entities[K]>) }[keyof Entities & string];
219
+ type QueryInvalidateTarget<QF extends string> = {
214
220
  __typename: 'Query';
215
221
  } | {
216
222
  __typename: 'Query';
217
- field: string;
218
- args?: Record<string, unknown>;
219
- } | {
220
- __typename: string;
221
- } | {
222
- __typename: string;
223
- field: string;
224
- args?: Record<string, unknown>;
223
+ $field: QF;
224
+ $args?: Record<string, unknown>;
225
225
  };
226
+ /**
227
+ * Target specification for cache invalidation operations.
228
+ */
229
+ type InvalidateTarget<TMeta extends SchemaMeta$1 = SchemaMeta$1> = EntityInvalidateTarget<EntityTypes<TMeta>> | QueryInvalidateTarget<QueryFields<TMeta>>;
226
230
  /**
227
231
  * Opaque type representing a serializable cache snapshot.
228
232
  */
@@ -232,17 +236,17 @@ type CacheSnapshot = {
232
236
  /**
233
237
  * Operations available for programmatic cache manipulation.
234
238
  */
235
- type CacheOperations = {
239
+ type CacheOperations<TMeta extends SchemaMeta$1 = SchemaMeta$1> = {
236
240
  extract(): CacheSnapshot;
237
241
  hydrate(data: CacheSnapshot): void;
238
- invalidate(...targets: InvalidateTarget[]): void;
242
+ invalidate(...targets: InvalidateTarget<TMeta>[]): void;
239
243
  clear(): void;
240
244
  };
241
245
  //#endregion
242
246
  //#region src/exchanges/cache.d.ts
243
247
  declare module '@mearie/core' {
244
- interface ExchangeExtensionMap {
245
- cache: CacheOperations;
248
+ interface ExchangeExtensionMap<TMeta extends SchemaMeta$1> {
249
+ cache: CacheOperations<TMeta>;
246
250
  }
247
251
  interface OperationResultMetadataMap {
248
252
  cache?: {
@@ -351,4 +355,4 @@ declare class RequiredFieldError extends Error {
351
355
  */
352
356
  declare const stringify: (value: unknown) => string;
353
357
  //#endregion
354
- export { AggregatedError, type Artifact, type ArtifactKind, type CacheOptions, type CacheSnapshot, Client, type ClientOptions, type DataOf, type Exchange, ExchangeError, type ExchangeErrorExtensionsMap, type ExchangeExtensionMap, type ExchangeIO, type ExchangeResult, type FragmentOptions, type FragmentRefs, GraphQLError, type HttpOptions, type MutationOptions, type Operation, type OperationError, type OperationMetadata, type OperationMetadataMap, type OperationResult, type OperationResultMetadataMap, type QueryOptions, type RequiredAction, RequiredFieldError, type RetryOptions, type SchemaMeta, type SubscriptionClient, type SubscriptionExchangeOptions, type SubscriptionOptions, type VariablesOf, cacheExchange, createClient, dedupExchange, fragmentExchange, httpExchange, isAggregatedError, isExchangeError, isGraphQLError, requiredExchange, retryExchange, stringify, subscriptionExchange };
358
+ export { AggregatedError, type Artifact, type ArtifactKind, type CacheOperations, type CacheOptions, type CacheSnapshot, Client, type ClientOptions, type DataOf, type Exchange, ExchangeError, type ExchangeErrorExtensionsMap, type ExchangeExtensionMap, type ExchangeIO, type ExchangeResult, type FragmentOptions, type FragmentRefs, GraphQLError, type HttpOptions, type InvalidateTarget, type MutationOptions, type Operation, type OperationError, type OperationMetadata, type OperationMetadataMap, type OperationResult, type OperationResultMetadataMap, type QueryOptions, type RequiredAction, RequiredFieldError, type RetryOptions, type SchemaMeta, type SubscriptionClient, type SubscriptionExchangeOptions, type SubscriptionOptions, type VariablesOf, cacheExchange, createClient, dedupExchange, fragmentExchange, httpExchange, isAggregatedError, isExchangeError, isGraphQLError, requiredExchange, retryExchange, stringify, subscriptionExchange };
package/dist/index.d.mts CHANGED
@@ -106,9 +106,9 @@ declare class Client<TMeta extends SchemaMeta$1 = SchemaMeta$1> {
106
106
  * @param name - The exchange name.
107
107
  * @returns The extension object provided by the exchange.
108
108
  */
109
- extension<TName extends keyof ExchangeExtensionMap>(name: TName): ExchangeExtensionMap[TName];
109
+ extension<TName extends keyof ExchangeExtensionMap<TMeta>>(name: TName): ExchangeExtensionMap<TMeta>[TName];
110
110
  extension(name: string): unknown;
111
- maybeExtension<TName extends keyof ExchangeExtensionMap>(name: TName): ExchangeExtensionMap[TName] | undefined;
111
+ maybeExtension<TName extends keyof ExchangeExtensionMap<TMeta>>(name: TName): ExchangeExtensionMap<TMeta>[TName] | undefined;
112
112
  maybeExtension(name: string): unknown;
113
113
  dispose(): void;
114
114
  }
@@ -143,14 +143,14 @@ type ExchangeInput<TMeta extends SchemaMeta$1 = SchemaMeta$1> = {
143
143
  client: Client<TMeta>;
144
144
  };
145
145
  type ExchangeIO = (operations: Source<Operation>) => Source<OperationResult>;
146
- interface ExchangeExtensionMap {}
147
- type ExchangeResult<TName extends keyof ExchangeExtensionMap | (string & {}) = string> = {
146
+ interface ExchangeExtensionMap<TMeta extends SchemaMeta$1 = SchemaMeta$1> {}
147
+ type ExchangeResult<TName extends keyof ExchangeExtensionMap | (string & {}) = string, TMeta extends SchemaMeta$1 = SchemaMeta$1> = {
148
148
  name: TName;
149
149
  io: ExchangeIO;
150
- } & (TName extends keyof ExchangeExtensionMap ? {
151
- extension: ExchangeExtensionMap[TName];
150
+ } & (TName extends keyof ExchangeExtensionMap<TMeta> ? {
151
+ extension: ExchangeExtensionMap<TMeta>[TName];
152
152
  } : {});
153
- type Exchange<TName extends keyof ExchangeExtensionMap | (string & {}) = string> = <TMeta extends SchemaMeta$1 = SchemaMeta$1>(input: ExchangeInput<TMeta>) => ExchangeResult<TName>;
153
+ type Exchange<TName extends keyof ExchangeExtensionMap | (string & {}) = string> = <TMeta extends SchemaMeta$1 = SchemaMeta$1>(input: ExchangeInput<TMeta>) => ExchangeResult<TName, TMeta>;
154
154
  //#endregion
155
155
  //#region src/exchanges/http.d.ts
156
156
  declare module '@mearie/core' {
@@ -195,34 +195,38 @@ declare module '@mearie/core' {
195
195
  declare const dedupExchange: () => Exchange;
196
196
  //#endregion
197
197
  //#region src/cache/types.d.ts
198
- /**
199
- * Identifier for a single entity, supporting simple or composite keys.
200
- */
201
- type EntityId = string | number | Record<string, string | number>;
202
- /**
203
- * Target specification for cache invalidation operations.
204
- */
205
- type InvalidateTarget = {
206
- __typename: string;
207
- id: EntityId;
208
- } | {
209
- __typename: string;
210
- id: EntityId;
211
- field: string;
212
- args?: Record<string, unknown>;
213
- } | {
198
+ type EntityTypes<TMeta extends SchemaMeta$1> = NonNullable<TMeta[' $entityTypes']>;
199
+ type QueryFields<TMeta extends SchemaMeta$1> = NonNullable<TMeta[' $queryFields']>;
200
+ type KeyFieldsOf<E> = E extends {
201
+ keyFields: infer KF;
202
+ } ? KF : Record<string, unknown>;
203
+ type FieldsOf<E> = E extends {
204
+ fields: infer F extends string;
205
+ } ? F : string;
206
+ type EntityInvalidateTarget<Entities> = { [K in keyof Entities & string]: {
207
+ __typename: K;
208
+ } | ({
209
+ __typename: K;
210
+ } & KeyFieldsOf<Entities[K]>) | {
211
+ __typename: K;
212
+ $field: FieldsOf<Entities[K]>;
213
+ $args?: Record<string, unknown>;
214
+ } | ({
215
+ __typename: K;
216
+ $field: FieldsOf<Entities[K]>;
217
+ $args?: Record<string, unknown>;
218
+ } & KeyFieldsOf<Entities[K]>) }[keyof Entities & string];
219
+ type QueryInvalidateTarget<QF extends string> = {
214
220
  __typename: 'Query';
215
221
  } | {
216
222
  __typename: 'Query';
217
- field: string;
218
- args?: Record<string, unknown>;
219
- } | {
220
- __typename: string;
221
- } | {
222
- __typename: string;
223
- field: string;
224
- args?: Record<string, unknown>;
223
+ $field: QF;
224
+ $args?: Record<string, unknown>;
225
225
  };
226
+ /**
227
+ * Target specification for cache invalidation operations.
228
+ */
229
+ type InvalidateTarget<TMeta extends SchemaMeta$1 = SchemaMeta$1> = EntityInvalidateTarget<EntityTypes<TMeta>> | QueryInvalidateTarget<QueryFields<TMeta>>;
226
230
  /**
227
231
  * Opaque type representing a serializable cache snapshot.
228
232
  */
@@ -232,17 +236,17 @@ type CacheSnapshot = {
232
236
  /**
233
237
  * Operations available for programmatic cache manipulation.
234
238
  */
235
- type CacheOperations = {
239
+ type CacheOperations<TMeta extends SchemaMeta$1 = SchemaMeta$1> = {
236
240
  extract(): CacheSnapshot;
237
241
  hydrate(data: CacheSnapshot): void;
238
- invalidate(...targets: InvalidateTarget[]): void;
242
+ invalidate(...targets: InvalidateTarget<TMeta>[]): void;
239
243
  clear(): void;
240
244
  };
241
245
  //#endregion
242
246
  //#region src/exchanges/cache.d.ts
243
247
  declare module '@mearie/core' {
244
- interface ExchangeExtensionMap {
245
- cache: CacheOperations;
248
+ interface ExchangeExtensionMap<TMeta extends SchemaMeta$1> {
249
+ cache: CacheOperations<TMeta>;
246
250
  }
247
251
  interface OperationResultMetadataMap {
248
252
  cache?: {
@@ -351,4 +355,4 @@ declare class RequiredFieldError extends Error {
351
355
  */
352
356
  declare const stringify: (value: unknown) => string;
353
357
  //#endregion
354
- export { AggregatedError, type Artifact, type ArtifactKind, type CacheOptions, type CacheSnapshot, Client, type ClientOptions, type DataOf, type Exchange, ExchangeError, type ExchangeErrorExtensionsMap, type ExchangeExtensionMap, type ExchangeIO, type ExchangeResult, type FragmentOptions, type FragmentRefs, GraphQLError, type HttpOptions, type MutationOptions, type Operation, type OperationError, type OperationMetadata, type OperationMetadataMap, type OperationResult, type OperationResultMetadataMap, type QueryOptions, type RequiredAction, RequiredFieldError, type RetryOptions, type SchemaMeta, type SubscriptionClient, type SubscriptionExchangeOptions, type SubscriptionOptions, type VariablesOf, cacheExchange, createClient, dedupExchange, fragmentExchange, httpExchange, isAggregatedError, isExchangeError, isGraphQLError, requiredExchange, retryExchange, stringify, subscriptionExchange };
358
+ export { AggregatedError, type Artifact, type ArtifactKind, type CacheOperations, type CacheOptions, type CacheSnapshot, Client, type ClientOptions, type DataOf, type Exchange, ExchangeError, type ExchangeErrorExtensionsMap, type ExchangeExtensionMap, type ExchangeIO, type ExchangeResult, type FragmentOptions, type FragmentRefs, GraphQLError, type HttpOptions, type InvalidateTarget, type MutationOptions, type Operation, type OperationError, type OperationMetadata, type OperationMetadataMap, type OperationResult, type OperationResultMetadataMap, type QueryOptions, type RequiredAction, RequiredFieldError, type RetryOptions, type SchemaMeta, type SubscriptionClient, type SubscriptionExchangeOptions, type SubscriptionOptions, type VariablesOf, cacheExchange, createClient, dedupExchange, fragmentExchange, httpExchange, isAggregatedError, isExchangeError, isGraphQLError, requiredExchange, retryExchange, stringify, subscriptionExchange };
package/dist/index.mjs CHANGED
@@ -500,18 +500,6 @@ const mergeFields = (target, source) => {
500
500
  const makeFieldKeyFromArgs = (field, args) => {
501
501
  return `${field}@${args && Object.keys(args).length > 0 ? stringify(args) : "{}"}`;
502
502
  };
503
- /**
504
- * Converts an EntityId to an EntityKey.
505
- * @internal
506
- * @param typename - The GraphQL typename of the entity.
507
- * @param id - The entity identifier (string, number, or composite key record).
508
- * @param keyFields - Optional ordered list of key field names for composite keys.
509
- * @returns An EntityKey.
510
- */
511
- const resolveEntityKey = (typename, id, keyFields) => {
512
- if (typeof id === "string" || typeof id === "number") return makeEntityKey(typename, [id]);
513
- return makeEntityKey(typename, keyFields ? keyFields.map((f) => id[f]) : Object.values(id));
514
- };
515
503
 
516
504
  //#endregion
517
505
  //#region src/cache/normalize.ts
@@ -761,8 +749,8 @@ var Cache = class {
761
749
  */
762
750
  invalidate(...targets) {
763
751
  const subscriptions = /* @__PURE__ */ new Set();
764
- for (const target of targets) if (target.__typename === "Query") if ("field" in target) {
765
- const fieldKey = makeFieldKeyFromArgs(target.field, target.args);
752
+ for (const target of targets) if (target.__typename === "Query") if ("$field" in target) {
753
+ const fieldKey = makeFieldKeyFromArgs(target.$field, target.$args);
766
754
  const depKey = makeDependencyKey(RootFieldKey, fieldKey);
767
755
  this.#stale.add(depKey);
768
756
  this.#collectSubscriptions(RootFieldKey, fieldKey, subscriptions);
@@ -770,32 +758,39 @@ var Cache = class {
770
758
  this.#stale.add(RootFieldKey);
771
759
  this.#collectSubscriptions(RootFieldKey, void 0, subscriptions);
772
760
  }
773
- else if ("id" in target) {
774
- const entityKey = resolveEntityKey(target.__typename, target.id, this.#schemaMeta.entities[target.__typename]?.keyFields);
775
- if ("field" in target) {
776
- const fieldKey = makeFieldKeyFromArgs(target.field, target.args);
777
- this.#stale.add(makeDependencyKey(entityKey, fieldKey));
778
- this.#collectSubscriptions(entityKey, fieldKey, subscriptions);
779
- } else {
780
- this.#stale.add(entityKey);
781
- this.#collectSubscriptions(entityKey, void 0, subscriptions);
782
- }
783
- } else {
784
- const prefix = `${target.__typename}:`;
785
- for (const key of Object.keys(this.#storage)) if (key.startsWith(prefix)) {
786
- const entityKey = key;
787
- if ("field" in target) {
788
- const fieldKey = makeFieldKeyFromArgs(target.field, target.args);
761
+ else {
762
+ const keyFields = this.#schemaMeta.entities[target.__typename]?.keyFields;
763
+ if (keyFields && this.#hasKeyFields(target, keyFields)) {
764
+ const keyValues = keyFields.map((f) => target[f]);
765
+ const entityKey = makeEntityKey(target.__typename, keyValues);
766
+ if ("$field" in target) {
767
+ const fieldKey = makeFieldKeyFromArgs(target.$field, target.$args);
789
768
  this.#stale.add(makeDependencyKey(entityKey, fieldKey));
790
769
  this.#collectSubscriptions(entityKey, fieldKey, subscriptions);
791
770
  } else {
792
771
  this.#stale.add(entityKey);
793
772
  this.#collectSubscriptions(entityKey, void 0, subscriptions);
794
773
  }
774
+ } else {
775
+ const prefix = `${target.__typename}:`;
776
+ for (const key of Object.keys(this.#storage)) if (key.startsWith(prefix)) {
777
+ const entityKey = key;
778
+ if ("$field" in target) {
779
+ const fieldKey = makeFieldKeyFromArgs(target.$field, target.$args);
780
+ this.#stale.add(makeDependencyKey(entityKey, fieldKey));
781
+ this.#collectSubscriptions(entityKey, fieldKey, subscriptions);
782
+ } else {
783
+ this.#stale.add(entityKey);
784
+ this.#collectSubscriptions(entityKey, void 0, subscriptions);
785
+ }
786
+ }
795
787
  }
796
788
  }
797
789
  for (const subscription of subscriptions) subscription.listener();
798
790
  }
791
+ #hasKeyFields(target, keyFields) {
792
+ return keyFields.every((f) => f in target);
793
+ }
799
794
  #collectSubscriptions(storageKey, fieldKey, out) {
800
795
  if (fieldKey === void 0) {
801
796
  const prefix = `${storageKey}.`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mearie/core",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "Type-safe, zero-overhead GraphQL client",
5
5
  "keywords": [
6
6
  "graphql",
@@ -62,7 +62,7 @@
62
62
  "README.md"
63
63
  ],
64
64
  "dependencies": {
65
- "@mearie/shared": "0.2.2"
65
+ "@mearie/shared": "0.3.0"
66
66
  },
67
67
  "devDependencies": {
68
68
  "tsdown": "^0.20.3",