@mearie/core 0.2.1 → 0.2.3

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
@@ -91,6 +91,7 @@ const executeFetch = async ({ url, fetchFn, fetchOptions, operation, signal }) =
91
91
  ...fetchOptions.headers
92
92
  },
93
93
  body: JSON.stringify({
94
+ operationName: artifact.name,
94
95
  query: artifact.body,
95
96
  variables
96
97
  }),
@@ -263,16 +264,19 @@ const dedupExchange = () => {
263
264
  name: "dedup",
264
265
  io: (ops$) => {
265
266
  const operations = /* @__PURE__ */ new Map();
267
+ const resolved = /* @__PURE__ */ new Set();
266
268
  return require_make.pipe(require_make.merge(require_make.pipe(ops$, require_make.filter((op) => op.variant === "request" && (op.artifact.kind === "mutation" || op.artifact.kind === "fragment"))), require_make.pipe(ops$, require_make.filter((op) => op.variant === "request" && op.artifact.kind !== "mutation" && op.artifact.kind !== "fragment"), require_make.filter((op) => {
267
269
  const dedupKey = makeDedupKey(op);
268
- const isInflight = operations.has(dedupKey);
270
+ const isInflight = operations.has(dedupKey) && !resolved.has(dedupKey);
269
271
  if (isInflight) operations.get(dedupKey).add(op.key);
270
272
  else operations.set(dedupKey, new Set([op.key]));
273
+ if (!isInflight) resolved.delete(dedupKey);
271
274
  return (op.metadata.dedup?.skip ?? false) || !isInflight;
272
275
  }), delay(0)), require_make.pipe(ops$, require_make.filter((op) => op.variant === "teardown"), require_make.filter((teardown) => {
273
276
  for (const [dedupKey, subs] of operations.entries()) if (subs.delete(teardown.key)) {
274
277
  if (subs.size === 0) {
275
278
  operations.delete(dedupKey);
279
+ resolved.delete(dedupKey);
276
280
  return true;
277
281
  }
278
282
  return false;
@@ -281,6 +285,7 @@ const dedupExchange = () => {
281
285
  }))), forward, require_make.mergeMap((result) => {
282
286
  if (result.operation.variant !== "request" || result.operation.artifact.kind === "mutation" || result.operation.artifact.kind === "fragment") return require_make.fromValue(result);
283
287
  const dedupKey = makeDedupKey(result.operation);
288
+ resolved.add(dedupKey);
284
289
  return require_make.fromArray([...operations.get(dedupKey) ?? /* @__PURE__ */ new Set()].map((key) => ({
285
290
  ...result,
286
291
  operation: {
@@ -539,10 +544,9 @@ const normalize = (schemaMeta, selections, storage, data, variables, accessor) =
539
544
  if (inner !== SKIP && !isEntityLink(inner)) mergeFields(fields, inner);
540
545
  }
541
546
  if (entityMeta && storageKey !== null) {
542
- storage[storageKey] = {
543
- ...storage[storageKey],
544
- ...fields
545
- };
547
+ const existing = storage[storageKey];
548
+ if (existing) mergeFields(existing, fields);
549
+ else storage[storageKey] = fields;
546
550
  return { [EntityLinkKey]: storageKey };
547
551
  }
548
552
  return fields;
@@ -1109,6 +1113,7 @@ const subscriptionExchange = (options) => {
1109
1113
  Promise.resolve().then(() => {
1110
1114
  if (completed) return;
1111
1115
  unsubscribe = client.subscribe({
1116
+ operationName: op.artifact.name,
1112
1117
  query: op.artifact.body,
1113
1118
  variables: op.variables
1114
1119
  }, {
package/dist/index.d.cts CHANGED
@@ -279,6 +279,7 @@ declare const requiredExchange: () => Exchange;
279
279
  //#region src/exchanges/subscription.d.ts
280
280
  interface SubscriptionClient {
281
281
  subscribe(payload: {
282
+ operationName?: string;
282
283
  query: string;
283
284
  variables?: Record<string, unknown>;
284
285
  }, sink: {
package/dist/index.d.mts CHANGED
@@ -279,6 +279,7 @@ declare const requiredExchange: () => Exchange;
279
279
  //#region src/exchanges/subscription.d.ts
280
280
  interface SubscriptionClient {
281
281
  subscribe(payload: {
282
+ operationName?: string;
282
283
  query: string;
283
284
  variables?: Record<string, unknown>;
284
285
  }, sink: {
package/dist/index.mjs CHANGED
@@ -90,6 +90,7 @@ const executeFetch = async ({ url, fetchFn, fetchOptions, operation, signal }) =
90
90
  ...fetchOptions.headers
91
91
  },
92
92
  body: JSON.stringify({
93
+ operationName: artifact.name,
93
94
  query: artifact.body,
94
95
  variables
95
96
  }),
@@ -262,16 +263,19 @@ const dedupExchange = () => {
262
263
  name: "dedup",
263
264
  io: (ops$) => {
264
265
  const operations = /* @__PURE__ */ new Map();
266
+ const resolved = /* @__PURE__ */ new Set();
265
267
  return pipe(merge(pipe(ops$, filter((op) => op.variant === "request" && (op.artifact.kind === "mutation" || op.artifact.kind === "fragment"))), pipe(ops$, filter((op) => op.variant === "request" && op.artifact.kind !== "mutation" && op.artifact.kind !== "fragment"), filter((op) => {
266
268
  const dedupKey = makeDedupKey(op);
267
- const isInflight = operations.has(dedupKey);
269
+ const isInflight = operations.has(dedupKey) && !resolved.has(dedupKey);
268
270
  if (isInflight) operations.get(dedupKey).add(op.key);
269
271
  else operations.set(dedupKey, new Set([op.key]));
272
+ if (!isInflight) resolved.delete(dedupKey);
270
273
  return (op.metadata.dedup?.skip ?? false) || !isInflight;
271
274
  }), delay(0)), pipe(ops$, filter((op) => op.variant === "teardown"), filter((teardown) => {
272
275
  for (const [dedupKey, subs] of operations.entries()) if (subs.delete(teardown.key)) {
273
276
  if (subs.size === 0) {
274
277
  operations.delete(dedupKey);
278
+ resolved.delete(dedupKey);
275
279
  return true;
276
280
  }
277
281
  return false;
@@ -280,6 +284,7 @@ const dedupExchange = () => {
280
284
  }))), forward, mergeMap((result) => {
281
285
  if (result.operation.variant !== "request" || result.operation.artifact.kind === "mutation" || result.operation.artifact.kind === "fragment") return fromValue(result);
282
286
  const dedupKey = makeDedupKey(result.operation);
287
+ resolved.add(dedupKey);
283
288
  return fromArray([...operations.get(dedupKey) ?? /* @__PURE__ */ new Set()].map((key) => ({
284
289
  ...result,
285
290
  operation: {
@@ -538,10 +543,9 @@ const normalize = (schemaMeta, selections, storage, data, variables, accessor) =
538
543
  if (inner !== SKIP && !isEntityLink(inner)) mergeFields(fields, inner);
539
544
  }
540
545
  if (entityMeta && storageKey !== null) {
541
- storage[storageKey] = {
542
- ...storage[storageKey],
543
- ...fields
544
- };
546
+ const existing = storage[storageKey];
547
+ if (existing) mergeFields(existing, fields);
548
+ else storage[storageKey] = fields;
545
549
  return { [EntityLinkKey]: storageKey };
546
550
  }
547
551
  return fields;
@@ -1108,6 +1112,7 @@ const subscriptionExchange = (options) => {
1108
1112
  Promise.resolve().then(() => {
1109
1113
  if (completed) return;
1110
1114
  unsubscribe = client.subscribe({
1115
+ operationName: op.artifact.name,
1111
1116
  query: op.artifact.body,
1112
1117
  variables: op.variables
1113
1118
  }, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mearie/core",
3
- "version": "0.2.1",
3
+ "version": "0.2.3",
4
4
  "description": "Type-safe, zero-overhead GraphQL client",
5
5
  "keywords": [
6
6
  "graphql",