houdini 1.0.0-next.19 → 1.0.0-next.20
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/build/cmd-cjs/index.js +2220 -66
- package/build/cmd-esm/index.js +2220 -66
- package/build/codegen/generators/runtime/runtimeConfig.d.ts +7 -0
- package/build/codegen-cjs/index.js +2816 -645
- package/build/codegen-esm/index.js +2816 -645
- package/build/lib/types.d.ts +3 -3
- package/build/lib-cjs/index.js +3123 -130
- package/build/lib-esm/index.js +3116 -130
- package/build/runtime/imports/pluginConfig.d.ts +3 -0
- package/build/runtime-cjs/client/index.js +3 -0
- package/build/runtime-cjs/imports/pluginConfig.d.ts +3 -0
- package/build/runtime-cjs/imports/pluginConfig.js +27 -0
- package/build/runtime-cjs/lib/config.js +11 -1
- package/build/runtime-esm/client/index.js +3 -0
- package/build/runtime-esm/imports/pluginConfig.d.ts +3 -0
- package/build/runtime-esm/imports/pluginConfig.js +5 -0
- package/build/runtime-esm/lib/config.js +11 -1
- package/build/test-cjs/index.js +2195 -47
- package/build/test-esm/index.js +2195 -47
- package/build/vite-cjs/index.js +2218 -64
- package/build/vite-esm/index.js +2218 -64
- package/package.json +2 -2
package/build/test-esm/index.js
CHANGED
|
@@ -15650,42 +15650,42 @@ var require_node = __commonJS({
|
|
|
15650
15650
|
return Link2;
|
|
15651
15651
|
}(events_1.EventEmitter);
|
|
15652
15652
|
exports.Link = Link;
|
|
15653
|
-
var
|
|
15654
|
-
function
|
|
15653
|
+
var File2 = function() {
|
|
15654
|
+
function File3(link, node, flags, fd) {
|
|
15655
15655
|
this.position = 0;
|
|
15656
15656
|
this.link = link;
|
|
15657
15657
|
this.node = node;
|
|
15658
15658
|
this.flags = flags;
|
|
15659
15659
|
this.fd = fd;
|
|
15660
15660
|
}
|
|
15661
|
-
|
|
15661
|
+
File3.prototype.getString = function(encoding) {
|
|
15662
15662
|
if (encoding === void 0) {
|
|
15663
15663
|
encoding = "utf8";
|
|
15664
15664
|
}
|
|
15665
15665
|
return this.node.getString();
|
|
15666
15666
|
};
|
|
15667
|
-
|
|
15667
|
+
File3.prototype.setString = function(str) {
|
|
15668
15668
|
this.node.setString(str);
|
|
15669
15669
|
};
|
|
15670
|
-
|
|
15670
|
+
File3.prototype.getBuffer = function() {
|
|
15671
15671
|
return this.node.getBuffer();
|
|
15672
15672
|
};
|
|
15673
|
-
|
|
15673
|
+
File3.prototype.setBuffer = function(buf) {
|
|
15674
15674
|
this.node.setBuffer(buf);
|
|
15675
15675
|
};
|
|
15676
|
-
|
|
15676
|
+
File3.prototype.getSize = function() {
|
|
15677
15677
|
return this.node.getSize();
|
|
15678
15678
|
};
|
|
15679
|
-
|
|
15679
|
+
File3.prototype.truncate = function(len) {
|
|
15680
15680
|
this.node.truncate(len);
|
|
15681
15681
|
};
|
|
15682
|
-
|
|
15682
|
+
File3.prototype.seekTo = function(position) {
|
|
15683
15683
|
this.position = position;
|
|
15684
15684
|
};
|
|
15685
|
-
|
|
15685
|
+
File3.prototype.stats = function() {
|
|
15686
15686
|
return Stats_1.default.build(this.node);
|
|
15687
15687
|
};
|
|
15688
|
-
|
|
15688
|
+
File3.prototype.write = function(buf, offset, length, position) {
|
|
15689
15689
|
if (offset === void 0) {
|
|
15690
15690
|
offset = 0;
|
|
15691
15691
|
}
|
|
@@ -15700,7 +15700,7 @@ var require_node = __commonJS({
|
|
|
15700
15700
|
this.position = position + bytes;
|
|
15701
15701
|
return bytes;
|
|
15702
15702
|
};
|
|
15703
|
-
|
|
15703
|
+
File3.prototype.read = function(buf, offset, length, position) {
|
|
15704
15704
|
if (offset === void 0) {
|
|
15705
15705
|
offset = 0;
|
|
15706
15706
|
}
|
|
@@ -15713,15 +15713,15 @@ var require_node = __commonJS({
|
|
|
15713
15713
|
this.position = position + bytes;
|
|
15714
15714
|
return bytes;
|
|
15715
15715
|
};
|
|
15716
|
-
|
|
15716
|
+
File3.prototype.chmod = function(perm) {
|
|
15717
15717
|
this.node.chmod(perm);
|
|
15718
15718
|
};
|
|
15719
|
-
|
|
15719
|
+
File3.prototype.chown = function(uid, gid) {
|
|
15720
15720
|
this.node.chown(uid, gid);
|
|
15721
15721
|
};
|
|
15722
|
-
return
|
|
15722
|
+
return File3;
|
|
15723
15723
|
}();
|
|
15724
|
-
exports.File =
|
|
15724
|
+
exports.File = File2;
|
|
15725
15725
|
}
|
|
15726
15726
|
});
|
|
15727
15727
|
|
|
@@ -16407,20 +16407,20 @@ var require_volume = __commonJS({
|
|
|
16407
16407
|
}
|
|
16408
16408
|
function flattenJSON(nestedJSON) {
|
|
16409
16409
|
var flatJSON = {};
|
|
16410
|
-
function
|
|
16410
|
+
function flatten2(pathPrefix, node) {
|
|
16411
16411
|
for (var path2 in node) {
|
|
16412
16412
|
var contentOrNode = node[path2];
|
|
16413
16413
|
var joinedPath = join2(pathPrefix, path2);
|
|
16414
16414
|
if (typeof contentOrNode === "string") {
|
|
16415
16415
|
flatJSON[joinedPath] = contentOrNode;
|
|
16416
16416
|
} else if (typeof contentOrNode === "object" && contentOrNode !== null && Object.keys(contentOrNode).length > 0) {
|
|
16417
|
-
|
|
16417
|
+
flatten2(joinedPath, contentOrNode);
|
|
16418
16418
|
} else {
|
|
16419
16419
|
flatJSON[joinedPath] = null;
|
|
16420
16420
|
}
|
|
16421
16421
|
}
|
|
16422
16422
|
}
|
|
16423
|
-
|
|
16423
|
+
flatten2("", nestedJSON);
|
|
16424
16424
|
return flatJSON;
|
|
16425
16425
|
}
|
|
16426
16426
|
var Volume = function() {
|
|
@@ -54056,7 +54056,18 @@ var graphql = __toESM(require_graphql2(), 1);
|
|
|
54056
54056
|
var import_minimatch = __toESM(require_minimatch(), 1);
|
|
54057
54057
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
54058
54058
|
|
|
54059
|
+
// src/runtime/imports/config.ts
|
|
54060
|
+
var config_default = {};
|
|
54061
|
+
|
|
54062
|
+
// src/runtime/imports/pluginConfig.ts
|
|
54063
|
+
var configs = [];
|
|
54064
|
+
var pluginConfig_default = configs;
|
|
54065
|
+
|
|
54059
54066
|
// src/runtime/lib/config.ts
|
|
54067
|
+
var mockConfig = null;
|
|
54068
|
+
function getMockConfig() {
|
|
54069
|
+
return mockConfig;
|
|
54070
|
+
}
|
|
54060
54071
|
function defaultConfigValues(file) {
|
|
54061
54072
|
return {
|
|
54062
54073
|
defaultKeys: ["id"],
|
|
@@ -54084,6 +54095,106 @@ function computeID(configFile, type, data) {
|
|
|
54084
54095
|
}
|
|
54085
54096
|
return id.slice(0, -2);
|
|
54086
54097
|
}
|
|
54098
|
+
var _configFile = null;
|
|
54099
|
+
function getCurrentConfig() {
|
|
54100
|
+
const mockConfig2 = getMockConfig();
|
|
54101
|
+
if (mockConfig2) {
|
|
54102
|
+
return mockConfig2;
|
|
54103
|
+
}
|
|
54104
|
+
if (_configFile) {
|
|
54105
|
+
return _configFile;
|
|
54106
|
+
}
|
|
54107
|
+
let configFile = defaultConfigValues(config_default);
|
|
54108
|
+
for (const pluginConfig of pluginConfig_default) {
|
|
54109
|
+
configFile = pluginConfig(configFile);
|
|
54110
|
+
}
|
|
54111
|
+
_configFile = configFile;
|
|
54112
|
+
return configFile;
|
|
54113
|
+
}
|
|
54114
|
+
|
|
54115
|
+
// src/runtime/lib/deepEquals.ts
|
|
54116
|
+
function deepEquals(objA, objB, map = /* @__PURE__ */ new WeakMap()) {
|
|
54117
|
+
if (Object.is(objA, objB))
|
|
54118
|
+
return true;
|
|
54119
|
+
if (objA instanceof Date && objB instanceof Date) {
|
|
54120
|
+
return objA.getTime() === objB.getTime();
|
|
54121
|
+
}
|
|
54122
|
+
if (objA instanceof RegExp && objB instanceof RegExp) {
|
|
54123
|
+
return objA.toString() === objB.toString();
|
|
54124
|
+
}
|
|
54125
|
+
if (typeof objA !== "object" || objA === null || typeof objB !== "object" || objB === null) {
|
|
54126
|
+
return false;
|
|
54127
|
+
}
|
|
54128
|
+
if (map.get(objA) === objB)
|
|
54129
|
+
return true;
|
|
54130
|
+
map.set(objA, objB);
|
|
54131
|
+
const keysA = Reflect.ownKeys(objA);
|
|
54132
|
+
const keysB = Reflect.ownKeys(objB);
|
|
54133
|
+
if (keysA.length !== keysB.length) {
|
|
54134
|
+
return false;
|
|
54135
|
+
}
|
|
54136
|
+
for (let i = 0; i < keysA.length; i++) {
|
|
54137
|
+
if (!Reflect.has(objB, keysA[i]) || !deepEquals(objA[keysA[i]], objB[keysA[i]], map)) {
|
|
54138
|
+
return false;
|
|
54139
|
+
}
|
|
54140
|
+
}
|
|
54141
|
+
return true;
|
|
54142
|
+
}
|
|
54143
|
+
|
|
54144
|
+
// src/runtime/lib/selection.ts
|
|
54145
|
+
function getFieldsForType(selection2, __typename) {
|
|
54146
|
+
let targetSelection = selection2.fields || {};
|
|
54147
|
+
if (selection2.abstractFields && __typename) {
|
|
54148
|
+
const mappedType = selection2.abstractFields.typeMap[__typename];
|
|
54149
|
+
if (mappedType) {
|
|
54150
|
+
targetSelection = selection2.abstractFields.fields[mappedType];
|
|
54151
|
+
} else if (selection2.abstractFields.fields[__typename]) {
|
|
54152
|
+
targetSelection = selection2.abstractFields.fields[__typename];
|
|
54153
|
+
}
|
|
54154
|
+
}
|
|
54155
|
+
return targetSelection;
|
|
54156
|
+
}
|
|
54157
|
+
|
|
54158
|
+
// src/runtime/lib/scalars.ts
|
|
54159
|
+
async function marshalSelection({
|
|
54160
|
+
selection: selection2,
|
|
54161
|
+
data
|
|
54162
|
+
}) {
|
|
54163
|
+
const config2 = getCurrentConfig();
|
|
54164
|
+
if (data === null || typeof data === "undefined") {
|
|
54165
|
+
return data;
|
|
54166
|
+
}
|
|
54167
|
+
if (Array.isArray(data)) {
|
|
54168
|
+
return await Promise.all(data.map((val) => marshalSelection({ selection: selection2, data: val })));
|
|
54169
|
+
}
|
|
54170
|
+
const targetSelection = getFieldsForType(selection2, data["__typename"]);
|
|
54171
|
+
return Object.fromEntries(
|
|
54172
|
+
await Promise.all(
|
|
54173
|
+
Object.entries(data).map(async ([fieldName, value]) => {
|
|
54174
|
+
const { type, selection: selection3 } = targetSelection[fieldName];
|
|
54175
|
+
if (!type) {
|
|
54176
|
+
return [fieldName, value];
|
|
54177
|
+
}
|
|
54178
|
+
if (selection3) {
|
|
54179
|
+
return [fieldName, await marshalSelection({ selection: selection3, data: value })];
|
|
54180
|
+
}
|
|
54181
|
+
if (config2.scalars?.[type]) {
|
|
54182
|
+
const marshalFn = config2.scalars[type].marshal;
|
|
54183
|
+
if (!marshalFn) {
|
|
54184
|
+
throw new Error(
|
|
54185
|
+
`scalar type ${type} is missing a \`marshal\` function. see https://github.com/AlecAivazis/houdini#%EF%B8%8Fcustom-scalars`
|
|
54186
|
+
);
|
|
54187
|
+
}
|
|
54188
|
+
if (Array.isArray(value)) {
|
|
54189
|
+
return [fieldName, value.map(marshalFn)];
|
|
54190
|
+
}
|
|
54191
|
+
return [fieldName, marshalFn(value)];
|
|
54192
|
+
}
|
|
54193
|
+
return [fieldName, value];
|
|
54194
|
+
})
|
|
54195
|
+
)
|
|
54196
|
+
);
|
|
54197
|
+
}
|
|
54087
54198
|
|
|
54088
54199
|
// src/runtime/lib/types.ts
|
|
54089
54200
|
var CachePolicy = {
|
|
@@ -54107,6 +54218,27 @@ var RefetchUpdateMode = {
|
|
|
54107
54218
|
prepend: "prepend",
|
|
54108
54219
|
replace: "replace"
|
|
54109
54220
|
};
|
|
54221
|
+
var DataSource = {
|
|
54222
|
+
Cache: "cache",
|
|
54223
|
+
Network: "network",
|
|
54224
|
+
Ssr: "ssr"
|
|
54225
|
+
};
|
|
54226
|
+
|
|
54227
|
+
// src/runtime/lib/key.ts
|
|
54228
|
+
var computeKey = ({ field, args }) => {
|
|
54229
|
+
const keys = Object.keys(args ?? {});
|
|
54230
|
+
keys.sort();
|
|
54231
|
+
return args && keys.length > 0 ? `${field}(${keys.map((key) => `${key}: ${stringifyObjectWithNoQuotesOnKeys(args[key])}`).join(", ")})` : field;
|
|
54232
|
+
};
|
|
54233
|
+
var stringifyObjectWithNoQuotesOnKeys = (obj_from_json) => {
|
|
54234
|
+
if (Array.isArray(obj_from_json)) {
|
|
54235
|
+
return `[${obj_from_json.map((obj) => `${stringifyObjectWithNoQuotesOnKeys(obj)}`).join(", ")}]`;
|
|
54236
|
+
}
|
|
54237
|
+
if (typeof obj_from_json !== "object" || obj_from_json instanceof Date || obj_from_json === null) {
|
|
54238
|
+
return JSON.stringify(obj_from_json).replace(/"([^"]+)":/g, "$1: ");
|
|
54239
|
+
}
|
|
54240
|
+
return `{${Object.keys(obj_from_json).map((key) => `${key}: ${stringifyObjectWithNoQuotesOnKeys(obj_from_json[key])}`).join(", ")}}`;
|
|
54241
|
+
};
|
|
54110
54242
|
|
|
54111
54243
|
// src/lib/constants.ts
|
|
54112
54244
|
var siteURL = "https://houdinigraphql.com";
|
|
@@ -54429,6 +54561,1995 @@ async function glob(pattern) {
|
|
|
54429
54561
|
}
|
|
54430
54562
|
glob.hasMagic = import_glob.glob.hasMagic;
|
|
54431
54563
|
|
|
54564
|
+
// src/runtime/lib/flatten.ts
|
|
54565
|
+
function flatten(source) {
|
|
54566
|
+
if (!source) {
|
|
54567
|
+
return [];
|
|
54568
|
+
}
|
|
54569
|
+
return source.reduce((acc, element) => {
|
|
54570
|
+
if (!element) {
|
|
54571
|
+
return acc;
|
|
54572
|
+
}
|
|
54573
|
+
if (Array.isArray(element)) {
|
|
54574
|
+
return acc.concat(flatten(element));
|
|
54575
|
+
}
|
|
54576
|
+
return acc.concat(element);
|
|
54577
|
+
}, []);
|
|
54578
|
+
}
|
|
54579
|
+
|
|
54580
|
+
// src/runtime/cache/gc.ts
|
|
54581
|
+
var GarbageCollector = class {
|
|
54582
|
+
cache;
|
|
54583
|
+
lifetimes = /* @__PURE__ */ new Map();
|
|
54584
|
+
get cacheBufferSize() {
|
|
54585
|
+
return this.cache._internal_unstable.config.cacheBufferSize ?? 10;
|
|
54586
|
+
}
|
|
54587
|
+
constructor(cache) {
|
|
54588
|
+
this.cache = cache;
|
|
54589
|
+
}
|
|
54590
|
+
resetLifetime(id, field) {
|
|
54591
|
+
if (!this.lifetimes.get(id)) {
|
|
54592
|
+
this.lifetimes.set(id, /* @__PURE__ */ new Map());
|
|
54593
|
+
}
|
|
54594
|
+
this.lifetimes.get(id).set(field, 0);
|
|
54595
|
+
}
|
|
54596
|
+
tick() {
|
|
54597
|
+
const dt_tick = Date.now().valueOf();
|
|
54598
|
+
const config_max_time = this.cache._internal_unstable.config.defaultLifetime;
|
|
54599
|
+
for (const [id, fieldMap] of this.lifetimes.entries()) {
|
|
54600
|
+
for (const [field, lifetime] of fieldMap.entries()) {
|
|
54601
|
+
if (this.cache._internal_unstable.subscriptions.get(id, field).length > 0) {
|
|
54602
|
+
continue;
|
|
54603
|
+
}
|
|
54604
|
+
fieldMap.set(field, lifetime + 1);
|
|
54605
|
+
if (fieldMap.get(field) > this.cacheBufferSize) {
|
|
54606
|
+
this.cache._internal_unstable.storage.deleteField(id, field);
|
|
54607
|
+
this.cache._internal_unstable.lists.deleteField(id, field);
|
|
54608
|
+
fieldMap.delete(field);
|
|
54609
|
+
if ([...fieldMap.keys()].length === 0) {
|
|
54610
|
+
this.lifetimes.delete(id);
|
|
54611
|
+
}
|
|
54612
|
+
this.cache._internal_unstable.staleManager.delete(id, field);
|
|
54613
|
+
}
|
|
54614
|
+
if (config_max_time && config_max_time > 0) {
|
|
54615
|
+
const dt_valueOf = this.cache.getFieldTime(id, field);
|
|
54616
|
+
if (dt_valueOf && dt_tick - dt_valueOf > config_max_time) {
|
|
54617
|
+
this.cache._internal_unstable.staleManager.markFieldStale(id, field);
|
|
54618
|
+
}
|
|
54619
|
+
}
|
|
54620
|
+
}
|
|
54621
|
+
}
|
|
54622
|
+
}
|
|
54623
|
+
};
|
|
54624
|
+
|
|
54625
|
+
// src/runtime/cache/lists.ts
|
|
54626
|
+
var ListManager = class {
|
|
54627
|
+
rootID;
|
|
54628
|
+
cache;
|
|
54629
|
+
constructor(cache, rootID2) {
|
|
54630
|
+
this.rootID = rootID2;
|
|
54631
|
+
this.cache = cache;
|
|
54632
|
+
}
|
|
54633
|
+
lists = /* @__PURE__ */ new Map();
|
|
54634
|
+
listsByField = /* @__PURE__ */ new Map();
|
|
54635
|
+
get(listName, id, allLists) {
|
|
54636
|
+
const matches = this.lists.get(listName);
|
|
54637
|
+
if (!matches || matches.size === 0) {
|
|
54638
|
+
return null;
|
|
54639
|
+
}
|
|
54640
|
+
if (allLists) {
|
|
54641
|
+
return new ListCollection(
|
|
54642
|
+
Array.from(matches, ([key, value]) => [...value.lists]).flat()
|
|
54643
|
+
);
|
|
54644
|
+
}
|
|
54645
|
+
const head = [...matches.values()][0];
|
|
54646
|
+
const { recordType } = head.lists[0];
|
|
54647
|
+
const parentID = id ? this.cache._internal_unstable.id(recordType || "", id) : this.rootID;
|
|
54648
|
+
if (matches?.size === 1) {
|
|
54649
|
+
if (!id) {
|
|
54650
|
+
return head;
|
|
54651
|
+
}
|
|
54652
|
+
return parentID === Array.from(matches.keys())[0] ? head : null;
|
|
54653
|
+
}
|
|
54654
|
+
if (!id) {
|
|
54655
|
+
console.error(
|
|
54656
|
+
`Found multiple instances of "${listName}". Please provide one of @parentID or @allLists directives to help identify which list you want modify. For more information, visit this guide: https://www.houdinigraphql.com/api/graphql#parentidvalue-string `
|
|
54657
|
+
);
|
|
54658
|
+
return null;
|
|
54659
|
+
}
|
|
54660
|
+
return this.lists.get(listName)?.get(parentID);
|
|
54661
|
+
}
|
|
54662
|
+
remove(listName, id) {
|
|
54663
|
+
this.lists.get(listName)?.delete(id || this.rootID);
|
|
54664
|
+
}
|
|
54665
|
+
add(list) {
|
|
54666
|
+
if (!this.lists.has(list.name)) {
|
|
54667
|
+
this.lists.set(list.name, /* @__PURE__ */ new Map());
|
|
54668
|
+
}
|
|
54669
|
+
const name = list.name;
|
|
54670
|
+
const parentID = list.recordID || this.rootID;
|
|
54671
|
+
if (this.lists.get(name)?.get(parentID)?.includes(list.key)) {
|
|
54672
|
+
return;
|
|
54673
|
+
}
|
|
54674
|
+
if (!this.lists.has(name)) {
|
|
54675
|
+
this.lists.set(name, /* @__PURE__ */ new Map());
|
|
54676
|
+
}
|
|
54677
|
+
if (!this.lists.get(name).has(parentID)) {
|
|
54678
|
+
this.lists.get(name).set(parentID, new ListCollection([]));
|
|
54679
|
+
}
|
|
54680
|
+
if (!this.listsByField.has(parentID)) {
|
|
54681
|
+
this.listsByField.set(parentID, /* @__PURE__ */ new Map());
|
|
54682
|
+
}
|
|
54683
|
+
if (!this.listsByField.get(parentID).has(list.key)) {
|
|
54684
|
+
this.listsByField.get(parentID)?.set(list.key, []);
|
|
54685
|
+
}
|
|
54686
|
+
const handler = new List({ ...list, manager: this });
|
|
54687
|
+
this.lists.get(list.name).get(parentID).lists.push(handler);
|
|
54688
|
+
this.listsByField.get(parentID).get(list.key).push(handler);
|
|
54689
|
+
}
|
|
54690
|
+
removeIDFromAllLists(id) {
|
|
54691
|
+
for (const fieldMap of this.lists.values()) {
|
|
54692
|
+
for (const list of fieldMap.values()) {
|
|
54693
|
+
list.removeID(id);
|
|
54694
|
+
}
|
|
54695
|
+
}
|
|
54696
|
+
}
|
|
54697
|
+
deleteField(parentID, field) {
|
|
54698
|
+
if (!this.listsByField.get(parentID)?.has(field)) {
|
|
54699
|
+
return;
|
|
54700
|
+
}
|
|
54701
|
+
for (const list of this.listsByField.get(parentID).get(field)) {
|
|
54702
|
+
this.lists.get(list.name)?.get(list.recordID)?.deleteListWithKey(field);
|
|
54703
|
+
if (this.lists.get(list.name)?.get(list.recordID)?.lists.length === 0) {
|
|
54704
|
+
this.lists.get(list.name)?.delete(list.recordID);
|
|
54705
|
+
}
|
|
54706
|
+
}
|
|
54707
|
+
this.listsByField.get(parentID).delete(field);
|
|
54708
|
+
}
|
|
54709
|
+
};
|
|
54710
|
+
var List = class {
|
|
54711
|
+
recordID;
|
|
54712
|
+
recordType;
|
|
54713
|
+
key;
|
|
54714
|
+
type;
|
|
54715
|
+
cache;
|
|
54716
|
+
selection;
|
|
54717
|
+
_when;
|
|
54718
|
+
filters;
|
|
54719
|
+
name;
|
|
54720
|
+
connection;
|
|
54721
|
+
manager;
|
|
54722
|
+
abstract;
|
|
54723
|
+
constructor({
|
|
54724
|
+
name,
|
|
54725
|
+
recordID,
|
|
54726
|
+
recordType,
|
|
54727
|
+
key,
|
|
54728
|
+
listType,
|
|
54729
|
+
selection: selection2,
|
|
54730
|
+
when,
|
|
54731
|
+
filters,
|
|
54732
|
+
connection,
|
|
54733
|
+
manager,
|
|
54734
|
+
abstract
|
|
54735
|
+
}) {
|
|
54736
|
+
this.recordID = recordID || rootID;
|
|
54737
|
+
this.recordType = recordType;
|
|
54738
|
+
this.key = key;
|
|
54739
|
+
this.type = listType;
|
|
54740
|
+
this.cache = manager.cache;
|
|
54741
|
+
this.selection = selection2;
|
|
54742
|
+
this._when = when;
|
|
54743
|
+
this.filters = filters;
|
|
54744
|
+
this.name = name;
|
|
54745
|
+
this.connection = connection;
|
|
54746
|
+
this.manager = manager;
|
|
54747
|
+
this.abstract = abstract;
|
|
54748
|
+
}
|
|
54749
|
+
when(when) {
|
|
54750
|
+
return this.manager.lists.get(this.name).get(this.recordID).when(when);
|
|
54751
|
+
}
|
|
54752
|
+
append(selection2, data, variables = {}) {
|
|
54753
|
+
return this.addToList(selection2, data, variables, "last");
|
|
54754
|
+
}
|
|
54755
|
+
prepend(selection2, data, variables = {}) {
|
|
54756
|
+
return this.addToList(selection2, data, variables, "first");
|
|
54757
|
+
}
|
|
54758
|
+
addToList(selection2, data, variables = {}, where) {
|
|
54759
|
+
const listType = this.listType(data);
|
|
54760
|
+
const dataID = this.cache._internal_unstable.id(listType, data);
|
|
54761
|
+
if (!this.validateWhen() || !dataID) {
|
|
54762
|
+
return;
|
|
54763
|
+
}
|
|
54764
|
+
let insertSelection = selection2;
|
|
54765
|
+
let insertData = data;
|
|
54766
|
+
if (this.connection) {
|
|
54767
|
+
insertSelection = {
|
|
54768
|
+
fields: {
|
|
54769
|
+
newEntry: {
|
|
54770
|
+
keyRaw: this.key,
|
|
54771
|
+
type: "Connection",
|
|
54772
|
+
selection: {
|
|
54773
|
+
fields: {
|
|
54774
|
+
edges: {
|
|
54775
|
+
keyRaw: "edges",
|
|
54776
|
+
type: "ConnectionEdge",
|
|
54777
|
+
updates: ["append", "prepend"],
|
|
54778
|
+
selection: {
|
|
54779
|
+
fields: {
|
|
54780
|
+
node: {
|
|
54781
|
+
type: listType,
|
|
54782
|
+
keyRaw: "node",
|
|
54783
|
+
selection: {
|
|
54784
|
+
...selection2,
|
|
54785
|
+
fields: {
|
|
54786
|
+
...selection2.fields,
|
|
54787
|
+
__typename: {
|
|
54788
|
+
keyRaw: "__typename",
|
|
54789
|
+
type: "String"
|
|
54790
|
+
}
|
|
54791
|
+
}
|
|
54792
|
+
}
|
|
54793
|
+
}
|
|
54794
|
+
}
|
|
54795
|
+
}
|
|
54796
|
+
}
|
|
54797
|
+
}
|
|
54798
|
+
}
|
|
54799
|
+
}
|
|
54800
|
+
}
|
|
54801
|
+
};
|
|
54802
|
+
insertData = {
|
|
54803
|
+
newEntry: {
|
|
54804
|
+
edges: [{ node: { ...data, __typename: listType } }]
|
|
54805
|
+
}
|
|
54806
|
+
};
|
|
54807
|
+
} else {
|
|
54808
|
+
insertSelection = {
|
|
54809
|
+
fields: {
|
|
54810
|
+
newEntries: {
|
|
54811
|
+
keyRaw: this.key,
|
|
54812
|
+
type: listType,
|
|
54813
|
+
updates: ["append", "prepend"],
|
|
54814
|
+
selection: {
|
|
54815
|
+
...selection2,
|
|
54816
|
+
fields: {
|
|
54817
|
+
...selection2.fields,
|
|
54818
|
+
__typename: {
|
|
54819
|
+
keyRaw: "__typename",
|
|
54820
|
+
type: "String"
|
|
54821
|
+
}
|
|
54822
|
+
}
|
|
54823
|
+
}
|
|
54824
|
+
}
|
|
54825
|
+
}
|
|
54826
|
+
};
|
|
54827
|
+
insertData = {
|
|
54828
|
+
newEntries: [{ ...data, __typename: listType }]
|
|
54829
|
+
};
|
|
54830
|
+
}
|
|
54831
|
+
this.cache.write({
|
|
54832
|
+
selection: insertSelection,
|
|
54833
|
+
data: insertData,
|
|
54834
|
+
variables,
|
|
54835
|
+
parent: this.recordID,
|
|
54836
|
+
applyUpdates: [where === "first" ? "prepend" : "append"]
|
|
54837
|
+
});
|
|
54838
|
+
}
|
|
54839
|
+
removeID(id, variables = {}) {
|
|
54840
|
+
if (!this.validateWhen()) {
|
|
54841
|
+
return;
|
|
54842
|
+
}
|
|
54843
|
+
let parentID = this.recordID;
|
|
54844
|
+
let targetID = id;
|
|
54845
|
+
let targetKey = this.key;
|
|
54846
|
+
if (this.connection) {
|
|
54847
|
+
const { value: embeddedConnection } = this.cache._internal_unstable.storage.get(
|
|
54848
|
+
this.recordID,
|
|
54849
|
+
this.key
|
|
54850
|
+
);
|
|
54851
|
+
if (!embeddedConnection) {
|
|
54852
|
+
return;
|
|
54853
|
+
}
|
|
54854
|
+
const embeddedConnectionID = embeddedConnection;
|
|
54855
|
+
const { value: edges } = this.cache._internal_unstable.storage.get(
|
|
54856
|
+
embeddedConnectionID,
|
|
54857
|
+
"edges"
|
|
54858
|
+
);
|
|
54859
|
+
for (const edge of flatten(edges) || []) {
|
|
54860
|
+
if (!edge) {
|
|
54861
|
+
continue;
|
|
54862
|
+
}
|
|
54863
|
+
const edgeID = edge;
|
|
54864
|
+
const { value: nodeID } = this.cache._internal_unstable.storage.get(edgeID, "node");
|
|
54865
|
+
if (!nodeID) {
|
|
54866
|
+
continue;
|
|
54867
|
+
}
|
|
54868
|
+
if (nodeID === id) {
|
|
54869
|
+
targetID = edgeID;
|
|
54870
|
+
}
|
|
54871
|
+
}
|
|
54872
|
+
parentID = embeddedConnectionID;
|
|
54873
|
+
targetKey = "edges";
|
|
54874
|
+
}
|
|
54875
|
+
let value = this.cache._internal_unstable.storage.get(parentID, targetKey).value;
|
|
54876
|
+
if (!value || !value.includes(targetID)) {
|
|
54877
|
+
return;
|
|
54878
|
+
}
|
|
54879
|
+
const subscribers = this.cache._internal_unstable.subscriptions.get(this.recordID, this.key);
|
|
54880
|
+
this.cache._internal_unstable.subscriptions.remove(
|
|
54881
|
+
targetID,
|
|
54882
|
+
this.connection ? this.selection.fields.edges.selection : this.selection,
|
|
54883
|
+
subscribers.map((sub) => sub[0]),
|
|
54884
|
+
variables
|
|
54885
|
+
);
|
|
54886
|
+
this.cache._internal_unstable.storage.remove(parentID, targetKey, targetID);
|
|
54887
|
+
for (const [spec] of subscribers) {
|
|
54888
|
+
spec.set(
|
|
54889
|
+
this.cache._internal_unstable.getSelection({
|
|
54890
|
+
parent: spec.parentID || this.manager.rootID,
|
|
54891
|
+
selection: spec.selection,
|
|
54892
|
+
variables: spec.variables?.() || {}
|
|
54893
|
+
}).data
|
|
54894
|
+
);
|
|
54895
|
+
}
|
|
54896
|
+
return true;
|
|
54897
|
+
}
|
|
54898
|
+
remove(data, variables = {}) {
|
|
54899
|
+
const targetID = this.cache._internal_unstable.id(this.listType(data), data);
|
|
54900
|
+
if (!targetID) {
|
|
54901
|
+
return;
|
|
54902
|
+
}
|
|
54903
|
+
return this.removeID(targetID, variables);
|
|
54904
|
+
}
|
|
54905
|
+
listType(data) {
|
|
54906
|
+
return data.__typename || this.type;
|
|
54907
|
+
}
|
|
54908
|
+
validateWhen(when) {
|
|
54909
|
+
let filters = when || this._when;
|
|
54910
|
+
let ok = true;
|
|
54911
|
+
if (filters) {
|
|
54912
|
+
const targets = this.filters;
|
|
54913
|
+
if (filters.must && targets) {
|
|
54914
|
+
ok = Object.entries(filters.must).reduce(
|
|
54915
|
+
(prev, [key, value]) => Boolean(prev && targets[key] == value),
|
|
54916
|
+
ok
|
|
54917
|
+
);
|
|
54918
|
+
}
|
|
54919
|
+
if (filters.must_not) {
|
|
54920
|
+
ok = !targets || Object.entries(filters.must_not).reduce(
|
|
54921
|
+
(prev, [key, value]) => Boolean(prev && targets[key] != value),
|
|
54922
|
+
ok
|
|
54923
|
+
);
|
|
54924
|
+
}
|
|
54925
|
+
}
|
|
54926
|
+
return ok;
|
|
54927
|
+
}
|
|
54928
|
+
toggleElement(selection2, data, variables = {}, where) {
|
|
54929
|
+
if (!this.remove(data, variables)) {
|
|
54930
|
+
this.addToList(selection2, data, variables, where);
|
|
54931
|
+
}
|
|
54932
|
+
}
|
|
54933
|
+
*[Symbol.iterator]() {
|
|
54934
|
+
let entries = [];
|
|
54935
|
+
let value = this.cache._internal_unstable.storage.get(this.recordID, this.key).value;
|
|
54936
|
+
if (!this.connection) {
|
|
54937
|
+
entries = flatten(value);
|
|
54938
|
+
} else {
|
|
54939
|
+
entries = this.cache._internal_unstable.storage.get(value, "edges").value;
|
|
54940
|
+
}
|
|
54941
|
+
for (let record2 of entries) {
|
|
54942
|
+
yield record2;
|
|
54943
|
+
}
|
|
54944
|
+
}
|
|
54945
|
+
};
|
|
54946
|
+
var ListCollection = class {
|
|
54947
|
+
lists = [];
|
|
54948
|
+
constructor(lists) {
|
|
54949
|
+
this.lists = lists;
|
|
54950
|
+
}
|
|
54951
|
+
get selection() {
|
|
54952
|
+
return this.lists[0].selection;
|
|
54953
|
+
}
|
|
54954
|
+
append(...args) {
|
|
54955
|
+
this.lists.forEach((list) => list.append(...args));
|
|
54956
|
+
}
|
|
54957
|
+
prepend(...args) {
|
|
54958
|
+
this.lists.forEach((list) => list.prepend(...args));
|
|
54959
|
+
}
|
|
54960
|
+
addToList(...args) {
|
|
54961
|
+
this.lists.forEach((list) => list.addToList(...args));
|
|
54962
|
+
}
|
|
54963
|
+
removeID(...args) {
|
|
54964
|
+
this.lists.forEach((list) => list.removeID(...args));
|
|
54965
|
+
}
|
|
54966
|
+
remove(...args) {
|
|
54967
|
+
this.lists.forEach((list) => list.remove(...args));
|
|
54968
|
+
}
|
|
54969
|
+
toggleElement(...args) {
|
|
54970
|
+
this.lists.forEach((list) => list.toggleElement(...args));
|
|
54971
|
+
}
|
|
54972
|
+
when(when) {
|
|
54973
|
+
return new ListCollection(
|
|
54974
|
+
this.lists.filter((list) => {
|
|
54975
|
+
return list.validateWhen(when);
|
|
54976
|
+
})
|
|
54977
|
+
);
|
|
54978
|
+
}
|
|
54979
|
+
includes(key) {
|
|
54980
|
+
return !!this.lists.find((list) => list.key === key);
|
|
54981
|
+
}
|
|
54982
|
+
deleteListWithKey(key) {
|
|
54983
|
+
return this.lists = this.lists.filter((list) => list.key !== key);
|
|
54984
|
+
}
|
|
54985
|
+
*[Symbol.iterator]() {
|
|
54986
|
+
for (let list of this.lists) {
|
|
54987
|
+
for (const entry of list) {
|
|
54988
|
+
yield entry;
|
|
54989
|
+
}
|
|
54990
|
+
}
|
|
54991
|
+
}
|
|
54992
|
+
};
|
|
54993
|
+
|
|
54994
|
+
// src/runtime/cache/schema.ts
|
|
54995
|
+
var SchemaManager = class {
|
|
54996
|
+
cache;
|
|
54997
|
+
fieldTypes = {};
|
|
54998
|
+
constructor(cache) {
|
|
54999
|
+
this.cache = cache;
|
|
55000
|
+
}
|
|
55001
|
+
setFieldType({
|
|
55002
|
+
parent,
|
|
55003
|
+
key,
|
|
55004
|
+
type,
|
|
55005
|
+
nullable = false,
|
|
55006
|
+
link
|
|
55007
|
+
}) {
|
|
55008
|
+
let parensIndex = key.indexOf("(");
|
|
55009
|
+
if (parensIndex !== -1) {
|
|
55010
|
+
key = key.substring(0, parensIndex);
|
|
55011
|
+
}
|
|
55012
|
+
if (parent === rootID) {
|
|
55013
|
+
parent = "Query";
|
|
55014
|
+
} else if (parent.includes(":")) {
|
|
55015
|
+
parent = parent.substring(0, parent.indexOf(":"));
|
|
55016
|
+
}
|
|
55017
|
+
if (!this.fieldTypes[parent]) {
|
|
55018
|
+
this.fieldTypes[parent] = {};
|
|
55019
|
+
}
|
|
55020
|
+
this.fieldTypes[parent][key] = {
|
|
55021
|
+
type,
|
|
55022
|
+
nullable,
|
|
55023
|
+
link: !!link
|
|
55024
|
+
};
|
|
55025
|
+
}
|
|
55026
|
+
fieldType(type, field) {
|
|
55027
|
+
return this.fieldTypes[type]?.[field] || null;
|
|
55028
|
+
}
|
|
55029
|
+
get config() {
|
|
55030
|
+
return this.cache._internal_unstable.config;
|
|
55031
|
+
}
|
|
55032
|
+
};
|
|
55033
|
+
|
|
55034
|
+
// src/runtime/cache/staleManager.ts
|
|
55035
|
+
var StaleManager = class {
|
|
55036
|
+
cache;
|
|
55037
|
+
fieldsTime = /* @__PURE__ */ new Map();
|
|
55038
|
+
constructor(cache) {
|
|
55039
|
+
this.cache = cache;
|
|
55040
|
+
}
|
|
55041
|
+
#initMapId = (id) => {
|
|
55042
|
+
if (!this.fieldsTime.get(id)) {
|
|
55043
|
+
this.fieldsTime.set(id, /* @__PURE__ */ new Map());
|
|
55044
|
+
}
|
|
55045
|
+
};
|
|
55046
|
+
getFieldTime(id, field) {
|
|
55047
|
+
return this.fieldsTime.get(id)?.get(field);
|
|
55048
|
+
}
|
|
55049
|
+
setFieldTimeToNow(id, field) {
|
|
55050
|
+
this.#initMapId(id);
|
|
55051
|
+
this.fieldsTime.get(id)?.set(field, new Date().valueOf());
|
|
55052
|
+
}
|
|
55053
|
+
markFieldStale(id, field) {
|
|
55054
|
+
this.#initMapId(id);
|
|
55055
|
+
this.fieldsTime.get(id)?.set(field, null);
|
|
55056
|
+
}
|
|
55057
|
+
markAllStale() {
|
|
55058
|
+
for (const [id, fieldMap] of this.fieldsTime.entries()) {
|
|
55059
|
+
for (const [field] of fieldMap.entries()) {
|
|
55060
|
+
this.markFieldStale(id, field);
|
|
55061
|
+
}
|
|
55062
|
+
}
|
|
55063
|
+
}
|
|
55064
|
+
markRecordStale(id) {
|
|
55065
|
+
const fieldsTimeOfType = this.fieldsTime.get(id);
|
|
55066
|
+
if (fieldsTimeOfType) {
|
|
55067
|
+
for (const [field] of fieldsTimeOfType.entries()) {
|
|
55068
|
+
this.markFieldStale(id, field);
|
|
55069
|
+
}
|
|
55070
|
+
}
|
|
55071
|
+
}
|
|
55072
|
+
markTypeStale(type) {
|
|
55073
|
+
for (const [id, fieldMap] of this.fieldsTime.entries()) {
|
|
55074
|
+
if (id.startsWith(`${type}:`)) {
|
|
55075
|
+
for (const [field] of fieldMap.entries()) {
|
|
55076
|
+
this.markFieldStale(id, field);
|
|
55077
|
+
}
|
|
55078
|
+
}
|
|
55079
|
+
}
|
|
55080
|
+
}
|
|
55081
|
+
markTypeFieldStale(type, field, when) {
|
|
55082
|
+
const key = computeKey({ field, args: when });
|
|
55083
|
+
for (const [id, fieldMap] of this.fieldsTime.entries()) {
|
|
55084
|
+
if (id.startsWith(`${type}:`)) {
|
|
55085
|
+
for (const local_field of fieldMap.keys()) {
|
|
55086
|
+
if (local_field === key) {
|
|
55087
|
+
this.markFieldStale(id, field);
|
|
55088
|
+
}
|
|
55089
|
+
}
|
|
55090
|
+
}
|
|
55091
|
+
}
|
|
55092
|
+
}
|
|
55093
|
+
delete(id, field) {
|
|
55094
|
+
if (this.fieldsTime.has(id)) {
|
|
55095
|
+
this.fieldsTime.get(id)?.delete(field);
|
|
55096
|
+
if (this.fieldsTime.get(id)?.size === 0) {
|
|
55097
|
+
this.fieldsTime.delete(id);
|
|
55098
|
+
}
|
|
55099
|
+
}
|
|
55100
|
+
}
|
|
55101
|
+
};
|
|
55102
|
+
|
|
55103
|
+
// src/runtime/cache/storage.ts
|
|
55104
|
+
var InMemoryStorage = class {
|
|
55105
|
+
data;
|
|
55106
|
+
idCount = 0;
|
|
55107
|
+
rank = 0;
|
|
55108
|
+
constructor() {
|
|
55109
|
+
this.data = [];
|
|
55110
|
+
}
|
|
55111
|
+
get layerCount() {
|
|
55112
|
+
return this.data.length;
|
|
55113
|
+
}
|
|
55114
|
+
get nextRank() {
|
|
55115
|
+
return this.rank++;
|
|
55116
|
+
}
|
|
55117
|
+
createLayer(optimistic = false) {
|
|
55118
|
+
const layer = new Layer(this.idCount++);
|
|
55119
|
+
layer.optimistic = optimistic;
|
|
55120
|
+
this.data.push(layer);
|
|
55121
|
+
return layer;
|
|
55122
|
+
}
|
|
55123
|
+
insert(id, field, location, target) {
|
|
55124
|
+
return this.topLayer.insert(id, field, location, target);
|
|
55125
|
+
}
|
|
55126
|
+
remove(id, field, target) {
|
|
55127
|
+
return this.topLayer.remove(id, field, target);
|
|
55128
|
+
}
|
|
55129
|
+
delete(id) {
|
|
55130
|
+
return this.topLayer.delete(id);
|
|
55131
|
+
}
|
|
55132
|
+
deleteField(id, field) {
|
|
55133
|
+
return this.topLayer.deleteField(id, field);
|
|
55134
|
+
}
|
|
55135
|
+
getLayer(id) {
|
|
55136
|
+
for (const layer of this.data) {
|
|
55137
|
+
if (layer.id === id) {
|
|
55138
|
+
return layer;
|
|
55139
|
+
}
|
|
55140
|
+
}
|
|
55141
|
+
throw new Error("Could not find layer with id: " + id);
|
|
55142
|
+
}
|
|
55143
|
+
replaceID(replacement) {
|
|
55144
|
+
for (const layer of this.data) {
|
|
55145
|
+
layer.replaceID(replacement);
|
|
55146
|
+
}
|
|
55147
|
+
}
|
|
55148
|
+
get(id, field) {
|
|
55149
|
+
const operations = {
|
|
55150
|
+
[OperationKind.insert]: {
|
|
55151
|
+
[OperationLocation.start]: [],
|
|
55152
|
+
[OperationLocation.end]: []
|
|
55153
|
+
},
|
|
55154
|
+
[OperationKind.remove]: /* @__PURE__ */ new Set()
|
|
55155
|
+
};
|
|
55156
|
+
const layerIDs = [];
|
|
55157
|
+
for (let i = this.data.length - 1; i >= 0; i--) {
|
|
55158
|
+
const layer = this.data[i];
|
|
55159
|
+
const [layerValue, kind] = layer.get(id, field);
|
|
55160
|
+
const layerOperations = layer.getOperations(id, field) || [];
|
|
55161
|
+
layer.deletedIDs.forEach((v) => {
|
|
55162
|
+
if (layer.operations[v]?.undoDeletesInList?.includes(field)) {
|
|
55163
|
+
return;
|
|
55164
|
+
}
|
|
55165
|
+
operations.remove.add(v);
|
|
55166
|
+
});
|
|
55167
|
+
if (typeof layerValue === "undefined" && layerOperations.length === 0) {
|
|
55168
|
+
if (layer.deletedIDs.size > 0) {
|
|
55169
|
+
layerIDs.push(layer.id);
|
|
55170
|
+
}
|
|
55171
|
+
continue;
|
|
55172
|
+
}
|
|
55173
|
+
if (typeof layerValue !== "undefined" && !Array.isArray(layerValue)) {
|
|
55174
|
+
return {
|
|
55175
|
+
value: layerValue,
|
|
55176
|
+
kind,
|
|
55177
|
+
displayLayers: [layer.id]
|
|
55178
|
+
};
|
|
55179
|
+
}
|
|
55180
|
+
layerIDs.push(layer.id);
|
|
55181
|
+
if (layerOperations.length > 0) {
|
|
55182
|
+
for (const op of layerOperations) {
|
|
55183
|
+
if (isRemoveOperation(op)) {
|
|
55184
|
+
operations.remove.add(op.id);
|
|
55185
|
+
}
|
|
55186
|
+
if (isInsertOperation(op)) {
|
|
55187
|
+
operations.insert[op.location].unshift(op.id);
|
|
55188
|
+
}
|
|
55189
|
+
if (isDeleteOperation(op)) {
|
|
55190
|
+
return {
|
|
55191
|
+
value: void 0,
|
|
55192
|
+
kind: "unknown",
|
|
55193
|
+
displayLayers: []
|
|
55194
|
+
};
|
|
55195
|
+
}
|
|
55196
|
+
}
|
|
55197
|
+
}
|
|
55198
|
+
if (typeof layerValue === "undefined") {
|
|
55199
|
+
continue;
|
|
55200
|
+
}
|
|
55201
|
+
if (!operations.remove.size && !operations.insert.start.length && !operations.insert.end.length) {
|
|
55202
|
+
return { value: layerValue, displayLayers: layerIDs, kind: "link" };
|
|
55203
|
+
}
|
|
55204
|
+
return {
|
|
55205
|
+
value: [...operations.insert.start, ...layerValue, ...operations.insert.end].filter(
|
|
55206
|
+
(value) => !operations.remove.has(value)
|
|
55207
|
+
),
|
|
55208
|
+
displayLayers: layerIDs,
|
|
55209
|
+
kind
|
|
55210
|
+
};
|
|
55211
|
+
}
|
|
55212
|
+
return {
|
|
55213
|
+
value: void 0,
|
|
55214
|
+
kind: "unknown",
|
|
55215
|
+
displayLayers: []
|
|
55216
|
+
};
|
|
55217
|
+
}
|
|
55218
|
+
writeLink(id, field, value) {
|
|
55219
|
+
return this.topLayer.writeLink(id, field, value);
|
|
55220
|
+
}
|
|
55221
|
+
writeField(id, field, value) {
|
|
55222
|
+
return this.topLayer.writeField(id, field, value);
|
|
55223
|
+
}
|
|
55224
|
+
resolveLayer(id) {
|
|
55225
|
+
let startingIndex = null;
|
|
55226
|
+
for (const [index, layer] of this.data.entries()) {
|
|
55227
|
+
if (layer.id !== id) {
|
|
55228
|
+
continue;
|
|
55229
|
+
}
|
|
55230
|
+
startingIndex = index - 1;
|
|
55231
|
+
this.data[index].optimistic = false;
|
|
55232
|
+
break;
|
|
55233
|
+
}
|
|
55234
|
+
if (startingIndex === null) {
|
|
55235
|
+
throw new Error("could not find layer with id: " + id);
|
|
55236
|
+
}
|
|
55237
|
+
if (startingIndex === -1) {
|
|
55238
|
+
startingIndex = 0;
|
|
55239
|
+
}
|
|
55240
|
+
if (this.data[startingIndex].optimistic) {
|
|
55241
|
+
startingIndex++;
|
|
55242
|
+
}
|
|
55243
|
+
const baseLayer = this.data[startingIndex];
|
|
55244
|
+
let layerIndex = startingIndex;
|
|
55245
|
+
while (layerIndex < this.data.length) {
|
|
55246
|
+
const layer = this.data[layerIndex++];
|
|
55247
|
+
if (layer.optimistic) {
|
|
55248
|
+
layerIndex--;
|
|
55249
|
+
break;
|
|
55250
|
+
}
|
|
55251
|
+
baseLayer.writeLayer(layer);
|
|
55252
|
+
}
|
|
55253
|
+
this.data.splice(startingIndex + 1, layerIndex - startingIndex - 1);
|
|
55254
|
+
}
|
|
55255
|
+
get topLayer() {
|
|
55256
|
+
if (this.data.length === 0) {
|
|
55257
|
+
this.createLayer();
|
|
55258
|
+
}
|
|
55259
|
+
if (this.data[this.data.length - 1]?.optimistic) {
|
|
55260
|
+
this.createLayer();
|
|
55261
|
+
}
|
|
55262
|
+
return this.data[this.data.length - 1];
|
|
55263
|
+
}
|
|
55264
|
+
};
|
|
55265
|
+
var Layer = class {
|
|
55266
|
+
id;
|
|
55267
|
+
optimistic = false;
|
|
55268
|
+
fields = {};
|
|
55269
|
+
links = {};
|
|
55270
|
+
operations = {};
|
|
55271
|
+
deletedIDs = /* @__PURE__ */ new Set();
|
|
55272
|
+
constructor(id) {
|
|
55273
|
+
this.id = id;
|
|
55274
|
+
}
|
|
55275
|
+
get(id, field) {
|
|
55276
|
+
if (typeof this.links[id]?.[field] !== "undefined") {
|
|
55277
|
+
return [this.links[id][field], "link"];
|
|
55278
|
+
}
|
|
55279
|
+
return [this.fields[id]?.[field], "scalar"];
|
|
55280
|
+
}
|
|
55281
|
+
getOperations(id, field) {
|
|
55282
|
+
if (this.operations[id]?.deleted) {
|
|
55283
|
+
return [
|
|
55284
|
+
{
|
|
55285
|
+
kind: OperationKind.delete,
|
|
55286
|
+
target: id
|
|
55287
|
+
}
|
|
55288
|
+
];
|
|
55289
|
+
}
|
|
55290
|
+
if (this.operations[id]?.fields?.[field]) {
|
|
55291
|
+
return this.operations[id].fields[field];
|
|
55292
|
+
}
|
|
55293
|
+
}
|
|
55294
|
+
writeField(id, field, value) {
|
|
55295
|
+
this.fields[id] = {
|
|
55296
|
+
...this.fields[id],
|
|
55297
|
+
[field]: value
|
|
55298
|
+
};
|
|
55299
|
+
return this.id;
|
|
55300
|
+
}
|
|
55301
|
+
writeLink(id, field, value) {
|
|
55302
|
+
const valueList = Array.isArray(value) ? value : [value];
|
|
55303
|
+
for (const value2 of flatten(valueList)) {
|
|
55304
|
+
if (!value2) {
|
|
55305
|
+
continue;
|
|
55306
|
+
}
|
|
55307
|
+
const fieldOperations = this.operations[id]?.fields[field];
|
|
55308
|
+
if (this.operations[value2]?.deleted || this.deletedIDs.has(value2)) {
|
|
55309
|
+
this.operations[value2] = {
|
|
55310
|
+
...this.operations[value2],
|
|
55311
|
+
undoDeletesInList: [...this.operations[id]?.undoDeletesInList || [], field]
|
|
55312
|
+
};
|
|
55313
|
+
} else if (value2 && fieldOperations?.length > 0) {
|
|
55314
|
+
this.operations[id].fields[field] = fieldOperations.filter(
|
|
55315
|
+
(op) => op.kind !== "remove" || op.id !== value2
|
|
55316
|
+
);
|
|
55317
|
+
}
|
|
55318
|
+
}
|
|
55319
|
+
this.links[id] = {
|
|
55320
|
+
...this.links[id],
|
|
55321
|
+
[field]: value
|
|
55322
|
+
};
|
|
55323
|
+
return this.id;
|
|
55324
|
+
}
|
|
55325
|
+
isDisplayLayer(displayLayers) {
|
|
55326
|
+
return displayLayers.length === 0 || displayLayers.includes(this.id) || Math.max(...displayLayers) < this.id;
|
|
55327
|
+
}
|
|
55328
|
+
clear() {
|
|
55329
|
+
this.links = {};
|
|
55330
|
+
this.fields = {};
|
|
55331
|
+
this.operations = {};
|
|
55332
|
+
this.deletedIDs = /* @__PURE__ */ new Set();
|
|
55333
|
+
}
|
|
55334
|
+
replaceID({ from, to }) {
|
|
55335
|
+
this.fields[to] = this.fields[from];
|
|
55336
|
+
this.links[to] = this.links[from];
|
|
55337
|
+
this.operations[to] = this.operations[from] || { fields: {} };
|
|
55338
|
+
if (this.deletedIDs.has(from)) {
|
|
55339
|
+
this.deletedIDs.add(to);
|
|
55340
|
+
}
|
|
55341
|
+
}
|
|
55342
|
+
removeUndefinedFields() {
|
|
55343
|
+
for (const [id, fields] of Object.entries(this.fields)) {
|
|
55344
|
+
for (const [field, value] of Object.entries(fields)) {
|
|
55345
|
+
if (typeof value === "undefined") {
|
|
55346
|
+
try {
|
|
55347
|
+
delete this.fields[id][field];
|
|
55348
|
+
} catch {
|
|
55349
|
+
}
|
|
55350
|
+
try {
|
|
55351
|
+
delete this.links[id][field];
|
|
55352
|
+
} catch {
|
|
55353
|
+
}
|
|
55354
|
+
}
|
|
55355
|
+
}
|
|
55356
|
+
if (Object.keys(fields || {}).length === 0) {
|
|
55357
|
+
delete this.fields[id];
|
|
55358
|
+
}
|
|
55359
|
+
if (Object.keys(this.links[id] || {}).length === 0) {
|
|
55360
|
+
delete this.links[id];
|
|
55361
|
+
}
|
|
55362
|
+
}
|
|
55363
|
+
}
|
|
55364
|
+
delete(id) {
|
|
55365
|
+
this.operations = {
|
|
55366
|
+
...this.operations,
|
|
55367
|
+
[id]: {
|
|
55368
|
+
...this.operations[id],
|
|
55369
|
+
deleted: true,
|
|
55370
|
+
undoDeletesInList: []
|
|
55371
|
+
}
|
|
55372
|
+
};
|
|
55373
|
+
this.deletedIDs.add(id);
|
|
55374
|
+
}
|
|
55375
|
+
deleteField(id, field) {
|
|
55376
|
+
this.fields[id] = {
|
|
55377
|
+
...this.fields[id],
|
|
55378
|
+
[field]: void 0
|
|
55379
|
+
};
|
|
55380
|
+
}
|
|
55381
|
+
insert(id, field, where, target) {
|
|
55382
|
+
this.addFieldOperation(id, field, {
|
|
55383
|
+
kind: OperationKind.insert,
|
|
55384
|
+
id: target,
|
|
55385
|
+
location: where
|
|
55386
|
+
});
|
|
55387
|
+
}
|
|
55388
|
+
remove(id, field, target) {
|
|
55389
|
+
this.addFieldOperation(id, field, {
|
|
55390
|
+
kind: OperationKind.remove,
|
|
55391
|
+
id: target
|
|
55392
|
+
});
|
|
55393
|
+
}
|
|
55394
|
+
writeLayer(layer) {
|
|
55395
|
+
if (layer.id === this.id) {
|
|
55396
|
+
return;
|
|
55397
|
+
}
|
|
55398
|
+
for (const [id, ops] of Object.entries(layer.operations)) {
|
|
55399
|
+
const fields = {};
|
|
55400
|
+
for (const opMap of [this.operations[id], layer.operations[id]].filter(Boolean)) {
|
|
55401
|
+
for (const [fieldName, operations] of Object.entries(opMap.fields || {})) {
|
|
55402
|
+
fields[fieldName] = [...fields[fieldName] || [], ...operations];
|
|
55403
|
+
}
|
|
55404
|
+
}
|
|
55405
|
+
if (Object.keys(fields).length > 0) {
|
|
55406
|
+
this.operations[id] = {
|
|
55407
|
+
...this.operations[id],
|
|
55408
|
+
fields
|
|
55409
|
+
};
|
|
55410
|
+
}
|
|
55411
|
+
if (ops?.deleted) {
|
|
55412
|
+
delete this.fields[id];
|
|
55413
|
+
delete this.links[id];
|
|
55414
|
+
}
|
|
55415
|
+
}
|
|
55416
|
+
for (const [id, values] of Object.entries(layer.fields)) {
|
|
55417
|
+
if (!values) {
|
|
55418
|
+
continue;
|
|
55419
|
+
}
|
|
55420
|
+
for (const [field, value] of Object.entries(values)) {
|
|
55421
|
+
this.writeField(id, field, value);
|
|
55422
|
+
}
|
|
55423
|
+
}
|
|
55424
|
+
for (const [id, values] of Object.entries(layer.links)) {
|
|
55425
|
+
if (!values) {
|
|
55426
|
+
continue;
|
|
55427
|
+
}
|
|
55428
|
+
for (const [field, value] of Object.entries(values)) {
|
|
55429
|
+
this.writeLink(id, field, value);
|
|
55430
|
+
}
|
|
55431
|
+
}
|
|
55432
|
+
layer.deletedIDs.forEach((v) => this.deletedIDs.add(v));
|
|
55433
|
+
}
|
|
55434
|
+
addFieldOperation(id, field, operation) {
|
|
55435
|
+
this.operations = {
|
|
55436
|
+
...this.operations,
|
|
55437
|
+
[id]: {
|
|
55438
|
+
...this.operations[id],
|
|
55439
|
+
fields: {
|
|
55440
|
+
[field]: [...this.operations[id]?.fields[field] || [], operation]
|
|
55441
|
+
}
|
|
55442
|
+
}
|
|
55443
|
+
};
|
|
55444
|
+
}
|
|
55445
|
+
};
|
|
55446
|
+
function isDeleteOperation(value) {
|
|
55447
|
+
return !!value && value.kind === OperationKind.delete;
|
|
55448
|
+
}
|
|
55449
|
+
function isInsertOperation(value) {
|
|
55450
|
+
return !!value && value.kind === OperationKind.insert;
|
|
55451
|
+
}
|
|
55452
|
+
function isRemoveOperation(value) {
|
|
55453
|
+
return !!value && value.kind === OperationKind.remove;
|
|
55454
|
+
}
|
|
55455
|
+
var OperationLocation = {
|
|
55456
|
+
start: "start",
|
|
55457
|
+
end: "end"
|
|
55458
|
+
};
|
|
55459
|
+
var OperationKind = {
|
|
55460
|
+
delete: "delete",
|
|
55461
|
+
insert: "insert",
|
|
55462
|
+
remove: "remove"
|
|
55463
|
+
};
|
|
55464
|
+
|
|
55465
|
+
// src/runtime/cache/stuff.ts
|
|
55466
|
+
function evaluateKey(key, variables = {}) {
|
|
55467
|
+
let evaluated = "";
|
|
55468
|
+
let varName = "";
|
|
55469
|
+
let inString = false;
|
|
55470
|
+
for (const char of key) {
|
|
55471
|
+
if (varName) {
|
|
55472
|
+
if (varChars.includes(char)) {
|
|
55473
|
+
varName += char;
|
|
55474
|
+
continue;
|
|
55475
|
+
}
|
|
55476
|
+
const value = variables[varName.slice(1)];
|
|
55477
|
+
evaluated += typeof value !== "undefined" ? JSON.stringify(value) : "undefined";
|
|
55478
|
+
varName = "";
|
|
55479
|
+
}
|
|
55480
|
+
if (char === "$" && !inString) {
|
|
55481
|
+
varName = "$";
|
|
55482
|
+
continue;
|
|
55483
|
+
}
|
|
55484
|
+
if (char === '"') {
|
|
55485
|
+
inString = !inString;
|
|
55486
|
+
}
|
|
55487
|
+
evaluated += char;
|
|
55488
|
+
}
|
|
55489
|
+
return evaluated;
|
|
55490
|
+
}
|
|
55491
|
+
var varChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789";
|
|
55492
|
+
|
|
55493
|
+
// src/runtime/cache/subscription.ts
|
|
55494
|
+
var InMemorySubscriptions = class {
|
|
55495
|
+
cache;
|
|
55496
|
+
constructor(cache) {
|
|
55497
|
+
this.cache = cache;
|
|
55498
|
+
}
|
|
55499
|
+
subscribers = {};
|
|
55500
|
+
referenceCounts = {};
|
|
55501
|
+
keyVersions = {};
|
|
55502
|
+
add({
|
|
55503
|
+
parent,
|
|
55504
|
+
spec,
|
|
55505
|
+
selection: selection2,
|
|
55506
|
+
variables,
|
|
55507
|
+
parentType
|
|
55508
|
+
}) {
|
|
55509
|
+
const __typename = this.cache._internal_unstable.storage.get(parent, "__typename").value;
|
|
55510
|
+
let targetSelection = getFieldsForType(selection2, __typename);
|
|
55511
|
+
for (const fieldSelection of Object.values(targetSelection || {})) {
|
|
55512
|
+
const { keyRaw, selection: innerSelection, type, list, filters } = fieldSelection;
|
|
55513
|
+
const key = evaluateKey(keyRaw, variables);
|
|
55514
|
+
let targetSelection2;
|
|
55515
|
+
if (innerSelection) {
|
|
55516
|
+
const __typename2 = this.cache._internal_unstable.storage.get(parent, "__typename").value;
|
|
55517
|
+
targetSelection2 = getFieldsForType(innerSelection, __typename2);
|
|
55518
|
+
}
|
|
55519
|
+
this.addFieldSubscription({
|
|
55520
|
+
id: parent,
|
|
55521
|
+
key,
|
|
55522
|
+
selection: [spec, targetSelection2],
|
|
55523
|
+
type
|
|
55524
|
+
});
|
|
55525
|
+
if (list) {
|
|
55526
|
+
this.registerList({
|
|
55527
|
+
list,
|
|
55528
|
+
filters,
|
|
55529
|
+
id: parent,
|
|
55530
|
+
key,
|
|
55531
|
+
variables,
|
|
55532
|
+
selection: innerSelection,
|
|
55533
|
+
parentType: parentType || spec.rootType
|
|
55534
|
+
});
|
|
55535
|
+
}
|
|
55536
|
+
if (innerSelection) {
|
|
55537
|
+
const { value: linkedRecord } = this.cache._internal_unstable.storage.get(
|
|
55538
|
+
parent,
|
|
55539
|
+
key
|
|
55540
|
+
);
|
|
55541
|
+
let children = !Array.isArray(linkedRecord) ? [linkedRecord] : flatten(linkedRecord) || [];
|
|
55542
|
+
for (const child of children) {
|
|
55543
|
+
if (!child) {
|
|
55544
|
+
continue;
|
|
55545
|
+
}
|
|
55546
|
+
this.add({
|
|
55547
|
+
parent: child,
|
|
55548
|
+
spec,
|
|
55549
|
+
selection: innerSelection,
|
|
55550
|
+
variables,
|
|
55551
|
+
parentType: type
|
|
55552
|
+
});
|
|
55553
|
+
}
|
|
55554
|
+
}
|
|
55555
|
+
}
|
|
55556
|
+
}
|
|
55557
|
+
addFieldSubscription({
|
|
55558
|
+
id,
|
|
55559
|
+
key,
|
|
55560
|
+
selection: selection2,
|
|
55561
|
+
type
|
|
55562
|
+
}) {
|
|
55563
|
+
const spec = selection2[0];
|
|
55564
|
+
if (!this.subscribers[id]) {
|
|
55565
|
+
this.subscribers[id] = {};
|
|
55566
|
+
}
|
|
55567
|
+
if (!this.subscribers[id][key]) {
|
|
55568
|
+
this.subscribers[id][key] = [];
|
|
55569
|
+
}
|
|
55570
|
+
if (!this.keyVersions[key]) {
|
|
55571
|
+
this.keyVersions[key] = /* @__PURE__ */ new Set();
|
|
55572
|
+
}
|
|
55573
|
+
this.keyVersions[key].add(key);
|
|
55574
|
+
if (!this.subscribers[id][key].map(([{ set }]) => set).includes(spec.set)) {
|
|
55575
|
+
this.subscribers[id][key].push([spec, selection2[1]]);
|
|
55576
|
+
}
|
|
55577
|
+
if (!this.referenceCounts[id]) {
|
|
55578
|
+
this.referenceCounts[id] = {};
|
|
55579
|
+
}
|
|
55580
|
+
if (!this.referenceCounts[id][key]) {
|
|
55581
|
+
this.referenceCounts[id][key] = /* @__PURE__ */ new Map();
|
|
55582
|
+
}
|
|
55583
|
+
const counts = this.referenceCounts[id][key];
|
|
55584
|
+
counts.set(spec.set, (counts.get(spec.set) || 0) + 1);
|
|
55585
|
+
this.cache._internal_unstable.lifetimes.resetLifetime(id, key);
|
|
55586
|
+
const { selection: innerSelection } = selection2[1]?.[key] ?? {};
|
|
55587
|
+
}
|
|
55588
|
+
registerList({
|
|
55589
|
+
list,
|
|
55590
|
+
id,
|
|
55591
|
+
key,
|
|
55592
|
+
parentType,
|
|
55593
|
+
selection: selection2,
|
|
55594
|
+
filters,
|
|
55595
|
+
variables
|
|
55596
|
+
}) {
|
|
55597
|
+
this.cache._internal_unstable.lists.add({
|
|
55598
|
+
name: list.name,
|
|
55599
|
+
connection: list.connection,
|
|
55600
|
+
recordID: id,
|
|
55601
|
+
recordType: this.cache._internal_unstable.storage.get(id, "__typename")?.value || parentType,
|
|
55602
|
+
listType: list.type,
|
|
55603
|
+
key,
|
|
55604
|
+
selection: selection2,
|
|
55605
|
+
filters: Object.entries(filters || {}).reduce((acc, [key2, { kind, value }]) => {
|
|
55606
|
+
return {
|
|
55607
|
+
...acc,
|
|
55608
|
+
[key2]: kind !== "Variable" ? value : variables[value]
|
|
55609
|
+
};
|
|
55610
|
+
}, {})
|
|
55611
|
+
});
|
|
55612
|
+
}
|
|
55613
|
+
addMany({
|
|
55614
|
+
parent,
|
|
55615
|
+
variables,
|
|
55616
|
+
subscribers,
|
|
55617
|
+
parentType
|
|
55618
|
+
}) {
|
|
55619
|
+
for (const [spec, targetSelection] of subscribers) {
|
|
55620
|
+
for (const selection2 of Object.values(targetSelection ?? {})) {
|
|
55621
|
+
const {
|
|
55622
|
+
type: linkedType,
|
|
55623
|
+
keyRaw,
|
|
55624
|
+
selection: innerSelection,
|
|
55625
|
+
list,
|
|
55626
|
+
filters
|
|
55627
|
+
} = selection2;
|
|
55628
|
+
const key = evaluateKey(keyRaw, variables);
|
|
55629
|
+
const fieldSelection = innerSelection ? getFieldsForType(innerSelection, parentType) : void 0;
|
|
55630
|
+
this.addFieldSubscription({
|
|
55631
|
+
id: parent,
|
|
55632
|
+
key,
|
|
55633
|
+
selection: [spec, fieldSelection],
|
|
55634
|
+
type: linkedType
|
|
55635
|
+
});
|
|
55636
|
+
if (list) {
|
|
55637
|
+
this.registerList({
|
|
55638
|
+
list,
|
|
55639
|
+
filters,
|
|
55640
|
+
id: parent,
|
|
55641
|
+
key,
|
|
55642
|
+
variables,
|
|
55643
|
+
selection: innerSelection,
|
|
55644
|
+
parentType: parentType || spec.rootType
|
|
55645
|
+
});
|
|
55646
|
+
}
|
|
55647
|
+
const childSelection = selection2.selection;
|
|
55648
|
+
if (childSelection) {
|
|
55649
|
+
const { value: link } = this.cache._internal_unstable.storage.get(parent, key);
|
|
55650
|
+
const children = !Array.isArray(link) ? [link] : flatten(link);
|
|
55651
|
+
for (const linkedRecord of children) {
|
|
55652
|
+
if (!linkedRecord) {
|
|
55653
|
+
continue;
|
|
55654
|
+
}
|
|
55655
|
+
const __typename = this.cache._internal_unstable.storage.get(
|
|
55656
|
+
linkedRecord,
|
|
55657
|
+
"__typename"
|
|
55658
|
+
).value;
|
|
55659
|
+
let targetSelection2 = getFieldsForType(childSelection, __typename);
|
|
55660
|
+
this.addMany({
|
|
55661
|
+
parent: linkedRecord,
|
|
55662
|
+
variables,
|
|
55663
|
+
subscribers: subscribers.map(([sub]) => [sub, targetSelection2]),
|
|
55664
|
+
parentType: linkedType
|
|
55665
|
+
});
|
|
55666
|
+
}
|
|
55667
|
+
}
|
|
55668
|
+
}
|
|
55669
|
+
}
|
|
55670
|
+
}
|
|
55671
|
+
get(id, field) {
|
|
55672
|
+
return this.subscribers[id]?.[field] || [];
|
|
55673
|
+
}
|
|
55674
|
+
remove(id, selection2, targets, variables, visited = []) {
|
|
55675
|
+
visited.push(id);
|
|
55676
|
+
const linkedIDs = [];
|
|
55677
|
+
const __typename = this.cache._internal_unstable.storage.get(id, "__typename").value;
|
|
55678
|
+
let targetSelection = getFieldsForType(selection2, __typename);
|
|
55679
|
+
for (const fieldSelection of Object.values(targetSelection || {})) {
|
|
55680
|
+
const key = evaluateKey(fieldSelection.keyRaw, variables);
|
|
55681
|
+
this.removeSubscribers(id, key, targets);
|
|
55682
|
+
if (!fieldSelection.selection) {
|
|
55683
|
+
continue;
|
|
55684
|
+
}
|
|
55685
|
+
const { value: previousValue } = this.cache._internal_unstable.storage.get(id, key);
|
|
55686
|
+
const links = !Array.isArray(previousValue) ? [previousValue] : flatten(previousValue);
|
|
55687
|
+
for (const link of links) {
|
|
55688
|
+
if (link !== null) {
|
|
55689
|
+
linkedIDs.push([link, fieldSelection.selection || {}]);
|
|
55690
|
+
}
|
|
55691
|
+
}
|
|
55692
|
+
}
|
|
55693
|
+
for (const [linkedRecordID, linkFields] of linkedIDs) {
|
|
55694
|
+
this.remove(linkedRecordID, linkFields, targets, visited);
|
|
55695
|
+
}
|
|
55696
|
+
}
|
|
55697
|
+
removeSubscribers(id, fieldName, specs) {
|
|
55698
|
+
let targets = [];
|
|
55699
|
+
for (const spec of specs) {
|
|
55700
|
+
if (!this.referenceCounts[id]?.[fieldName]?.has(spec.set)) {
|
|
55701
|
+
continue;
|
|
55702
|
+
}
|
|
55703
|
+
const counts = this.referenceCounts[id][fieldName];
|
|
55704
|
+
const newVal = (counts.get(spec.set) || 0) - 1;
|
|
55705
|
+
counts.set(spec.set, newVal);
|
|
55706
|
+
if (newVal <= 0) {
|
|
55707
|
+
targets.push(spec.set);
|
|
55708
|
+
counts.delete(spec.set);
|
|
55709
|
+
}
|
|
55710
|
+
}
|
|
55711
|
+
if (this.subscribers[id]) {
|
|
55712
|
+
this.subscribers[id][fieldName] = this.get(id, fieldName).filter(
|
|
55713
|
+
([{ set }]) => !targets.includes(set)
|
|
55714
|
+
);
|
|
55715
|
+
}
|
|
55716
|
+
}
|
|
55717
|
+
removeAllSubscribers(id, targets, visited = []) {
|
|
55718
|
+
visited.push(id);
|
|
55719
|
+
for (const field of Object.keys(this.subscribers[id] || [])) {
|
|
55720
|
+
const subscribers = targets || this.subscribers[id][field].map(([spec]) => spec);
|
|
55721
|
+
this.removeSubscribers(id, field, subscribers);
|
|
55722
|
+
const { value, kind } = this.cache._internal_unstable.storage.get(id, field);
|
|
55723
|
+
if (kind === "scalar") {
|
|
55724
|
+
continue;
|
|
55725
|
+
}
|
|
55726
|
+
const nextTargets = Array.isArray(value) ? flatten(value) : [value];
|
|
55727
|
+
for (const id2 of nextTargets) {
|
|
55728
|
+
if (visited.includes(id2)) {
|
|
55729
|
+
continue;
|
|
55730
|
+
}
|
|
55731
|
+
this.removeAllSubscribers(id2, subscribers, visited);
|
|
55732
|
+
}
|
|
55733
|
+
}
|
|
55734
|
+
}
|
|
55735
|
+
};
|
|
55736
|
+
|
|
55737
|
+
// src/runtime/cache/cache.ts
|
|
55738
|
+
var Cache = class {
|
|
55739
|
+
_internal_unstable;
|
|
55740
|
+
constructor(config2) {
|
|
55741
|
+
this._internal_unstable = new CacheInternal({
|
|
55742
|
+
cache: this,
|
|
55743
|
+
storage: new InMemoryStorage(),
|
|
55744
|
+
subscriptions: new InMemorySubscriptions(this),
|
|
55745
|
+
lists: new ListManager(this, rootID),
|
|
55746
|
+
lifetimes: new GarbageCollector(this),
|
|
55747
|
+
staleManager: new StaleManager(this),
|
|
55748
|
+
schema: new SchemaManager(this)
|
|
55749
|
+
});
|
|
55750
|
+
if (config2) {
|
|
55751
|
+
this.setConfig(defaultConfigValues(config2));
|
|
55752
|
+
}
|
|
55753
|
+
}
|
|
55754
|
+
write({
|
|
55755
|
+
layer: layerID,
|
|
55756
|
+
notifySubscribers = [],
|
|
55757
|
+
...args
|
|
55758
|
+
}) {
|
|
55759
|
+
const layer = layerID ? this._internal_unstable.storage.getLayer(layerID) : this._internal_unstable.storage.topLayer;
|
|
55760
|
+
const subscribers = this._internal_unstable.writeSelection({ ...args, layer }).map((sub) => sub[0]);
|
|
55761
|
+
const notified = [];
|
|
55762
|
+
for (const spec of subscribers.concat(notifySubscribers)) {
|
|
55763
|
+
if (!notified.includes(spec.set)) {
|
|
55764
|
+
notified.push(spec.set);
|
|
55765
|
+
spec.set(
|
|
55766
|
+
this._internal_unstable.getSelection({
|
|
55767
|
+
parent: spec.parentID || rootID,
|
|
55768
|
+
selection: spec.selection,
|
|
55769
|
+
variables: spec.variables?.() || {}
|
|
55770
|
+
}).data
|
|
55771
|
+
);
|
|
55772
|
+
}
|
|
55773
|
+
}
|
|
55774
|
+
return subscribers;
|
|
55775
|
+
}
|
|
55776
|
+
read(...args) {
|
|
55777
|
+
const { data, partial, stale, hasData } = this._internal_unstable.getSelection(...args);
|
|
55778
|
+
if (!hasData) {
|
|
55779
|
+
return { data: null, partial: false, stale: false };
|
|
55780
|
+
}
|
|
55781
|
+
return {
|
|
55782
|
+
data,
|
|
55783
|
+
partial,
|
|
55784
|
+
stale
|
|
55785
|
+
};
|
|
55786
|
+
}
|
|
55787
|
+
subscribe(spec, variables = {}) {
|
|
55788
|
+
return this._internal_unstable.subscriptions.add({
|
|
55789
|
+
parent: spec.parentID || rootID,
|
|
55790
|
+
spec,
|
|
55791
|
+
selection: spec.selection,
|
|
55792
|
+
variables
|
|
55793
|
+
});
|
|
55794
|
+
}
|
|
55795
|
+
unsubscribe(spec, variables = {}) {
|
|
55796
|
+
return this._internal_unstable.subscriptions.remove(
|
|
55797
|
+
spec.parentID || rootID,
|
|
55798
|
+
spec.selection,
|
|
55799
|
+
[spec],
|
|
55800
|
+
variables
|
|
55801
|
+
);
|
|
55802
|
+
}
|
|
55803
|
+
list(name, parentID, allLists) {
|
|
55804
|
+
const handler = this._internal_unstable.lists.get(name, parentID, allLists);
|
|
55805
|
+
if (!handler) {
|
|
55806
|
+
throw new Error(
|
|
55807
|
+
`Cannot find list with name: ${name}${parentID ? " under parent " + parentID : ""}. Is it possible that the query is not mounted?`
|
|
55808
|
+
);
|
|
55809
|
+
}
|
|
55810
|
+
return handler;
|
|
55811
|
+
}
|
|
55812
|
+
delete(id) {
|
|
55813
|
+
this._internal_unstable.subscriptions.removeAllSubscribers(id);
|
|
55814
|
+
this._internal_unstable.lists.removeIDFromAllLists(id);
|
|
55815
|
+
this._internal_unstable.storage.delete(id);
|
|
55816
|
+
}
|
|
55817
|
+
setConfig(config2) {
|
|
55818
|
+
this._internal_unstable.setConfig(config2);
|
|
55819
|
+
}
|
|
55820
|
+
markTypeStale(options) {
|
|
55821
|
+
if (!options) {
|
|
55822
|
+
this._internal_unstable.staleManager.markAllStale();
|
|
55823
|
+
} else if (!options.field) {
|
|
55824
|
+
this._internal_unstable.staleManager.markTypeStale(options.type);
|
|
55825
|
+
} else {
|
|
55826
|
+
this._internal_unstable.staleManager.markTypeFieldStale(
|
|
55827
|
+
options.type,
|
|
55828
|
+
options.field,
|
|
55829
|
+
options.when
|
|
55830
|
+
);
|
|
55831
|
+
}
|
|
55832
|
+
}
|
|
55833
|
+
markRecordStale(id, options) {
|
|
55834
|
+
if (options.field) {
|
|
55835
|
+
const key = computeKey({ field: options.field, args: options.when ?? {} });
|
|
55836
|
+
this._internal_unstable.staleManager.markFieldStale(id, key);
|
|
55837
|
+
} else {
|
|
55838
|
+
this._internal_unstable.staleManager.markRecordStale(id);
|
|
55839
|
+
}
|
|
55840
|
+
}
|
|
55841
|
+
getFieldTime(id, field) {
|
|
55842
|
+
return this._internal_unstable.staleManager.getFieldTime(id, field);
|
|
55843
|
+
}
|
|
55844
|
+
};
|
|
55845
|
+
var CacheInternal = class {
|
|
55846
|
+
_disabled = false;
|
|
55847
|
+
config = defaultConfigValues({
|
|
55848
|
+
plugins: {
|
|
55849
|
+
"houdini-svelte": {
|
|
55850
|
+
client: ""
|
|
55851
|
+
}
|
|
55852
|
+
}
|
|
55853
|
+
});
|
|
55854
|
+
storage;
|
|
55855
|
+
subscriptions;
|
|
55856
|
+
lists;
|
|
55857
|
+
cache;
|
|
55858
|
+
lifetimes;
|
|
55859
|
+
staleManager;
|
|
55860
|
+
schema;
|
|
55861
|
+
constructor({
|
|
55862
|
+
storage,
|
|
55863
|
+
subscriptions,
|
|
55864
|
+
lists,
|
|
55865
|
+
cache,
|
|
55866
|
+
lifetimes,
|
|
55867
|
+
staleManager,
|
|
55868
|
+
schema
|
|
55869
|
+
}) {
|
|
55870
|
+
this.storage = storage;
|
|
55871
|
+
this.subscriptions = subscriptions;
|
|
55872
|
+
this.lists = lists;
|
|
55873
|
+
this.cache = cache;
|
|
55874
|
+
this.lifetimes = lifetimes;
|
|
55875
|
+
this.staleManager = staleManager;
|
|
55876
|
+
this.schema = schema;
|
|
55877
|
+
this._disabled = typeof globalThis.window === "undefined";
|
|
55878
|
+
try {
|
|
55879
|
+
if (process.env.HOUDINI_TEST === "true") {
|
|
55880
|
+
this._disabled = false;
|
|
55881
|
+
}
|
|
55882
|
+
} catch {
|
|
55883
|
+
}
|
|
55884
|
+
}
|
|
55885
|
+
setConfig(config2) {
|
|
55886
|
+
this.config = config2;
|
|
55887
|
+
}
|
|
55888
|
+
writeSelection({
|
|
55889
|
+
data,
|
|
55890
|
+
selection: selection2,
|
|
55891
|
+
variables = {},
|
|
55892
|
+
parent = rootID,
|
|
55893
|
+
applyUpdates,
|
|
55894
|
+
layer,
|
|
55895
|
+
toNotify = [],
|
|
55896
|
+
forceNotify,
|
|
55897
|
+
forceStale
|
|
55898
|
+
}) {
|
|
55899
|
+
if (this._disabled) {
|
|
55900
|
+
return [];
|
|
55901
|
+
}
|
|
55902
|
+
let targetSelection = getFieldsForType(selection2, data["__typename"]);
|
|
55903
|
+
for (const [field, value] of Object.entries(data)) {
|
|
55904
|
+
if (!selection2 || !targetSelection[field]) {
|
|
55905
|
+
throw new Error(
|
|
55906
|
+
"Could not find field listing in selection for " + field + " @ " + JSON.stringify(selection2)
|
|
55907
|
+
);
|
|
55908
|
+
}
|
|
55909
|
+
let {
|
|
55910
|
+
type: linkedType,
|
|
55911
|
+
keyRaw,
|
|
55912
|
+
selection: fieldSelection,
|
|
55913
|
+
operations,
|
|
55914
|
+
abstract: isAbstract,
|
|
55915
|
+
updates,
|
|
55916
|
+
nullable
|
|
55917
|
+
} = targetSelection[field];
|
|
55918
|
+
const key = evaluateKey(keyRaw, variables);
|
|
55919
|
+
this.schema.setFieldType({
|
|
55920
|
+
parent,
|
|
55921
|
+
key: keyRaw,
|
|
55922
|
+
type: linkedType,
|
|
55923
|
+
nullable,
|
|
55924
|
+
link: !!fieldSelection
|
|
55925
|
+
});
|
|
55926
|
+
const currentSubscribers = this.subscriptions.get(parent, key);
|
|
55927
|
+
const specs = currentSubscribers.map((sub) => sub[0]);
|
|
55928
|
+
const { value: previousValue, displayLayers } = this.storage.get(parent, key);
|
|
55929
|
+
const displayLayer = layer.isDisplayLayer(displayLayers);
|
|
55930
|
+
if (displayLayer) {
|
|
55931
|
+
this.lifetimes.resetLifetime(parent, key);
|
|
55932
|
+
if (forceStale) {
|
|
55933
|
+
this.staleManager.markFieldStale(parent, key);
|
|
55934
|
+
} else {
|
|
55935
|
+
this.staleManager.setFieldTimeToNow(parent, key);
|
|
55936
|
+
}
|
|
55937
|
+
}
|
|
55938
|
+
if (!fieldSelection) {
|
|
55939
|
+
let newValue = value;
|
|
55940
|
+
if (updates && applyUpdates && Array.isArray(value)) {
|
|
55941
|
+
for (const update of applyUpdates) {
|
|
55942
|
+
if (!updates.includes(update)) {
|
|
55943
|
+
continue;
|
|
55944
|
+
}
|
|
55945
|
+
if (update === "append") {
|
|
55946
|
+
newValue = (previousValue || []).concat(value);
|
|
55947
|
+
} else if (update === "prepend") {
|
|
55948
|
+
newValue = value.concat(previousValue || []);
|
|
55949
|
+
}
|
|
55950
|
+
}
|
|
55951
|
+
}
|
|
55952
|
+
if (updates && applyUpdates?.includes("prepend") && ["endCursor", "hasNextPage"].includes(key)) {
|
|
55953
|
+
newValue = previousValue;
|
|
55954
|
+
} else if (updates && applyUpdates?.includes("append") && ["startCursor", "hasPreviousPage"].includes(key)) {
|
|
55955
|
+
newValue = previousValue;
|
|
55956
|
+
}
|
|
55957
|
+
const valueChanged = !deepEquals(newValue, previousValue);
|
|
55958
|
+
if (displayLayer && (valueChanged || forceNotify)) {
|
|
55959
|
+
toNotify.push(...currentSubscribers);
|
|
55960
|
+
}
|
|
55961
|
+
layer.writeField(parent, key, newValue);
|
|
55962
|
+
} else if (value === null) {
|
|
55963
|
+
if (previousValue === null) {
|
|
55964
|
+
continue;
|
|
55965
|
+
}
|
|
55966
|
+
const previousLinks = flatten([previousValue]);
|
|
55967
|
+
for (const link of previousLinks) {
|
|
55968
|
+
this.subscriptions.remove(link, fieldSelection, specs, variables);
|
|
55969
|
+
}
|
|
55970
|
+
layer.writeLink(parent, key, null);
|
|
55971
|
+
toNotify.push(...currentSubscribers);
|
|
55972
|
+
} else if (value instanceof Object && !Array.isArray(value)) {
|
|
55973
|
+
if (isAbstract) {
|
|
55974
|
+
if (!value.__typename) {
|
|
55975
|
+
throw new Error(
|
|
55976
|
+
"Encountered interface type without __typename in the payload"
|
|
55977
|
+
);
|
|
55978
|
+
}
|
|
55979
|
+
linkedType = value.__typename;
|
|
55980
|
+
}
|
|
55981
|
+
const embedded = this.idFields(linkedType)?.filter(
|
|
55982
|
+
(field2) => typeof value[field2] === "undefined"
|
|
55983
|
+
).length > 0;
|
|
55984
|
+
let linkedID = null;
|
|
55985
|
+
if (value !== null) {
|
|
55986
|
+
linkedID = !embedded ? this.id(linkedType, value) : `${parent}.${key}`;
|
|
55987
|
+
}
|
|
55988
|
+
let linkChange = linkedID !== previousValue;
|
|
55989
|
+
layer.writeLink(parent, key, linkedID);
|
|
55990
|
+
if (linkedID && displayLayer && (linkChange || forceNotify)) {
|
|
55991
|
+
if (previousValue && typeof previousValue === "string") {
|
|
55992
|
+
this.subscriptions.remove(previousValue, fieldSelection, specs, variables);
|
|
55993
|
+
}
|
|
55994
|
+
this.subscriptions.addMany({
|
|
55995
|
+
parent: linkedID,
|
|
55996
|
+
subscribers: currentSubscribers,
|
|
55997
|
+
variables,
|
|
55998
|
+
parentType: linkedType
|
|
55999
|
+
});
|
|
56000
|
+
toNotify.push(...currentSubscribers);
|
|
56001
|
+
}
|
|
56002
|
+
if (linkedID) {
|
|
56003
|
+
this.writeSelection({
|
|
56004
|
+
selection: fieldSelection,
|
|
56005
|
+
parent: linkedID,
|
|
56006
|
+
data: value,
|
|
56007
|
+
variables,
|
|
56008
|
+
toNotify,
|
|
56009
|
+
applyUpdates,
|
|
56010
|
+
layer,
|
|
56011
|
+
forceNotify
|
|
56012
|
+
});
|
|
56013
|
+
}
|
|
56014
|
+
} else if (Array.isArray(value) && (typeof previousValue === "undefined" || Array.isArray(previousValue))) {
|
|
56015
|
+
let oldIDs = [...previousValue || []];
|
|
56016
|
+
const emptyEdges = !updates ? [] : oldIDs.map((id) => {
|
|
56017
|
+
if (!id) {
|
|
56018
|
+
return "";
|
|
56019
|
+
}
|
|
56020
|
+
const { value: cursorField } = this.storage.get(id, "cursor");
|
|
56021
|
+
if (cursorField) {
|
|
56022
|
+
return "";
|
|
56023
|
+
}
|
|
56024
|
+
const { value: node } = this.storage.get(id, "node");
|
|
56025
|
+
if (!node) {
|
|
56026
|
+
return "";
|
|
56027
|
+
}
|
|
56028
|
+
return node;
|
|
56029
|
+
});
|
|
56030
|
+
let linkedIDs = [];
|
|
56031
|
+
const { newIDs, nestedIDs } = this.extractNestedListIDs({
|
|
56032
|
+
value,
|
|
56033
|
+
abstract: Boolean(isAbstract),
|
|
56034
|
+
specs: toNotify,
|
|
56035
|
+
applyUpdates,
|
|
56036
|
+
recordID: parent,
|
|
56037
|
+
key,
|
|
56038
|
+
linkedType,
|
|
56039
|
+
variables,
|
|
56040
|
+
fields: fieldSelection,
|
|
56041
|
+
layer,
|
|
56042
|
+
forceNotify
|
|
56043
|
+
});
|
|
56044
|
+
if (applyUpdates && updates) {
|
|
56045
|
+
if (key === "edges") {
|
|
56046
|
+
const newNodeIDs = [];
|
|
56047
|
+
for (const id of newIDs) {
|
|
56048
|
+
if (!id) {
|
|
56049
|
+
continue;
|
|
56050
|
+
}
|
|
56051
|
+
const { value: node } = this.storage.get(id, "node");
|
|
56052
|
+
if (typeof node !== "string") {
|
|
56053
|
+
continue;
|
|
56054
|
+
}
|
|
56055
|
+
if (!node || !this.storage.get(node, "__typename")) {
|
|
56056
|
+
continue;
|
|
56057
|
+
}
|
|
56058
|
+
newNodeIDs.push(node);
|
|
56059
|
+
}
|
|
56060
|
+
oldIDs = oldIDs.filter((id) => {
|
|
56061
|
+
if (!id) {
|
|
56062
|
+
return true;
|
|
56063
|
+
}
|
|
56064
|
+
const { value: value2 } = this.storage.get(id, "node");
|
|
56065
|
+
const node = value2;
|
|
56066
|
+
if (newNodeIDs.includes(node) && emptyEdges.includes(node)) {
|
|
56067
|
+
return false;
|
|
56068
|
+
}
|
|
56069
|
+
return true;
|
|
56070
|
+
});
|
|
56071
|
+
}
|
|
56072
|
+
for (const update of applyUpdates) {
|
|
56073
|
+
if (update !== "replace" && !updates.includes(update)) {
|
|
56074
|
+
continue;
|
|
56075
|
+
}
|
|
56076
|
+
if (update === "prepend") {
|
|
56077
|
+
linkedIDs = newIDs.concat(oldIDs);
|
|
56078
|
+
} else if (update === "append") {
|
|
56079
|
+
linkedIDs = oldIDs.concat(newIDs);
|
|
56080
|
+
} else if (update === "replace") {
|
|
56081
|
+
linkedIDs = newIDs;
|
|
56082
|
+
}
|
|
56083
|
+
}
|
|
56084
|
+
} else {
|
|
56085
|
+
linkedIDs = nestedIDs;
|
|
56086
|
+
}
|
|
56087
|
+
const contentChanged = !deepEquals(linkedIDs, oldIDs);
|
|
56088
|
+
if (contentChanged || forceNotify) {
|
|
56089
|
+
toNotify.push(...currentSubscribers);
|
|
56090
|
+
}
|
|
56091
|
+
for (const lostID of oldIDs) {
|
|
56092
|
+
if (linkedIDs.includes(lostID) || !lostID) {
|
|
56093
|
+
continue;
|
|
56094
|
+
}
|
|
56095
|
+
this.subscriptions.remove(lostID, fieldSelection, specs, variables);
|
|
56096
|
+
}
|
|
56097
|
+
if (contentChanged || oldIDs.length === 0 && newIDs.length === 0) {
|
|
56098
|
+
layer.writeLink(parent, key, linkedIDs);
|
|
56099
|
+
}
|
|
56100
|
+
for (const id of newIDs.filter((id2) => !oldIDs.includes(id2))) {
|
|
56101
|
+
if (id == null) {
|
|
56102
|
+
continue;
|
|
56103
|
+
}
|
|
56104
|
+
this.subscriptions.addMany({
|
|
56105
|
+
parent: id,
|
|
56106
|
+
subscribers: currentSubscribers,
|
|
56107
|
+
variables,
|
|
56108
|
+
parentType: linkedType
|
|
56109
|
+
});
|
|
56110
|
+
}
|
|
56111
|
+
}
|
|
56112
|
+
for (const operation of operations || []) {
|
|
56113
|
+
let parentID;
|
|
56114
|
+
if (operation.parentID) {
|
|
56115
|
+
if (operation.parentID.kind !== "Variable") {
|
|
56116
|
+
parentID = operation.parentID.value;
|
|
56117
|
+
} else {
|
|
56118
|
+
const id = variables[operation.parentID.value];
|
|
56119
|
+
if (typeof id !== "string") {
|
|
56120
|
+
throw new Error("parentID value must be a string");
|
|
56121
|
+
}
|
|
56122
|
+
parentID = id;
|
|
56123
|
+
}
|
|
56124
|
+
}
|
|
56125
|
+
if (operation.list && !this.lists.get(operation.list, parentID, operation.target === "all")) {
|
|
56126
|
+
continue;
|
|
56127
|
+
}
|
|
56128
|
+
const targets = Array.isArray(value) ? value : [value];
|
|
56129
|
+
for (const target of targets) {
|
|
56130
|
+
if (operation.action === "insert" && target instanceof Object && fieldSelection && operation.list) {
|
|
56131
|
+
this.cache.list(operation.list, parentID, operation.target === "all").when(operation.when).addToList(
|
|
56132
|
+
fieldSelection,
|
|
56133
|
+
target,
|
|
56134
|
+
variables,
|
|
56135
|
+
operation.position || "last"
|
|
56136
|
+
);
|
|
56137
|
+
} else if (operation.action === "remove" && target instanceof Object && fieldSelection && operation.list) {
|
|
56138
|
+
this.cache.list(operation.list, parentID, operation.target === "all").when(operation.when).remove(target, variables);
|
|
56139
|
+
} else if (operation.action === "delete" && operation.type) {
|
|
56140
|
+
if (typeof target !== "string") {
|
|
56141
|
+
throw new Error("Cannot delete a record with a non-string ID");
|
|
56142
|
+
}
|
|
56143
|
+
const targetID = this.id(operation.type, target);
|
|
56144
|
+
if (!targetID) {
|
|
56145
|
+
continue;
|
|
56146
|
+
}
|
|
56147
|
+
this.cache.delete(targetID);
|
|
56148
|
+
} else if (operation.action === "toggle" && target instanceof Object && fieldSelection && operation.list) {
|
|
56149
|
+
this.cache.list(operation.list, parentID, operation.target === "all").when(operation.when).toggleElement(
|
|
56150
|
+
fieldSelection,
|
|
56151
|
+
target,
|
|
56152
|
+
variables,
|
|
56153
|
+
operation.position || "last"
|
|
56154
|
+
);
|
|
56155
|
+
}
|
|
56156
|
+
}
|
|
56157
|
+
}
|
|
56158
|
+
}
|
|
56159
|
+
return toNotify;
|
|
56160
|
+
}
|
|
56161
|
+
getSelection({
|
|
56162
|
+
selection: selection2,
|
|
56163
|
+
parent = rootID,
|
|
56164
|
+
variables,
|
|
56165
|
+
stepsFromConnection = null
|
|
56166
|
+
}) {
|
|
56167
|
+
if (parent === null) {
|
|
56168
|
+
return { data: null, partial: false, stale: false, hasData: true };
|
|
56169
|
+
}
|
|
56170
|
+
const target = {};
|
|
56171
|
+
let hasData = false;
|
|
56172
|
+
let partial = false;
|
|
56173
|
+
let cascadeNull = false;
|
|
56174
|
+
let stale = false;
|
|
56175
|
+
const typename = this.storage.get(parent, "__typename").value;
|
|
56176
|
+
let targetSelection = getFieldsForType(selection2, typename);
|
|
56177
|
+
for (const [
|
|
56178
|
+
attributeName,
|
|
56179
|
+
{ type, keyRaw, selection: fieldSelection, nullable, list }
|
|
56180
|
+
] of Object.entries(targetSelection)) {
|
|
56181
|
+
const key = evaluateKey(keyRaw, variables);
|
|
56182
|
+
const { value } = this.storage.get(parent, key);
|
|
56183
|
+
const dt_field = this.staleManager.getFieldTime(parent, key);
|
|
56184
|
+
if (dt_field === null) {
|
|
56185
|
+
stale = true;
|
|
56186
|
+
}
|
|
56187
|
+
let nextStep = stepsFromConnection;
|
|
56188
|
+
if (nextStep !== null) {
|
|
56189
|
+
if (nextStep >= 2) {
|
|
56190
|
+
nextStep = null;
|
|
56191
|
+
} else {
|
|
56192
|
+
nextStep += 1;
|
|
56193
|
+
}
|
|
56194
|
+
}
|
|
56195
|
+
if (list?.connection) {
|
|
56196
|
+
nextStep = 0;
|
|
56197
|
+
}
|
|
56198
|
+
const embeddedCursor = key === "cursor" && stepsFromConnection === 1;
|
|
56199
|
+
if (typeof value === "undefined" && !embeddedCursor) {
|
|
56200
|
+
partial = true;
|
|
56201
|
+
}
|
|
56202
|
+
if (typeof value === "undefined" || value === null) {
|
|
56203
|
+
target[attributeName] = null;
|
|
56204
|
+
if (typeof value !== "undefined") {
|
|
56205
|
+
hasData = true;
|
|
56206
|
+
}
|
|
56207
|
+
} else if (!fieldSelection) {
|
|
56208
|
+
const fnUnmarshal = this.config?.scalars?.[type]?.unmarshal;
|
|
56209
|
+
if (fnUnmarshal) {
|
|
56210
|
+
target[attributeName] = fnUnmarshal(value);
|
|
56211
|
+
} else {
|
|
56212
|
+
target[attributeName] = value;
|
|
56213
|
+
}
|
|
56214
|
+
hasData = true;
|
|
56215
|
+
} else if (Array.isArray(value)) {
|
|
56216
|
+
const listValue = this.hydrateNestedList({
|
|
56217
|
+
fields: fieldSelection,
|
|
56218
|
+
variables,
|
|
56219
|
+
linkedList: value,
|
|
56220
|
+
stepsFromConnection: nextStep
|
|
56221
|
+
});
|
|
56222
|
+
target[attributeName] = listValue.data;
|
|
56223
|
+
if (listValue.partial) {
|
|
56224
|
+
partial = true;
|
|
56225
|
+
}
|
|
56226
|
+
if (listValue.stale) {
|
|
56227
|
+
stale = true;
|
|
56228
|
+
}
|
|
56229
|
+
if (listValue.hasData || value.length === 0) {
|
|
56230
|
+
hasData = true;
|
|
56231
|
+
}
|
|
56232
|
+
} else {
|
|
56233
|
+
const objectFields = this.getSelection({
|
|
56234
|
+
parent: value,
|
|
56235
|
+
selection: fieldSelection,
|
|
56236
|
+
variables,
|
|
56237
|
+
stepsFromConnection: nextStep
|
|
56238
|
+
});
|
|
56239
|
+
target[attributeName] = objectFields.data;
|
|
56240
|
+
if (objectFields.partial) {
|
|
56241
|
+
partial = true;
|
|
56242
|
+
}
|
|
56243
|
+
if (objectFields.stale) {
|
|
56244
|
+
stale = true;
|
|
56245
|
+
}
|
|
56246
|
+
if (objectFields.hasData) {
|
|
56247
|
+
hasData = true;
|
|
56248
|
+
}
|
|
56249
|
+
}
|
|
56250
|
+
if (target[attributeName] === null && !nullable && !embeddedCursor) {
|
|
56251
|
+
cascadeNull = true;
|
|
56252
|
+
}
|
|
56253
|
+
}
|
|
56254
|
+
return {
|
|
56255
|
+
data: cascadeNull ? null : target,
|
|
56256
|
+
partial: hasData && partial,
|
|
56257
|
+
stale: hasData && stale,
|
|
56258
|
+
hasData
|
|
56259
|
+
};
|
|
56260
|
+
}
|
|
56261
|
+
id(type, data) {
|
|
56262
|
+
const id = typeof data === "string" ? data : this.computeID(type, data);
|
|
56263
|
+
if (!id) {
|
|
56264
|
+
return null;
|
|
56265
|
+
}
|
|
56266
|
+
if (!type) {
|
|
56267
|
+
return id;
|
|
56268
|
+
}
|
|
56269
|
+
return type + ":" + id;
|
|
56270
|
+
}
|
|
56271
|
+
idFields(type) {
|
|
56272
|
+
return keyFieldsForType(this.config, type);
|
|
56273
|
+
}
|
|
56274
|
+
computeID(type, data) {
|
|
56275
|
+
return computeID(this.config, type, data);
|
|
56276
|
+
}
|
|
56277
|
+
hydrateNestedList({
|
|
56278
|
+
fields,
|
|
56279
|
+
variables,
|
|
56280
|
+
linkedList,
|
|
56281
|
+
stepsFromConnection
|
|
56282
|
+
}) {
|
|
56283
|
+
const result = [];
|
|
56284
|
+
let partialData = false;
|
|
56285
|
+
let stale = false;
|
|
56286
|
+
let hasValues = false;
|
|
56287
|
+
for (const entry of linkedList) {
|
|
56288
|
+
if (Array.isArray(entry)) {
|
|
56289
|
+
const nestedValue = this.hydrateNestedList({
|
|
56290
|
+
fields,
|
|
56291
|
+
variables,
|
|
56292
|
+
linkedList: entry,
|
|
56293
|
+
stepsFromConnection
|
|
56294
|
+
});
|
|
56295
|
+
result.push(nestedValue.data);
|
|
56296
|
+
if (nestedValue.partial) {
|
|
56297
|
+
partialData = true;
|
|
56298
|
+
}
|
|
56299
|
+
continue;
|
|
56300
|
+
}
|
|
56301
|
+
if (entry === null) {
|
|
56302
|
+
result.push(entry);
|
|
56303
|
+
continue;
|
|
56304
|
+
}
|
|
56305
|
+
const {
|
|
56306
|
+
data,
|
|
56307
|
+
partial,
|
|
56308
|
+
stale: local_stale,
|
|
56309
|
+
hasData
|
|
56310
|
+
} = this.getSelection({
|
|
56311
|
+
parent: entry,
|
|
56312
|
+
selection: fields,
|
|
56313
|
+
variables,
|
|
56314
|
+
stepsFromConnection
|
|
56315
|
+
});
|
|
56316
|
+
result.push(data);
|
|
56317
|
+
if (partial) {
|
|
56318
|
+
partialData = true;
|
|
56319
|
+
}
|
|
56320
|
+
if (local_stale) {
|
|
56321
|
+
stale = true;
|
|
56322
|
+
}
|
|
56323
|
+
if (hasData) {
|
|
56324
|
+
hasValues = true;
|
|
56325
|
+
}
|
|
56326
|
+
}
|
|
56327
|
+
return {
|
|
56328
|
+
data: result,
|
|
56329
|
+
partial: partialData,
|
|
56330
|
+
stale,
|
|
56331
|
+
hasData: hasValues
|
|
56332
|
+
};
|
|
56333
|
+
}
|
|
56334
|
+
extractNestedListIDs({
|
|
56335
|
+
value,
|
|
56336
|
+
abstract,
|
|
56337
|
+
recordID,
|
|
56338
|
+
key,
|
|
56339
|
+
linkedType,
|
|
56340
|
+
fields,
|
|
56341
|
+
variables,
|
|
56342
|
+
applyUpdates,
|
|
56343
|
+
specs,
|
|
56344
|
+
layer,
|
|
56345
|
+
forceNotify
|
|
56346
|
+
}) {
|
|
56347
|
+
const nestedIDs = [];
|
|
56348
|
+
const newIDs = [];
|
|
56349
|
+
for (const [i, entry] of value.entries()) {
|
|
56350
|
+
if (Array.isArray(entry)) {
|
|
56351
|
+
const inner = this.extractNestedListIDs({
|
|
56352
|
+
value: entry,
|
|
56353
|
+
abstract,
|
|
56354
|
+
recordID,
|
|
56355
|
+
key,
|
|
56356
|
+
linkedType,
|
|
56357
|
+
fields,
|
|
56358
|
+
variables,
|
|
56359
|
+
applyUpdates,
|
|
56360
|
+
specs,
|
|
56361
|
+
layer,
|
|
56362
|
+
forceNotify
|
|
56363
|
+
});
|
|
56364
|
+
newIDs.push(...inner.newIDs);
|
|
56365
|
+
nestedIDs[i] = inner.nestedIDs;
|
|
56366
|
+
continue;
|
|
56367
|
+
}
|
|
56368
|
+
if (entry === null || typeof entry === "undefined") {
|
|
56369
|
+
newIDs.push(null);
|
|
56370
|
+
nestedIDs[i] = null;
|
|
56371
|
+
continue;
|
|
56372
|
+
}
|
|
56373
|
+
const entryObj = entry;
|
|
56374
|
+
let linkedID = `${recordID}.${key}[${this.storage.nextRank}]`;
|
|
56375
|
+
const embedded = this.idFields(linkedType)?.filter(
|
|
56376
|
+
(field) => typeof entry[field] === "undefined"
|
|
56377
|
+
).length > 0;
|
|
56378
|
+
const typename = entryObj.__typename;
|
|
56379
|
+
let innerType = linkedType;
|
|
56380
|
+
if (abstract) {
|
|
56381
|
+
if (!typename) {
|
|
56382
|
+
throw new Error("Encountered interface type without __typename in the payload");
|
|
56383
|
+
}
|
|
56384
|
+
innerType = typename;
|
|
56385
|
+
}
|
|
56386
|
+
if (!embedded) {
|
|
56387
|
+
const id = this.id(innerType, entry);
|
|
56388
|
+
if (id) {
|
|
56389
|
+
linkedID = id;
|
|
56390
|
+
} else {
|
|
56391
|
+
continue;
|
|
56392
|
+
}
|
|
56393
|
+
}
|
|
56394
|
+
this.writeSelection({
|
|
56395
|
+
root: rootID,
|
|
56396
|
+
selection: fields,
|
|
56397
|
+
parent: linkedID,
|
|
56398
|
+
data: entryObj,
|
|
56399
|
+
variables,
|
|
56400
|
+
toNotify: specs,
|
|
56401
|
+
applyUpdates,
|
|
56402
|
+
layer,
|
|
56403
|
+
forceNotify
|
|
56404
|
+
});
|
|
56405
|
+
newIDs.push(linkedID);
|
|
56406
|
+
nestedIDs[i] = linkedID;
|
|
56407
|
+
}
|
|
56408
|
+
return { newIDs, nestedIDs };
|
|
56409
|
+
}
|
|
56410
|
+
collectGarbage() {
|
|
56411
|
+
this.lifetimes.tick();
|
|
56412
|
+
if (this.storage.layerCount === 1) {
|
|
56413
|
+
this.storage.topLayer.removeUndefinedFields();
|
|
56414
|
+
}
|
|
56415
|
+
}
|
|
56416
|
+
};
|
|
56417
|
+
var rootID = "_ROOT_";
|
|
56418
|
+
|
|
56419
|
+
// src/runtime/cache/index.ts
|
|
56420
|
+
var cache_default = new Cache();
|
|
56421
|
+
|
|
56422
|
+
// src/runtime/client/utils/documentPlugins.ts
|
|
56423
|
+
var documentPlugin = (kind, source) => {
|
|
56424
|
+
return () => {
|
|
56425
|
+
const sourceHandlers = source();
|
|
56426
|
+
const enterWrapper = (handler) => {
|
|
56427
|
+
return !handler ? void 0 : (ctx, handlers) => {
|
|
56428
|
+
if (ctx.artifact.kind !== kind) {
|
|
56429
|
+
return handlers.next(ctx);
|
|
56430
|
+
}
|
|
56431
|
+
return handler(ctx, handlers);
|
|
56432
|
+
};
|
|
56433
|
+
};
|
|
56434
|
+
const exitWrapper = (handler) => {
|
|
56435
|
+
return !handler ? void 0 : (ctx, handlers) => {
|
|
56436
|
+
if (ctx.artifact.kind !== kind) {
|
|
56437
|
+
return handlers.resolve(ctx);
|
|
56438
|
+
}
|
|
56439
|
+
return handler(ctx, handlers);
|
|
56440
|
+
};
|
|
56441
|
+
};
|
|
56442
|
+
return {
|
|
56443
|
+
start: enterWrapper(sourceHandlers.start),
|
|
56444
|
+
network: enterWrapper(sourceHandlers.network),
|
|
56445
|
+
afterNetwork: exitWrapper(sourceHandlers.afterNetwork),
|
|
56446
|
+
end: exitWrapper(sourceHandlers.end),
|
|
56447
|
+
catch: sourceHandlers.catch ? (ctx, handlers) => sourceHandlers.catch(ctx, handlers) : void 0,
|
|
56448
|
+
cleanup: (...args) => sourceHandlers.cleanup?.(...args)
|
|
56449
|
+
};
|
|
56450
|
+
};
|
|
56451
|
+
};
|
|
56452
|
+
|
|
56453
|
+
// src/runtime/client/plugins/query.ts
|
|
56454
|
+
var query = documentPlugin(ArtifactKind.Query, function() {
|
|
56455
|
+
let subscriptionSpec = null;
|
|
56456
|
+
let lastVariables = null;
|
|
56457
|
+
let artifactName = "";
|
|
56458
|
+
return {
|
|
56459
|
+
start(ctx, { next }) {
|
|
56460
|
+
ctx.variables = {
|
|
56461
|
+
...lastVariables,
|
|
56462
|
+
...ctx.variables
|
|
56463
|
+
};
|
|
56464
|
+
next(ctx);
|
|
56465
|
+
},
|
|
56466
|
+
end(ctx, { resolve: resolve2, marshalVariables, variablesChanged }) {
|
|
56467
|
+
if (variablesChanged(ctx)) {
|
|
56468
|
+
artifactName = ctx.artifact.name;
|
|
56469
|
+
if (subscriptionSpec) {
|
|
56470
|
+
cache_default.unsubscribe(subscriptionSpec, subscriptionSpec.variables?.() || {});
|
|
56471
|
+
}
|
|
56472
|
+
lastVariables = { ...marshalVariables(ctx) };
|
|
56473
|
+
subscriptionSpec = {
|
|
56474
|
+
rootType: ctx.artifact.rootType,
|
|
56475
|
+
selection: ctx.artifact.selection,
|
|
56476
|
+
variables: () => lastVariables,
|
|
56477
|
+
set: (newValue) => {
|
|
56478
|
+
resolve2(ctx, {
|
|
56479
|
+
data: newValue,
|
|
56480
|
+
errors: null,
|
|
56481
|
+
fetching: false,
|
|
56482
|
+
partial: false,
|
|
56483
|
+
stale: false,
|
|
56484
|
+
source: DataSource.Cache,
|
|
56485
|
+
variables: ctx.variables ?? null
|
|
56486
|
+
});
|
|
56487
|
+
}
|
|
56488
|
+
};
|
|
56489
|
+
cache_default.subscribe(subscriptionSpec, lastVariables ?? {});
|
|
56490
|
+
}
|
|
56491
|
+
resolve2(ctx);
|
|
56492
|
+
},
|
|
56493
|
+
cleanup() {
|
|
56494
|
+
if (subscriptionSpec) {
|
|
56495
|
+
cache_default.unsubscribe(subscriptionSpec, subscriptionSpec.variables?.() ?? {});
|
|
56496
|
+
lastVariables = null;
|
|
56497
|
+
}
|
|
56498
|
+
}
|
|
56499
|
+
};
|
|
56500
|
+
});
|
|
56501
|
+
|
|
56502
|
+
// src/runtime/client/plugins/mutation.ts
|
|
56503
|
+
var mutation = documentPlugin(ArtifactKind.Mutation, () => {
|
|
56504
|
+
return {
|
|
56505
|
+
async start(ctx, { next, marshalVariables }) {
|
|
56506
|
+
const layer = cache_default._internal_unstable.storage.createLayer(true);
|
|
56507
|
+
const optimisticResponse = ctx.stuff.optimisticResponse;
|
|
56508
|
+
let toNotify = [];
|
|
56509
|
+
if (optimisticResponse) {
|
|
56510
|
+
toNotify = cache_default.write({
|
|
56511
|
+
selection: ctx.artifact.selection,
|
|
56512
|
+
data: await marshalSelection({
|
|
56513
|
+
selection: ctx.artifact.selection,
|
|
56514
|
+
data: optimisticResponse
|
|
56515
|
+
}),
|
|
56516
|
+
variables: marshalVariables(ctx),
|
|
56517
|
+
layer: layer.id
|
|
56518
|
+
});
|
|
56519
|
+
}
|
|
56520
|
+
ctx.cacheParams = {
|
|
56521
|
+
...ctx.cacheParams,
|
|
56522
|
+
layer,
|
|
56523
|
+
notifySubscribers: toNotify,
|
|
56524
|
+
forceNotify: true
|
|
56525
|
+
};
|
|
56526
|
+
next(ctx);
|
|
56527
|
+
},
|
|
56528
|
+
afterNetwork(ctx, { resolve: resolve2 }) {
|
|
56529
|
+
ctx.cacheParams?.layer?.clear();
|
|
56530
|
+
resolve2(ctx);
|
|
56531
|
+
},
|
|
56532
|
+
end(ctx, { resolve: resolve2, value }) {
|
|
56533
|
+
const hasErrors = value.errors && value.errors.length > 0;
|
|
56534
|
+
if (hasErrors) {
|
|
56535
|
+
ctx.cacheParams?.layer?.clear();
|
|
56536
|
+
}
|
|
56537
|
+
if (ctx.cacheParams?.layer) {
|
|
56538
|
+
cache_default._internal_unstable.storage.resolveLayer(ctx.cacheParams.layer.id);
|
|
56539
|
+
}
|
|
56540
|
+
resolve2(ctx);
|
|
56541
|
+
},
|
|
56542
|
+
catch(ctx, { error }) {
|
|
56543
|
+
if (ctx.cacheParams?.layer) {
|
|
56544
|
+
const { layer } = ctx.cacheParams;
|
|
56545
|
+
layer.clear();
|
|
56546
|
+
cache_default._internal_unstable.storage.resolveLayer(layer.id);
|
|
56547
|
+
}
|
|
56548
|
+
throw error;
|
|
56549
|
+
}
|
|
56550
|
+
};
|
|
56551
|
+
});
|
|
56552
|
+
|
|
54432
56553
|
// src/lib/types.ts
|
|
54433
56554
|
var LogLevel = {
|
|
54434
56555
|
Full: "full",
|
|
@@ -54865,8 +56986,10 @@ var Config = class {
|
|
|
54865
56986
|
return node.name.value === "CachePolicy";
|
|
54866
56987
|
}
|
|
54867
56988
|
isInternalDirective(name) {
|
|
54868
|
-
const internalDirectives = this.#newSchemaInstance?.getDirectives().
|
|
54869
|
-
|
|
56989
|
+
const internalDirectives = this.#newSchemaInstance?.getDirectives().reduce((list, directive) => {
|
|
56990
|
+
return list.concat(directive.name);
|
|
56991
|
+
}, []) ?? [];
|
|
56992
|
+
return !defaultDirectives.includes(name) && (internalDirectives.includes(name) || this.isDeleteDirective(name));
|
|
54870
56993
|
}
|
|
54871
56994
|
isListFragment(name) {
|
|
54872
56995
|
return name.endsWith(this.insertFragmentSuffix) || name.endsWith(this.removeFragmentSuffix) || name.endsWith(this.toggleFragmentSuffix);
|
|
@@ -54939,6 +57062,8 @@ function findModule(pkg = "houdini", currentLocation) {
|
|
|
54939
57062
|
}
|
|
54940
57063
|
return locationFound;
|
|
54941
57064
|
}
|
|
57065
|
+
var emptySchema = graphql.buildSchema("type Query { hello: String }");
|
|
57066
|
+
var defaultDirectives = emptySchema.getDirectives().map((dir) => dir.name);
|
|
54942
57067
|
|
|
54943
57068
|
// src/lib/graphql.ts
|
|
54944
57069
|
var graphql2 = __toESM(require_graphql2(), 1);
|
|
@@ -57394,22 +59519,12 @@ function artifactGenerator(stats) {
|
|
|
57394
59519
|
document: doc
|
|
57395
59520
|
})
|
|
57396
59521
|
};
|
|
57397
|
-
|
|
57398
|
-
|
|
57399
|
-
|
|
57400
|
-
|
|
57401
|
-
|
|
57402
|
-
|
|
57403
|
-
const dataToAdd = plugin2.artifactData({ config: config2, document: doc }) ?? {};
|
|
57404
|
-
if (Object.keys(dataToAdd)) {
|
|
57405
|
-
result[plugin2.name] = dataToAdd;
|
|
57406
|
-
}
|
|
57407
|
-
return result;
|
|
57408
|
-
},
|
|
57409
|
-
{}
|
|
57410
|
-
);
|
|
57411
|
-
if (Object.keys(plugin_data).length > 0) {
|
|
57412
|
-
artifact.pluginData = plugin_data;
|
|
59522
|
+
artifact.pluginData = {};
|
|
59523
|
+
for (const plugin2 of config2.plugins) {
|
|
59524
|
+
if (!plugin2.artifactData) {
|
|
59525
|
+
continue;
|
|
59526
|
+
}
|
|
59527
|
+
artifact.pluginData[plugin2.name] = plugin2.artifactData({ config: config2, document: doc }) ?? {};
|
|
57413
59528
|
}
|
|
57414
59529
|
if (inputs && inputs.length > 0) {
|
|
57415
59530
|
artifact.input = inputObject(config2, inputs);
|
|
@@ -57583,6 +59698,30 @@ async function generatePluginIndex({
|
|
|
57583
59698
|
]);
|
|
57584
59699
|
}
|
|
57585
59700
|
|
|
59701
|
+
// src/codegen/generators/runtime/runtimeConfig.ts
|
|
59702
|
+
async function injectConfig({
|
|
59703
|
+
config: config2,
|
|
59704
|
+
content,
|
|
59705
|
+
importStatement,
|
|
59706
|
+
exportStatement
|
|
59707
|
+
}) {
|
|
59708
|
+
const extraConfigs = config2.plugins.reduce((acc, plugin2) => {
|
|
59709
|
+
if (!plugin2.config) {
|
|
59710
|
+
return acc;
|
|
59711
|
+
}
|
|
59712
|
+
return [...acc, plugin2.config];
|
|
59713
|
+
}, []);
|
|
59714
|
+
return extraConfigs.length > 0 ? `
|
|
59715
|
+
${extraConfigs.map((plugin2, i) => importStatement(plugin2, `plugin${i}`))}
|
|
59716
|
+
|
|
59717
|
+
const plugins = [
|
|
59718
|
+
${extraConfigs.map((_, i) => `plugin${i}`).join(",\n")}
|
|
59719
|
+
]
|
|
59720
|
+
|
|
59721
|
+
${exportStatement("plugins")}
|
|
59722
|
+
` : content;
|
|
59723
|
+
}
|
|
59724
|
+
|
|
57586
59725
|
// src/codegen/generators/runtime/index.ts
|
|
57587
59726
|
async function runtimeGenerator(config2, docs) {
|
|
57588
59727
|
const importStatement = config2.module === "commonjs" ? importDefaultFrom : (where, as) => `import ${as} from '${where}'`;
|
|
@@ -57593,6 +59732,9 @@ async function runtimeGenerator(config2, docs) {
|
|
|
57593
59732
|
[path_exports.join(config2.runtimeSource, "lib", "constants.js")]: (content) => {
|
|
57594
59733
|
return content.replace("SITE_URL", siteURL);
|
|
57595
59734
|
},
|
|
59735
|
+
[path_exports.join(config2.runtimeSource, "imports", "pluginConfig.js")]: (content) => {
|
|
59736
|
+
return injectConfig({ config: config2, importStatement, exportStatement, content });
|
|
59737
|
+
},
|
|
57596
59738
|
[path_exports.join(config2.runtimeSource, "imports", "config.js")]: (content) => {
|
|
57597
59739
|
const configFilePath = path_exports.join(config2.runtimeDirectory, "imports", "config.js");
|
|
57598
59740
|
const relativePath = path_exports.relative(path_exports.dirname(configFilePath), config2.filepath);
|
|
@@ -58820,13 +60962,19 @@ async function definitionsGenerator(config2) {
|
|
|
58820
60962
|
})
|
|
58821
60963
|
)
|
|
58822
60964
|
).code;
|
|
58823
|
-
const typeDefinitions2 =
|
|
58824
|
-
|
|
58825
|
-
|
|
58826
|
-
|
|
58827
|
-
|
|
58828
|
-
`
|
|
58829
|
-
|
|
60965
|
+
const typeDefinitions2 = `
|
|
60966
|
+
type ValuesOf<T> = T[keyof T]
|
|
60967
|
+
` + enums.sort((a, b) => a.name.value.localeCompare(b.name.value)).map((definition) => {
|
|
60968
|
+
const name = definition.name.value;
|
|
60969
|
+
const values = definition.values;
|
|
60970
|
+
return `
|
|
60971
|
+
export declare const ${name}: {
|
|
60972
|
+
${values?.map((value) => ` readonly ${value.name.value}: "${value.name.value}";`).join("\n")}
|
|
60973
|
+
}
|
|
60974
|
+
|
|
60975
|
+
export type ${name}$options = ValuesOf<typeof ${name}>
|
|
60976
|
+
`;
|
|
60977
|
+
}).join("");
|
|
58830
60978
|
const definitionsIndex = `
|
|
58831
60979
|
export * from './enums.js'
|
|
58832
60980
|
`;
|
|
@@ -60319,8 +62467,8 @@ function pipelineTest(config2, documents, shouldPass, testBody) {
|
|
|
60319
62467
|
}
|
|
60320
62468
|
};
|
|
60321
62469
|
}
|
|
60322
|
-
function mockCollectedDoc(
|
|
60323
|
-
const parsed = graphql25.parse(
|
|
62470
|
+
function mockCollectedDoc(query2) {
|
|
62471
|
+
const parsed = graphql25.parse(query2);
|
|
60324
62472
|
const name = parsed.definitions[0].name.value;
|
|
60325
62473
|
const operations = parsed.definitions;
|
|
60326
62474
|
let kind = ArtifactKind.Fragment;
|
|
@@ -60341,7 +62489,7 @@ function mockCollectedDoc(query) {
|
|
|
60341
62489
|
filename: `${name}.ts`,
|
|
60342
62490
|
generateArtifact: true,
|
|
60343
62491
|
generateStore: true,
|
|
60344
|
-
originalString:
|
|
62492
|
+
originalString: query2,
|
|
60345
62493
|
artifact: null
|
|
60346
62494
|
};
|
|
60347
62495
|
}
|