@zenstackhq/tanstack-query 3.0.0-beta.17 → 3.0.0-beta.19

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.
@@ -0,0 +1,1224 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
9
+ var __export = (target, all) => {
10
+ for (var name in all)
11
+ __defProp(target, name, { get: all[name], enumerable: true });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from))
16
+ if (!__hasOwnProp.call(to, key) && key !== except)
17
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
+ }
19
+ return to;
20
+ };
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
+ // If the importer is in node compatibility mode or this is not an ESM
23
+ // file that has been converted to a CommonJS file using a Babel-
24
+ // compatible transform (i.e. "__esModule" has not been set), then set
25
+ // "default" to the CommonJS "module.exports" for node compatibility.
26
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
+ mod
28
+ ));
29
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
+
31
+ // src/svelte.ts
32
+ var svelte_exports = {};
33
+ __export(svelte_exports, {
34
+ DEFAULT_QUERY_ENDPOINT: () => DEFAULT_QUERY_ENDPOINT,
35
+ SvelteQueryContextKey: () => SvelteQueryContextKey,
36
+ setHooksContext: () => setHooksContext,
37
+ setQuerySettingsContext: () => setQuerySettingsContext,
38
+ useClientQueries: () => useClientQueries,
39
+ useInternalInfiniteQuery: () => useInternalInfiniteQuery,
40
+ useInternalMutation: () => useInternalMutation,
41
+ useInternalQuery: () => useInternalQuery,
42
+ useModelQueries: () => useModelQueries
43
+ });
44
+ module.exports = __toCommonJS(svelte_exports);
45
+ var import_svelte_query = require("@tanstack/svelte-query");
46
+ var import_common_helpers4 = require("@zenstackhq/common-helpers");
47
+ var import_svelte = require("svelte");
48
+ var import_store = require("svelte/store");
49
+
50
+ // src/utils/common.ts
51
+ var import_common_helpers3 = require("@zenstackhq/common-helpers");
52
+
53
+ // src/utils/mutator.ts
54
+ var import_common_helpers2 = require("@zenstackhq/common-helpers");
55
+
56
+ // src/utils/nested-write-visitor.ts
57
+ var import_common_helpers = require("@zenstackhq/common-helpers");
58
+
59
+ // src/utils/types.ts
60
+ var ORMWriteActions = [
61
+ "create",
62
+ "createMany",
63
+ "createManyAndReturn",
64
+ "connectOrCreate",
65
+ "update",
66
+ "updateMany",
67
+ "updateManyAndReturn",
68
+ "upsert",
69
+ "connect",
70
+ "disconnect",
71
+ "set",
72
+ "delete",
73
+ "deleteMany"
74
+ ];
75
+
76
+ // src/utils/nested-write-visitor.ts
77
+ var NestedWriteVisitor = class {
78
+ static {
79
+ __name(this, "NestedWriteVisitor");
80
+ }
81
+ schema;
82
+ callback;
83
+ constructor(schema, callback) {
84
+ this.schema = schema;
85
+ this.callback = callback;
86
+ }
87
+ isWriteAction(value) {
88
+ return ORMWriteActions.includes(value);
89
+ }
90
+ /**
91
+ * Start visiting
92
+ *
93
+ * @see NestedWriterVisitorCallback
94
+ */
95
+ async visit(model, action, args) {
96
+ if (!args) {
97
+ return;
98
+ }
99
+ let topData = args;
100
+ switch (action) {
101
+ // create has its data wrapped in 'data' field
102
+ case "create":
103
+ topData = topData.data;
104
+ break;
105
+ case "delete":
106
+ case "deleteMany":
107
+ topData = topData.where;
108
+ break;
109
+ }
110
+ await this.doVisit(model, action, topData, void 0, void 0, []);
111
+ }
112
+ async doVisit(model, action, data, parent, field, nestingPath) {
113
+ if (!data) {
114
+ return;
115
+ }
116
+ const toplevel = field == void 0;
117
+ const context = {
118
+ parent,
119
+ field,
120
+ nestingPath: [
121
+ ...nestingPath
122
+ ]
123
+ };
124
+ const pushNewContext = /* @__PURE__ */ __name((field2, model2, where, unique = false) => {
125
+ return {
126
+ ...context,
127
+ nestingPath: [
128
+ ...context.nestingPath,
129
+ {
130
+ field: field2,
131
+ model: model2,
132
+ where,
133
+ unique
134
+ }
135
+ ]
136
+ };
137
+ }, "pushNewContext");
138
+ switch (action) {
139
+ case "create":
140
+ for (const item of this.enumerateReverse(data)) {
141
+ const newContext = pushNewContext(field, model, {});
142
+ let callbackResult;
143
+ if (this.callback.create) {
144
+ callbackResult = await this.callback.create(model, item, newContext);
145
+ }
146
+ if (callbackResult !== false) {
147
+ const subPayload = typeof callbackResult === "object" ? callbackResult : item;
148
+ await this.visitSubPayload(model, action, subPayload, newContext.nestingPath);
149
+ }
150
+ }
151
+ break;
152
+ case "createMany":
153
+ case "createManyAndReturn":
154
+ {
155
+ const newContext = pushNewContext(field, model, {});
156
+ let callbackResult;
157
+ if (this.callback.createMany) {
158
+ callbackResult = await this.callback.createMany(model, data, newContext);
159
+ }
160
+ if (callbackResult !== false) {
161
+ const subPayload = typeof callbackResult === "object" ? callbackResult : data.data;
162
+ await this.visitSubPayload(model, action, subPayload, newContext.nestingPath);
163
+ }
164
+ }
165
+ break;
166
+ case "connectOrCreate":
167
+ for (const item of this.enumerateReverse(data)) {
168
+ const newContext = pushNewContext(field, model, item.where);
169
+ let callbackResult;
170
+ if (this.callback.connectOrCreate) {
171
+ callbackResult = await this.callback.connectOrCreate(model, item, newContext);
172
+ }
173
+ if (callbackResult !== false) {
174
+ const subPayload = typeof callbackResult === "object" ? callbackResult : item.create;
175
+ await this.visitSubPayload(model, action, subPayload, newContext.nestingPath);
176
+ }
177
+ }
178
+ break;
179
+ case "connect":
180
+ if (this.callback.connect) {
181
+ for (const item of this.enumerateReverse(data)) {
182
+ const newContext = pushNewContext(field, model, item, true);
183
+ await this.callback.connect(model, item, newContext);
184
+ }
185
+ }
186
+ break;
187
+ case "disconnect":
188
+ if (this.callback.disconnect) {
189
+ for (const item of this.enumerateReverse(data)) {
190
+ const newContext = pushNewContext(field, model, item, typeof item === "object");
191
+ await this.callback.disconnect(model, item, newContext);
192
+ }
193
+ }
194
+ break;
195
+ case "set":
196
+ if (this.callback.set) {
197
+ for (const item of this.enumerateReverse(data)) {
198
+ const newContext = pushNewContext(field, model, item, true);
199
+ await this.callback.set(model, item, newContext);
200
+ }
201
+ }
202
+ break;
203
+ case "update":
204
+ for (const item of this.enumerateReverse(data)) {
205
+ const newContext = pushNewContext(field, model, item.where);
206
+ let callbackResult;
207
+ if (this.callback.update) {
208
+ callbackResult = await this.callback.update(model, item, newContext);
209
+ }
210
+ if (callbackResult !== false) {
211
+ const subPayload = typeof callbackResult === "object" ? callbackResult : typeof item.data === "object" ? item.data : item;
212
+ await this.visitSubPayload(model, action, subPayload, newContext.nestingPath);
213
+ }
214
+ }
215
+ break;
216
+ case "updateMany":
217
+ case "updateManyAndReturn":
218
+ for (const item of this.enumerateReverse(data)) {
219
+ const newContext = pushNewContext(field, model, item.where);
220
+ let callbackResult;
221
+ if (this.callback.updateMany) {
222
+ callbackResult = await this.callback.updateMany(model, item, newContext);
223
+ }
224
+ if (callbackResult !== false) {
225
+ const subPayload = typeof callbackResult === "object" ? callbackResult : item;
226
+ await this.visitSubPayload(model, action, subPayload, newContext.nestingPath);
227
+ }
228
+ }
229
+ break;
230
+ case "upsert": {
231
+ for (const item of this.enumerateReverse(data)) {
232
+ const newContext = pushNewContext(field, model, item.where);
233
+ let callbackResult;
234
+ if (this.callback.upsert) {
235
+ callbackResult = await this.callback.upsert(model, item, newContext);
236
+ }
237
+ if (callbackResult !== false) {
238
+ if (typeof callbackResult === "object") {
239
+ await this.visitSubPayload(model, action, callbackResult, newContext.nestingPath);
240
+ } else {
241
+ await this.visitSubPayload(model, action, item.create, newContext.nestingPath);
242
+ await this.visitSubPayload(model, action, item.update, newContext.nestingPath);
243
+ }
244
+ }
245
+ }
246
+ break;
247
+ }
248
+ case "delete": {
249
+ if (this.callback.delete) {
250
+ for (const item of this.enumerateReverse(data)) {
251
+ const newContext = pushNewContext(field, model, toplevel ? item.where : item);
252
+ await this.callback.delete(model, item, newContext);
253
+ }
254
+ }
255
+ break;
256
+ }
257
+ case "deleteMany":
258
+ if (this.callback.deleteMany) {
259
+ for (const item of this.enumerateReverse(data)) {
260
+ const newContext = pushNewContext(field, model, toplevel ? item.where : item);
261
+ await this.callback.deleteMany(model, item, newContext);
262
+ }
263
+ }
264
+ break;
265
+ default: {
266
+ throw new Error(`unhandled action type ${action}`);
267
+ }
268
+ }
269
+ }
270
+ async visitSubPayload(model, action, payload, nestingPath) {
271
+ for (const item of (0, import_common_helpers.enumerate)(payload)) {
272
+ if (!item || typeof item !== "object") {
273
+ continue;
274
+ }
275
+ for (const field of Object.keys(item)) {
276
+ const fieldDef = this.schema.models[model]?.fields[field];
277
+ if (!fieldDef) {
278
+ continue;
279
+ }
280
+ if (fieldDef.relation) {
281
+ if (item[field]) {
282
+ for (const [subAction, subData] of Object.entries(item[field])) {
283
+ if (this.isWriteAction(subAction) && subData) {
284
+ await this.doVisit(fieldDef.type, subAction, subData, item[field], fieldDef, [
285
+ ...nestingPath
286
+ ]);
287
+ }
288
+ }
289
+ }
290
+ } else {
291
+ if (this.callback.field) {
292
+ await this.callback.field(fieldDef, action, item[field], {
293
+ parent: item,
294
+ nestingPath,
295
+ field: fieldDef
296
+ });
297
+ }
298
+ }
299
+ }
300
+ }
301
+ }
302
+ // enumerate a (possible) array in reverse order, so that the enumeration
303
+ // callback can safely delete the current item
304
+ *enumerateReverse(data) {
305
+ if (Array.isArray(data)) {
306
+ for (let i = data.length - 1; i >= 0; i--) {
307
+ yield data[i];
308
+ }
309
+ } else {
310
+ yield data;
311
+ }
312
+ }
313
+ };
314
+
315
+ // src/utils/mutator.ts
316
+ async function applyMutation(queryModel, queryOp, queryData, mutationModel, mutationOp, mutationArgs, schema, logging) {
317
+ if (!queryData || typeof queryData !== "object" && !Array.isArray(queryData)) {
318
+ return void 0;
319
+ }
320
+ if (!queryOp.startsWith("find")) {
321
+ return void 0;
322
+ }
323
+ return await doApplyMutation(queryModel, queryData, mutationModel, mutationOp, mutationArgs, schema, logging);
324
+ }
325
+ __name(applyMutation, "applyMutation");
326
+ async function doApplyMutation(queryModel, queryData, mutationModel, mutationOp, mutationArgs, schema, logging) {
327
+ let resultData = queryData;
328
+ let updated = false;
329
+ const visitor = new NestedWriteVisitor(schema, {
330
+ create: /* @__PURE__ */ __name((model, args) => {
331
+ if (model === queryModel && Array.isArray(resultData)) {
332
+ const r = createMutate(queryModel, resultData, args, schema, logging);
333
+ if (r) {
334
+ resultData = r;
335
+ updated = true;
336
+ }
337
+ }
338
+ }, "create"),
339
+ createMany: /* @__PURE__ */ __name((model, args) => {
340
+ if (model === queryModel && args?.data && Array.isArray(resultData)) {
341
+ for (const oneArg of (0, import_common_helpers2.enumerate)(args.data)) {
342
+ const r = createMutate(queryModel, resultData, oneArg, schema, logging);
343
+ if (r) {
344
+ resultData = r;
345
+ updated = true;
346
+ }
347
+ }
348
+ }
349
+ }, "createMany"),
350
+ update: /* @__PURE__ */ __name((model, args) => {
351
+ if (model === queryModel && !Array.isArray(resultData)) {
352
+ const r = updateMutate(queryModel, resultData, model, args, schema, logging);
353
+ if (r) {
354
+ resultData = r;
355
+ updated = true;
356
+ }
357
+ }
358
+ }, "update"),
359
+ upsert: /* @__PURE__ */ __name((model, args) => {
360
+ if (model === queryModel && args?.where && args?.create && args?.update) {
361
+ const r = upsertMutate(queryModel, resultData, model, args, schema, logging);
362
+ if (r) {
363
+ resultData = r;
364
+ updated = true;
365
+ }
366
+ }
367
+ }, "upsert"),
368
+ delete: /* @__PURE__ */ __name((model, args) => {
369
+ if (model === queryModel) {
370
+ const r = deleteMutate(queryModel, resultData, model, args, schema, logging);
371
+ if (r) {
372
+ resultData = r;
373
+ updated = true;
374
+ }
375
+ }
376
+ }, "delete")
377
+ });
378
+ await visitor.visit(mutationModel, mutationOp, mutationArgs);
379
+ const modelFields = schema.models[queryModel]?.fields;
380
+ (0, import_common_helpers2.invariant)(modelFields, `Model ${queryModel} not found in schema`);
381
+ if (Array.isArray(resultData)) {
382
+ let arrayCloned = false;
383
+ for (let i = 0; i < resultData.length; i++) {
384
+ const item = resultData[i];
385
+ if (!item || typeof item !== "object" || item.$optimistic) {
386
+ continue;
387
+ }
388
+ const r = await doApplyMutation(queryModel, item, mutationModel, mutationOp, mutationArgs, schema, logging);
389
+ if (r && typeof r === "object") {
390
+ if (!arrayCloned) {
391
+ resultData = [
392
+ ...resultData
393
+ ];
394
+ arrayCloned = true;
395
+ }
396
+ resultData[i] = r;
397
+ updated = true;
398
+ }
399
+ }
400
+ } else if (resultData !== null && typeof resultData === "object") {
401
+ const currentData = {
402
+ ...resultData
403
+ };
404
+ for (const [key, value] of Object.entries(currentData)) {
405
+ const fieldDef = modelFields[key];
406
+ if (!fieldDef?.relation) {
407
+ continue;
408
+ }
409
+ const r = await doApplyMutation(fieldDef.type, value, mutationModel, mutationOp, mutationArgs, schema, logging);
410
+ if (r && typeof r === "object") {
411
+ resultData = {
412
+ ...resultData,
413
+ [key]: r
414
+ };
415
+ updated = true;
416
+ }
417
+ }
418
+ }
419
+ return updated ? resultData : void 0;
420
+ }
421
+ __name(doApplyMutation, "doApplyMutation");
422
+ function createMutate(queryModel, currentData, newData, schema, logging) {
423
+ if (!newData) {
424
+ return void 0;
425
+ }
426
+ const modelFields = schema.models[queryModel]?.fields;
427
+ if (!modelFields) {
428
+ return void 0;
429
+ }
430
+ const insert = {};
431
+ const newDataFields = Object.keys(newData);
432
+ Object.entries(modelFields).forEach(([name, field]) => {
433
+ if (field.relation && newData[name]) {
434
+ assignForeignKeyFields(field, insert, newData[name]);
435
+ return;
436
+ }
437
+ if (newDataFields.includes(name)) {
438
+ insert[name] = (0, import_common_helpers2.clone)(newData[name]);
439
+ } else {
440
+ const defaultAttr = field.attributes?.find((attr) => attr.name === "@default");
441
+ if (field.type === "DateTime") {
442
+ if (defaultAttr || field.attributes?.some((attr) => attr.name === "@updatedAt")) {
443
+ insert[name] = /* @__PURE__ */ new Date();
444
+ return;
445
+ }
446
+ }
447
+ const defaultArg = defaultAttr?.args?.[0]?.value;
448
+ if (defaultArg?.kind === "literal") {
449
+ insert[name] = defaultArg.value;
450
+ }
451
+ }
452
+ });
453
+ const idFields = getIdFields(schema, queryModel);
454
+ idFields.forEach((f) => {
455
+ if (insert[f.name] === void 0) {
456
+ if (f.type === "Int" || f.type === "BigInt") {
457
+ const currMax = Array.isArray(currentData) ? Math.max(...[
458
+ ...currentData
459
+ ].map((item) => {
460
+ const idv = parseInt(item[f.name]);
461
+ return isNaN(idv) ? 0 : idv;
462
+ })) : 0;
463
+ insert[f.name] = currMax + 1;
464
+ } else {
465
+ insert[f.name] = crypto.randomUUID();
466
+ }
467
+ }
468
+ });
469
+ insert.$optimistic = true;
470
+ if (logging) {
471
+ console.log(`Optimistic create for ${queryModel}:`, insert);
472
+ }
473
+ return [
474
+ insert,
475
+ ...Array.isArray(currentData) ? currentData : []
476
+ ];
477
+ }
478
+ __name(createMutate, "createMutate");
479
+ function updateMutate(queryModel, currentData, mutateModel, mutateArgs, schema, logging) {
480
+ if (!currentData || typeof currentData !== "object") {
481
+ return void 0;
482
+ }
483
+ if (!mutateArgs?.where || typeof mutateArgs.where !== "object") {
484
+ return void 0;
485
+ }
486
+ if (!mutateArgs?.data || typeof mutateArgs.data !== "object") {
487
+ return void 0;
488
+ }
489
+ if (!idFieldsMatch(mutateModel, currentData, mutateArgs.where, schema)) {
490
+ return void 0;
491
+ }
492
+ const modelFields = schema.models[queryModel]?.fields;
493
+ if (!modelFields) {
494
+ return void 0;
495
+ }
496
+ let updated = false;
497
+ let resultData = currentData;
498
+ for (const [key, value] of Object.entries(mutateArgs.data)) {
499
+ const fieldInfo = modelFields[key];
500
+ if (!fieldInfo) {
501
+ continue;
502
+ }
503
+ if (fieldInfo.relation && !value?.connect) {
504
+ continue;
505
+ }
506
+ if (!updated) {
507
+ resultData = {
508
+ ...currentData
509
+ };
510
+ }
511
+ if (fieldInfo.relation) {
512
+ assignForeignKeyFields(fieldInfo, resultData, value);
513
+ } else {
514
+ resultData[key] = (0, import_common_helpers2.clone)(value);
515
+ }
516
+ resultData.$optimistic = true;
517
+ updated = true;
518
+ if (logging) {
519
+ console.log(`Optimistic update for ${queryModel}:`, resultData);
520
+ }
521
+ }
522
+ return updated ? resultData : void 0;
523
+ }
524
+ __name(updateMutate, "updateMutate");
525
+ function upsertMutate(queryModel, currentData, model, args, schema, logging) {
526
+ let updated = false;
527
+ let resultData = currentData;
528
+ if (Array.isArray(resultData)) {
529
+ const foundIndex = resultData.findIndex((x) => idFieldsMatch(model, x, args.where, schema));
530
+ if (foundIndex >= 0) {
531
+ const updateResult = updateMutate(queryModel, resultData[foundIndex], model, {
532
+ where: args.where,
533
+ data: args.update
534
+ }, schema, logging);
535
+ if (updateResult) {
536
+ resultData = [
537
+ ...resultData.slice(0, foundIndex),
538
+ updateResult,
539
+ ...resultData.slice(foundIndex + 1)
540
+ ];
541
+ updated = true;
542
+ }
543
+ } else {
544
+ const createResult = createMutate(queryModel, resultData, args.create, schema, logging);
545
+ if (createResult) {
546
+ resultData = createResult;
547
+ updated = true;
548
+ }
549
+ }
550
+ } else {
551
+ const updateResult = updateMutate(queryModel, resultData, model, {
552
+ where: args.where,
553
+ data: args.update
554
+ }, schema, logging);
555
+ if (updateResult) {
556
+ resultData = updateResult;
557
+ updated = true;
558
+ }
559
+ }
560
+ return updated ? resultData : void 0;
561
+ }
562
+ __name(upsertMutate, "upsertMutate");
563
+ function deleteMutate(queryModel, currentData, mutateModel, mutateArgs, schema, logging) {
564
+ if (!currentData || !mutateArgs) {
565
+ return void 0;
566
+ }
567
+ if (queryModel !== mutateModel) {
568
+ return void 0;
569
+ }
570
+ let updated = false;
571
+ let result = currentData;
572
+ if (Array.isArray(currentData)) {
573
+ for (const item of currentData) {
574
+ if (idFieldsMatch(mutateModel, item, mutateArgs, schema)) {
575
+ result = result.filter((x) => x !== item);
576
+ updated = true;
577
+ if (logging) {
578
+ console.log(`Optimistic delete for ${queryModel}:`, item);
579
+ }
580
+ }
581
+ }
582
+ } else {
583
+ if (idFieldsMatch(mutateModel, currentData, mutateArgs, schema)) {
584
+ result = null;
585
+ updated = true;
586
+ if (logging) {
587
+ console.log(`Optimistic delete for ${queryModel}:`, currentData);
588
+ }
589
+ }
590
+ }
591
+ return updated ? result : void 0;
592
+ }
593
+ __name(deleteMutate, "deleteMutate");
594
+ function idFieldsMatch(model, x, y, schema) {
595
+ if (!x || !y || typeof x !== "object" || typeof y !== "object") {
596
+ return false;
597
+ }
598
+ const idFields = getIdFields(schema, model);
599
+ if (idFields.length === 0) {
600
+ return false;
601
+ }
602
+ return idFields.every((f) => x[f.name] === y[f.name]);
603
+ }
604
+ __name(idFieldsMatch, "idFieldsMatch");
605
+ function assignForeignKeyFields(field, resultData, mutationData) {
606
+ if (!mutationData?.connect) {
607
+ return;
608
+ }
609
+ if (!field.relation?.fields || !field.relation.references) {
610
+ return;
611
+ }
612
+ for (const [idField, fkField] of (0, import_common_helpers2.zip)(field.relation.references, field.relation.fields)) {
613
+ if (idField in mutationData.connect) {
614
+ resultData[fkField] = mutationData.connect[idField];
615
+ }
616
+ }
617
+ }
618
+ __name(assignForeignKeyFields, "assignForeignKeyFields");
619
+ function getIdFields(schema, model) {
620
+ return (schema.models[model]?.idFields ?? []).map((f) => schema.models[model].fields[f]);
621
+ }
622
+ __name(getIdFields, "getIdFields");
623
+
624
+ // src/utils/nested-read-visitor.ts
625
+ var NestedReadVisitor = class {
626
+ static {
627
+ __name(this, "NestedReadVisitor");
628
+ }
629
+ schema;
630
+ callback;
631
+ constructor(schema, callback) {
632
+ this.schema = schema;
633
+ this.callback = callback;
634
+ }
635
+ doVisit(model, field, kind, args) {
636
+ if (this.callback.field) {
637
+ const r = this.callback.field(model, field, kind, args);
638
+ if (r === false) {
639
+ return;
640
+ }
641
+ }
642
+ if (!args || typeof args !== "object") {
643
+ return;
644
+ }
645
+ let selectInclude;
646
+ let nextKind;
647
+ if (args.select) {
648
+ selectInclude = args.select;
649
+ nextKind = "select";
650
+ } else if (args.include) {
651
+ selectInclude = args.include;
652
+ nextKind = "include";
653
+ }
654
+ if (selectInclude && typeof selectInclude === "object") {
655
+ for (const [k, v] of Object.entries(selectInclude)) {
656
+ if (k === "_count" && typeof v === "object" && v) {
657
+ this.doVisit(model, field, kind, v);
658
+ } else {
659
+ const field2 = this.schema.models[model]?.fields[k];
660
+ if (field2) {
661
+ this.doVisit(field2.type, field2, nextKind, v);
662
+ }
663
+ }
664
+ }
665
+ }
666
+ }
667
+ visit(model, args) {
668
+ this.doVisit(model, void 0, void 0, args);
669
+ }
670
+ };
671
+
672
+ // src/utils/query-analysis.ts
673
+ function getReadModels(model, schema, args) {
674
+ const result = /* @__PURE__ */ new Set();
675
+ result.add(model);
676
+ const visitor = new NestedReadVisitor(schema, {
677
+ field: /* @__PURE__ */ __name((model2) => {
678
+ result.add(model2);
679
+ return true;
680
+ }, "field")
681
+ });
682
+ visitor.visit(model, args);
683
+ return [
684
+ ...result
685
+ ];
686
+ }
687
+ __name(getReadModels, "getReadModels");
688
+ async function getMutatedModels(model, operation, mutationArgs, schema) {
689
+ const result = /* @__PURE__ */ new Set();
690
+ result.add(model);
691
+ if (mutationArgs) {
692
+ const addModel = /* @__PURE__ */ __name((model2) => void result.add(model2), "addModel");
693
+ const addCascades = /* @__PURE__ */ __name((model2) => {
694
+ const cascades = /* @__PURE__ */ new Set();
695
+ const visited = /* @__PURE__ */ new Set();
696
+ collectDeleteCascades(model2, schema, cascades, visited);
697
+ cascades.forEach((m) => addModel(m));
698
+ }, "addCascades");
699
+ const visitor = new NestedWriteVisitor(schema, {
700
+ create: addModel,
701
+ createMany: addModel,
702
+ connectOrCreate: addModel,
703
+ connect: addModel,
704
+ disconnect: addModel,
705
+ set: addModel,
706
+ update: addModel,
707
+ updateMany: addModel,
708
+ upsert: addModel,
709
+ delete: /* @__PURE__ */ __name((model2) => {
710
+ addModel(model2);
711
+ addCascades(model2);
712
+ }, "delete"),
713
+ deleteMany: /* @__PURE__ */ __name((model2) => {
714
+ addModel(model2);
715
+ addCascades(model2);
716
+ }, "deleteMany")
717
+ });
718
+ await visitor.visit(model, operation, mutationArgs);
719
+ }
720
+ result.forEach((m) => {
721
+ getBaseRecursively(m, schema, result);
722
+ });
723
+ return [
724
+ ...result
725
+ ];
726
+ }
727
+ __name(getMutatedModels, "getMutatedModels");
728
+ function collectDeleteCascades(model, schema, result, visited) {
729
+ if (visited.has(model)) {
730
+ return;
731
+ }
732
+ visited.add(model);
733
+ const modelDef = schema.models[model];
734
+ if (!modelDef) {
735
+ return;
736
+ }
737
+ for (const [modelName, modelDef2] of Object.entries(schema.models)) {
738
+ if (!modelDef2) {
739
+ continue;
740
+ }
741
+ for (const fieldDef of Object.values(modelDef2.fields)) {
742
+ if (fieldDef.relation?.onDelete === "Cascade" && fieldDef.type === model) {
743
+ if (!result.has(modelName)) {
744
+ result.add(modelName);
745
+ }
746
+ collectDeleteCascades(modelName, schema, result, visited);
747
+ }
748
+ }
749
+ }
750
+ }
751
+ __name(collectDeleteCascades, "collectDeleteCascades");
752
+ function getBaseRecursively(model, schema, result) {
753
+ const modelDef = schema.models[model];
754
+ if (!modelDef) {
755
+ return;
756
+ }
757
+ if (modelDef.baseModel) {
758
+ result.add(modelDef.baseModel);
759
+ getBaseRecursively(modelDef.baseModel, schema, result);
760
+ }
761
+ }
762
+ __name(getBaseRecursively, "getBaseRecursively");
763
+
764
+ // src/utils/serialization.ts
765
+ var import_buffer = require("buffer");
766
+ var import_decimal = __toESM(require("decimal.js"), 1);
767
+ var import_superjson = __toESM(require("superjson"), 1);
768
+ import_superjson.default.registerCustom({
769
+ isApplicable: /* @__PURE__ */ __name((v) => v instanceof import_decimal.default || // interop with decimal.js
770
+ v?.toStringTag === "[object Decimal]", "isApplicable"),
771
+ serialize: /* @__PURE__ */ __name((v) => v.toJSON(), "serialize"),
772
+ deserialize: /* @__PURE__ */ __name((v) => new import_decimal.default(v), "deserialize")
773
+ }, "Decimal");
774
+ import_superjson.default.registerCustom({
775
+ isApplicable: /* @__PURE__ */ __name((v) => import_buffer.Buffer.isBuffer(v), "isApplicable"),
776
+ serialize: /* @__PURE__ */ __name((v) => v.toString("base64"), "serialize"),
777
+ deserialize: /* @__PURE__ */ __name((v) => import_buffer.Buffer.from(v, "base64"), "deserialize")
778
+ }, "Bytes");
779
+ function serialize(value) {
780
+ const { json, meta } = import_superjson.default.serialize(value);
781
+ return {
782
+ data: json,
783
+ meta
784
+ };
785
+ }
786
+ __name(serialize, "serialize");
787
+ function deserialize(value, meta) {
788
+ return import_superjson.default.deserialize({
789
+ json: value,
790
+ meta
791
+ });
792
+ }
793
+ __name(deserialize, "deserialize");
794
+
795
+ // src/utils/common.ts
796
+ var QUERY_KEY_PREFIX = "zenstack";
797
+ async function fetcher(url, options, customFetch) {
798
+ const _fetch = customFetch ?? fetch;
799
+ const res = await _fetch(url, options);
800
+ if (!res.ok) {
801
+ const errData = unmarshal(await res.text());
802
+ if (errData.error?.rejectedByPolicy && errData.error?.rejectReason === "cannot-read-back") {
803
+ return void 0;
804
+ }
805
+ const error = new Error("An error occurred while fetching the data.");
806
+ error.info = errData.error;
807
+ error.status = res.status;
808
+ throw error;
809
+ }
810
+ const textResult = await res.text();
811
+ try {
812
+ return unmarshal(textResult).data;
813
+ } catch (err) {
814
+ console.error(`Unable to deserialize data:`, textResult);
815
+ throw err;
816
+ }
817
+ }
818
+ __name(fetcher, "fetcher");
819
+ function getQueryKey(model, operation, args, options = {
820
+ infinite: false,
821
+ optimisticUpdate: true
822
+ }) {
823
+ const infinite = options.infinite;
824
+ const optimisticUpdate2 = options.infinite ? false : options.optimisticUpdate;
825
+ return [
826
+ QUERY_KEY_PREFIX,
827
+ model,
828
+ operation,
829
+ args,
830
+ {
831
+ infinite,
832
+ optimisticUpdate: optimisticUpdate2
833
+ }
834
+ ];
835
+ }
836
+ __name(getQueryKey, "getQueryKey");
837
+ function marshal(value) {
838
+ const { data, meta } = serialize(value);
839
+ if (meta) {
840
+ return JSON.stringify({
841
+ ...data,
842
+ meta: {
843
+ serialization: meta
844
+ }
845
+ });
846
+ } else {
847
+ return JSON.stringify(data);
848
+ }
849
+ }
850
+ __name(marshal, "marshal");
851
+ function unmarshal(value) {
852
+ const parsed = JSON.parse(value);
853
+ if (typeof parsed === "object" && parsed?.data && parsed?.meta?.serialization) {
854
+ const deserializedData = deserialize(parsed.data, parsed.meta.serialization);
855
+ return {
856
+ ...parsed,
857
+ data: deserializedData
858
+ };
859
+ } else {
860
+ return parsed;
861
+ }
862
+ }
863
+ __name(unmarshal, "unmarshal");
864
+ function makeUrl(endpoint, model, operation, args) {
865
+ const baseUrl = `${endpoint}/${(0, import_common_helpers3.lowerCaseFirst)(model)}/${operation}`;
866
+ if (!args) {
867
+ return baseUrl;
868
+ }
869
+ const { data, meta } = serialize(args);
870
+ let result = `${baseUrl}?q=${encodeURIComponent(JSON.stringify(data))}`;
871
+ if (meta) {
872
+ result += `&meta=${encodeURIComponent(JSON.stringify({
873
+ serialization: meta
874
+ }))}`;
875
+ }
876
+ return result;
877
+ }
878
+ __name(makeUrl, "makeUrl");
879
+ function setupInvalidation(model, operation, schema, options, invalidate, logging = false) {
880
+ const origOnSuccess = options?.onSuccess;
881
+ options.onSuccess = async (...args) => {
882
+ const [_, variables] = args;
883
+ const predicate = await getInvalidationPredicate(model, operation, variables, schema, logging);
884
+ await invalidate(predicate);
885
+ return origOnSuccess?.(...args);
886
+ };
887
+ }
888
+ __name(setupInvalidation, "setupInvalidation");
889
+ async function getInvalidationPredicate(model, operation, mutationArgs, schema, logging = false) {
890
+ const mutatedModels = await getMutatedModels(model, operation, mutationArgs, schema);
891
+ return ({ queryKey }) => {
892
+ const [_, queryModel, , args] = queryKey;
893
+ if (mutatedModels.includes(queryModel)) {
894
+ if (logging) {
895
+ console.log(`Invalidating query ${JSON.stringify(queryKey)} due to mutation "${model}.${operation}"`);
896
+ }
897
+ return true;
898
+ }
899
+ if (args) {
900
+ if (findNestedRead(queryModel, mutatedModels, schema, args)) {
901
+ if (logging) {
902
+ console.log(`Invalidating query ${JSON.stringify(queryKey)} due to mutation "${model}.${operation}"`);
903
+ }
904
+ return true;
905
+ }
906
+ }
907
+ return false;
908
+ };
909
+ }
910
+ __name(getInvalidationPredicate, "getInvalidationPredicate");
911
+ function findNestedRead(visitingModel, targetModels, schema, args) {
912
+ const modelsRead = getReadModels(visitingModel, schema, args);
913
+ return targetModels.some((m) => modelsRead.includes(m));
914
+ }
915
+ __name(findNestedRead, "findNestedRead");
916
+ function setupOptimisticUpdate(model, operation, schema, options, queryCache, setCache, invalidate, logging = false) {
917
+ const origOnMutate = options?.onMutate;
918
+ const origOnSettled = options?.onSettled;
919
+ options.onMutate = async (...args) => {
920
+ const [variables] = args;
921
+ await optimisticUpdate(model, operation, variables, options, schema, queryCache, setCache, logging);
922
+ return origOnMutate?.(...args);
923
+ };
924
+ options.onSettled = async (...args) => {
925
+ if (invalidate) {
926
+ const [, , variables] = args;
927
+ const predicate = await getInvalidationPredicate(model, operation, variables, schema, logging);
928
+ await invalidate(predicate);
929
+ }
930
+ return origOnSettled?.(...args);
931
+ };
932
+ }
933
+ __name(setupOptimisticUpdate, "setupOptimisticUpdate");
934
+ async function optimisticUpdate(mutationModel, mutationOp, mutationArgs, options, schema, queryCache, setCache, logging = false) {
935
+ for (const cacheItem of queryCache) {
936
+ const { queryKey, state: { data, error } } = cacheItem;
937
+ if (!isZenStackQueryKey(queryKey)) {
938
+ continue;
939
+ }
940
+ if (error) {
941
+ if (logging) {
942
+ console.warn(`Skipping optimistic update for ${JSON.stringify(queryKey)} due to error:`, error);
943
+ }
944
+ continue;
945
+ }
946
+ const [_, queryModel, queryOperation, queryArgs, queryOptions] = queryKey;
947
+ if (!queryOptions?.optimisticUpdate) {
948
+ if (logging) {
949
+ console.log(`Skipping optimistic update for ${JSON.stringify(queryKey)} due to opt-out`);
950
+ }
951
+ continue;
952
+ }
953
+ if (options.optimisticDataProvider) {
954
+ const providerResult = await options.optimisticDataProvider({
955
+ queryModel,
956
+ queryOperation,
957
+ queryArgs,
958
+ currentData: data,
959
+ mutationArgs
960
+ });
961
+ if (providerResult?.kind === "Skip") {
962
+ if (logging) {
963
+ console.log(`Skipping optimistic update for ${JSON.stringify(queryKey)} due to provider`);
964
+ }
965
+ continue;
966
+ } else if (providerResult?.kind === "Update") {
967
+ if (logging) {
968
+ console.log(`Optimistically updating query ${JSON.stringify(queryKey)} due to provider`);
969
+ }
970
+ setCache(queryKey, providerResult.data);
971
+ continue;
972
+ }
973
+ }
974
+ const mutatedData = await applyMutation(queryModel, queryOperation, data, mutationModel, mutationOp, mutationArgs, schema, logging);
975
+ if (mutatedData !== void 0) {
976
+ if (logging) {
977
+ console.log(`Optimistically updating query ${JSON.stringify(queryKey)} due to mutation "${mutationModel}.${mutationOp}"`);
978
+ }
979
+ setCache(queryKey, mutatedData);
980
+ }
981
+ }
982
+ }
983
+ __name(optimisticUpdate, "optimisticUpdate");
984
+ function isZenStackQueryKey(queryKey) {
985
+ if (queryKey.length < 5) {
986
+ return false;
987
+ }
988
+ if (queryKey[0] !== QUERY_KEY_PREFIX) {
989
+ return false;
990
+ }
991
+ return true;
992
+ }
993
+ __name(isZenStackQueryKey, "isZenStackQueryKey");
994
+
995
+ // src/svelte.ts
996
+ var DEFAULT_QUERY_ENDPOINT = "/api/model";
997
+ var SvelteQueryContextKey = "zenstack-svelte-query-context";
998
+ function setHooksContext(context) {
999
+ (0, import_svelte.setContext)(SvelteQueryContextKey, context);
1000
+ }
1001
+ __name(setHooksContext, "setHooksContext");
1002
+ function setQuerySettingsContext(context) {
1003
+ (0, import_svelte.setContext)(SvelteQueryContextKey, context);
1004
+ }
1005
+ __name(setQuerySettingsContext, "setQuerySettingsContext");
1006
+ function getQuerySettings() {
1007
+ const { endpoint, ...rest } = (0, import_svelte.getContext)(SvelteQueryContextKey) ?? {};
1008
+ return {
1009
+ endpoint: endpoint ?? DEFAULT_QUERY_ENDPOINT,
1010
+ ...rest
1011
+ };
1012
+ }
1013
+ __name(getQuerySettings, "getQuerySettings");
1014
+ function useClientQueries(schema) {
1015
+ return Object.keys(schema.models).reduce((acc, model) => {
1016
+ acc[(0, import_common_helpers4.lowerCaseFirst)(model)] = useModelQueries(schema, model);
1017
+ return acc;
1018
+ }, {});
1019
+ }
1020
+ __name(useClientQueries, "useClientQueries");
1021
+ function useModelQueries(schema, model) {
1022
+ const modelDef = Object.values(schema.models).find((m) => m.name.toLowerCase() === model.toLowerCase());
1023
+ if (!modelDef) {
1024
+ throw new Error(`Model "${model}" not found in schema`);
1025
+ }
1026
+ const modelName = modelDef.name;
1027
+ return {
1028
+ useFindUnique: /* @__PURE__ */ __name((args, options) => {
1029
+ return useInternalQuery(schema, modelName, "findUnique", args, options);
1030
+ }, "useFindUnique"),
1031
+ useFindFirst: /* @__PURE__ */ __name((args, options) => {
1032
+ return useInternalQuery(schema, modelName, "findFirst", args, options);
1033
+ }, "useFindFirst"),
1034
+ useFindMany: /* @__PURE__ */ __name((args, options) => {
1035
+ return useInternalQuery(schema, modelName, "findMany", args, options);
1036
+ }, "useFindMany"),
1037
+ useInfiniteFindMany: /* @__PURE__ */ __name((args, options) => {
1038
+ return useInternalInfiniteQuery(schema, modelName, "findMany", args, options);
1039
+ }, "useInfiniteFindMany"),
1040
+ useCreate: /* @__PURE__ */ __name((options) => {
1041
+ return useInternalMutation(schema, modelName, "POST", "create", options);
1042
+ }, "useCreate"),
1043
+ useCreateMany: /* @__PURE__ */ __name((options) => {
1044
+ return useInternalMutation(schema, modelName, "POST", "createMany", options);
1045
+ }, "useCreateMany"),
1046
+ useCreateManyAndReturn: /* @__PURE__ */ __name((options) => {
1047
+ return useInternalMutation(schema, modelName, "POST", "createManyAndReturn", options);
1048
+ }, "useCreateManyAndReturn"),
1049
+ useUpdate: /* @__PURE__ */ __name((options) => {
1050
+ return useInternalMutation(schema, modelName, "PUT", "update", options);
1051
+ }, "useUpdate"),
1052
+ useUpdateMany: /* @__PURE__ */ __name((options) => {
1053
+ return useInternalMutation(schema, modelName, "PUT", "updateMany", options);
1054
+ }, "useUpdateMany"),
1055
+ useUpdateManyAndReturn: /* @__PURE__ */ __name((options) => {
1056
+ return useInternalMutation(schema, modelName, "PUT", "updateManyAndReturn", options);
1057
+ }, "useUpdateManyAndReturn"),
1058
+ useUpsert: /* @__PURE__ */ __name((options) => {
1059
+ return useInternalMutation(schema, modelName, "POST", "upsert", options);
1060
+ }, "useUpsert"),
1061
+ useDelete: /* @__PURE__ */ __name((options) => {
1062
+ return useInternalMutation(schema, modelName, "DELETE", "delete", options);
1063
+ }, "useDelete"),
1064
+ useDeleteMany: /* @__PURE__ */ __name((options) => {
1065
+ return useInternalMutation(schema, modelName, "DELETE", "deleteMany", options);
1066
+ }, "useDeleteMany"),
1067
+ useCount: /* @__PURE__ */ __name((args, options) => {
1068
+ return useInternalQuery(schema, modelName, "count", args, options);
1069
+ }, "useCount"),
1070
+ useAggregate: /* @__PURE__ */ __name((args, options) => {
1071
+ return useInternalQuery(schema, modelName, "aggregate", args, options);
1072
+ }, "useAggregate"),
1073
+ useGroupBy: /* @__PURE__ */ __name((args, options) => {
1074
+ return useInternalQuery(schema, modelName, "groupBy", args, options);
1075
+ }, "useGroupBy")
1076
+ };
1077
+ }
1078
+ __name(useModelQueries, "useModelQueries");
1079
+ function useInternalQuery(_schema, model, operation, args, options) {
1080
+ const { endpoint, fetch: fetch2 } = getQuerySettings();
1081
+ const argsValue = unwrapStore(args);
1082
+ const reqUrl = makeUrl(endpoint, model, operation, argsValue);
1083
+ const optionsValue = unwrapStore(options);
1084
+ const queryKey = getQueryKey(model, operation, argsValue, {
1085
+ infinite: false,
1086
+ optimisticUpdate: optionsValue?.optimisticUpdate !== false
1087
+ });
1088
+ const queryFn = /* @__PURE__ */ __name(({ signal }) => fetcher(reqUrl, {
1089
+ signal
1090
+ }, fetch2), "queryFn");
1091
+ let mergedOpt;
1092
+ if (isStore(options)) {
1093
+ mergedOpt = (0, import_store.derived)([
1094
+ options
1095
+ ], ([$opt]) => {
1096
+ return {
1097
+ queryKey,
1098
+ queryFn,
1099
+ ...$opt
1100
+ };
1101
+ });
1102
+ } else {
1103
+ mergedOpt = {
1104
+ queryKey,
1105
+ queryFn,
1106
+ ...options
1107
+ };
1108
+ }
1109
+ const result = (0, import_svelte_query.createQuery)(mergedOpt);
1110
+ return (0, import_store.derived)(result, (r) => ({
1111
+ queryKey,
1112
+ ...r
1113
+ }));
1114
+ }
1115
+ __name(useInternalQuery, "useInternalQuery");
1116
+ function useInternalInfiniteQuery(_schema, model, operation, args, options) {
1117
+ options = options ?? {
1118
+ getNextPageParam: /* @__PURE__ */ __name(() => void 0, "getNextPageParam")
1119
+ };
1120
+ const { endpoint, fetch: fetch2 } = getQuerySettings();
1121
+ const argsValue = unwrapStore(args);
1122
+ const queryKey = getQueryKey(model, operation, argsValue, {
1123
+ infinite: true,
1124
+ optimisticUpdate: false
1125
+ });
1126
+ const queryFn = /* @__PURE__ */ __name(({ pageParam, signal }) => fetcher(makeUrl(endpoint, model, operation, pageParam ?? argsValue), {
1127
+ signal
1128
+ }, fetch2), "queryFn");
1129
+ let mergedOpt;
1130
+ if (isStore(options)) {
1131
+ mergedOpt = (0, import_store.derived)([
1132
+ options
1133
+ ], ([$opt]) => {
1134
+ return {
1135
+ queryKey,
1136
+ queryFn,
1137
+ initialPageParam: argsValue,
1138
+ ...$opt
1139
+ };
1140
+ });
1141
+ } else {
1142
+ mergedOpt = {
1143
+ queryKey,
1144
+ queryFn,
1145
+ initialPageParam: argsValue,
1146
+ ...options
1147
+ };
1148
+ }
1149
+ const result = (0, import_svelte_query.createInfiniteQuery)(mergedOpt);
1150
+ return (0, import_store.derived)(result, (r) => ({
1151
+ queryKey,
1152
+ ...r
1153
+ }));
1154
+ }
1155
+ __name(useInternalInfiniteQuery, "useInternalInfiniteQuery");
1156
+ function useInternalMutation(schema, model, method, operation, options) {
1157
+ const { endpoint, fetch: fetch2, logging } = getQuerySettings();
1158
+ const queryClient = (0, import_svelte_query.useQueryClient)();
1159
+ const optionsValue = unwrapStore(options);
1160
+ const mutationFn = /* @__PURE__ */ __name((data) => {
1161
+ const reqUrl = method === "DELETE" ? makeUrl(endpoint, model, operation, data) : makeUrl(endpoint, model, operation);
1162
+ const fetchInit = {
1163
+ method,
1164
+ ...method !== "DELETE" && {
1165
+ headers: {
1166
+ "content-type": "application/json"
1167
+ },
1168
+ body: marshal(data)
1169
+ }
1170
+ };
1171
+ return fetcher(reqUrl, fetchInit, fetch2);
1172
+ }, "mutationFn");
1173
+ let mergedOpt;
1174
+ if (isStore(options)) {
1175
+ mergedOpt = (0, import_store.derived)([
1176
+ options
1177
+ ], ([$opt]) => ({
1178
+ ...$opt,
1179
+ mutationFn
1180
+ }));
1181
+ } else {
1182
+ mergedOpt = {
1183
+ ...options,
1184
+ mutationFn
1185
+ };
1186
+ }
1187
+ const invalidateQueries = optionsValue?.invalidateQueries !== false;
1188
+ const optimisticUpdate2 = !!optionsValue?.optimisticUpdate;
1189
+ if (operation) {
1190
+ if (invalidateQueries) {
1191
+ setupInvalidation(model, operation, schema, unwrapStore(mergedOpt), (predicate) => queryClient.invalidateQueries({
1192
+ predicate
1193
+ }), logging);
1194
+ }
1195
+ if (optimisticUpdate2) {
1196
+ setupOptimisticUpdate(model, operation, schema, unwrapStore(mergedOpt), queryClient.getQueryCache().getAll(), (queryKey, data) => queryClient.setQueryData(queryKey, data), invalidateQueries ? (predicate) => queryClient.invalidateQueries({
1197
+ predicate
1198
+ }) : void 0, logging);
1199
+ }
1200
+ }
1201
+ return (0, import_svelte_query.createMutation)(mergedOpt);
1202
+ }
1203
+ __name(useInternalMutation, "useInternalMutation");
1204
+ function isStore(opt) {
1205
+ return typeof opt?.subscribe === "function";
1206
+ }
1207
+ __name(isStore, "isStore");
1208
+ function unwrapStore(storeOrValue) {
1209
+ return isStore(storeOrValue) ? (0, import_store.get)(storeOrValue) : storeOrValue;
1210
+ }
1211
+ __name(unwrapStore, "unwrapStore");
1212
+ // Annotate the CommonJS export names for ESM import in node:
1213
+ 0 && (module.exports = {
1214
+ DEFAULT_QUERY_ENDPOINT,
1215
+ SvelteQueryContextKey,
1216
+ setHooksContext,
1217
+ setQuerySettingsContext,
1218
+ useClientQueries,
1219
+ useInternalInfiniteQuery,
1220
+ useInternalMutation,
1221
+ useInternalQuery,
1222
+ useModelQueries
1223
+ });
1224
+ //# sourceMappingURL=svelte.cjs.map