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/vite-cjs/index.js
CHANGED
|
@@ -24050,42 +24050,42 @@ var require_node = __commonJS({
|
|
|
24050
24050
|
return Link2;
|
|
24051
24051
|
}(events_1.EventEmitter);
|
|
24052
24052
|
exports.Link = Link;
|
|
24053
|
-
var
|
|
24054
|
-
function
|
|
24053
|
+
var File4 = function() {
|
|
24054
|
+
function File5(link, node, flags, fd) {
|
|
24055
24055
|
this.position = 0;
|
|
24056
24056
|
this.link = link;
|
|
24057
24057
|
this.node = node;
|
|
24058
24058
|
this.flags = flags;
|
|
24059
24059
|
this.fd = fd;
|
|
24060
24060
|
}
|
|
24061
|
-
|
|
24061
|
+
File5.prototype.getString = function(encoding) {
|
|
24062
24062
|
if (encoding === void 0) {
|
|
24063
24063
|
encoding = "utf8";
|
|
24064
24064
|
}
|
|
24065
24065
|
return this.node.getString();
|
|
24066
24066
|
};
|
|
24067
|
-
|
|
24067
|
+
File5.prototype.setString = function(str) {
|
|
24068
24068
|
this.node.setString(str);
|
|
24069
24069
|
};
|
|
24070
|
-
|
|
24070
|
+
File5.prototype.getBuffer = function() {
|
|
24071
24071
|
return this.node.getBuffer();
|
|
24072
24072
|
};
|
|
24073
|
-
|
|
24073
|
+
File5.prototype.setBuffer = function(buf) {
|
|
24074
24074
|
this.node.setBuffer(buf);
|
|
24075
24075
|
};
|
|
24076
|
-
|
|
24076
|
+
File5.prototype.getSize = function() {
|
|
24077
24077
|
return this.node.getSize();
|
|
24078
24078
|
};
|
|
24079
|
-
|
|
24079
|
+
File5.prototype.truncate = function(len) {
|
|
24080
24080
|
this.node.truncate(len);
|
|
24081
24081
|
};
|
|
24082
|
-
|
|
24082
|
+
File5.prototype.seekTo = function(position) {
|
|
24083
24083
|
this.position = position;
|
|
24084
24084
|
};
|
|
24085
|
-
|
|
24085
|
+
File5.prototype.stats = function() {
|
|
24086
24086
|
return Stats_1.default.build(this.node);
|
|
24087
24087
|
};
|
|
24088
|
-
|
|
24088
|
+
File5.prototype.write = function(buf, offset, length, position) {
|
|
24089
24089
|
if (offset === void 0) {
|
|
24090
24090
|
offset = 0;
|
|
24091
24091
|
}
|
|
@@ -24100,7 +24100,7 @@ var require_node = __commonJS({
|
|
|
24100
24100
|
this.position = position + bytes;
|
|
24101
24101
|
return bytes;
|
|
24102
24102
|
};
|
|
24103
|
-
|
|
24103
|
+
File5.prototype.read = function(buf, offset, length, position) {
|
|
24104
24104
|
if (offset === void 0) {
|
|
24105
24105
|
offset = 0;
|
|
24106
24106
|
}
|
|
@@ -24113,15 +24113,15 @@ var require_node = __commonJS({
|
|
|
24113
24113
|
this.position = position + bytes;
|
|
24114
24114
|
return bytes;
|
|
24115
24115
|
};
|
|
24116
|
-
|
|
24116
|
+
File5.prototype.chmod = function(perm) {
|
|
24117
24117
|
this.node.chmod(perm);
|
|
24118
24118
|
};
|
|
24119
|
-
|
|
24119
|
+
File5.prototype.chown = function(uid, gid) {
|
|
24120
24120
|
this.node.chown(uid, gid);
|
|
24121
24121
|
};
|
|
24122
|
-
return
|
|
24122
|
+
return File5;
|
|
24123
24123
|
}();
|
|
24124
|
-
exports.File =
|
|
24124
|
+
exports.File = File4;
|
|
24125
24125
|
}
|
|
24126
24126
|
});
|
|
24127
24127
|
|
|
@@ -24807,20 +24807,20 @@ var require_volume = __commonJS({
|
|
|
24807
24807
|
}
|
|
24808
24808
|
function flattenJSON(nestedJSON) {
|
|
24809
24809
|
var flatJSON = {};
|
|
24810
|
-
function
|
|
24810
|
+
function flatten2(pathPrefix, node) {
|
|
24811
24811
|
for (var path2 in node) {
|
|
24812
24812
|
var contentOrNode = node[path2];
|
|
24813
24813
|
var joinedPath = join3(pathPrefix, path2);
|
|
24814
24814
|
if (typeof contentOrNode === "string") {
|
|
24815
24815
|
flatJSON[joinedPath] = contentOrNode;
|
|
24816
24816
|
} else if (typeof contentOrNode === "object" && contentOrNode !== null && Object.keys(contentOrNode).length > 0) {
|
|
24817
|
-
|
|
24817
|
+
flatten2(joinedPath, contentOrNode);
|
|
24818
24818
|
} else {
|
|
24819
24819
|
flatJSON[joinedPath] = null;
|
|
24820
24820
|
}
|
|
24821
24821
|
}
|
|
24822
24822
|
}
|
|
24823
|
-
|
|
24823
|
+
flatten2("", nestedJSON);
|
|
24824
24824
|
return flatJSON;
|
|
24825
24825
|
}
|
|
24826
24826
|
var Volume = function() {
|
|
@@ -30230,9 +30230,9 @@ var require_streams = __commonJS({
|
|
|
30230
30230
|
}
|
|
30231
30231
|
}
|
|
30232
30232
|
try {
|
|
30233
|
-
const { Blob:
|
|
30234
|
-
if (
|
|
30235
|
-
|
|
30233
|
+
const { Blob: Blob4 } = require("buffer");
|
|
30234
|
+
if (Blob4 && !Blob4.prototype.stream) {
|
|
30235
|
+
Blob4.prototype.stream = function name(params) {
|
|
30236
30236
|
let position = 0;
|
|
30237
30237
|
const blob = this;
|
|
30238
30238
|
return new ReadableStream({
|
|
@@ -30283,12 +30283,12 @@ async function* toIterator(parts, clone2 = true) {
|
|
|
30283
30283
|
}
|
|
30284
30284
|
}
|
|
30285
30285
|
}
|
|
30286
|
-
var import_streams, POOL_SIZE, _Blob,
|
|
30286
|
+
var import_streams, POOL_SIZE, _Blob, Blob3, fetch_blob_default;
|
|
30287
30287
|
var init_fetch_blob = __esm({
|
|
30288
30288
|
"../../node_modules/.pnpm/fetch-blob@3.2.0/node_modules/fetch-blob/index.js"() {
|
|
30289
30289
|
import_streams = __toESM(require_streams(), 1);
|
|
30290
30290
|
POOL_SIZE = 65536;
|
|
30291
|
-
_Blob = class
|
|
30291
|
+
_Blob = class Blob2 {
|
|
30292
30292
|
#parts = [];
|
|
30293
30293
|
#type = "";
|
|
30294
30294
|
#size = 0;
|
|
@@ -30312,7 +30312,7 @@ var init_fetch_blob = __esm({
|
|
|
30312
30312
|
part = new Uint8Array(element.buffer.slice(element.byteOffset, element.byteOffset + element.byteLength));
|
|
30313
30313
|
} else if (element instanceof ArrayBuffer) {
|
|
30314
30314
|
part = new Uint8Array(element.slice(0));
|
|
30315
|
-
} else if (element instanceof
|
|
30315
|
+
} else if (element instanceof Blob2) {
|
|
30316
30316
|
part = element;
|
|
30317
30317
|
} else {
|
|
30318
30318
|
part = encoder.encode(`${element}`);
|
|
@@ -30391,7 +30391,7 @@ var init_fetch_blob = __esm({
|
|
|
30391
30391
|
relativeStart = 0;
|
|
30392
30392
|
}
|
|
30393
30393
|
}
|
|
30394
|
-
const blob = new
|
|
30394
|
+
const blob = new Blob2([], { type: String(type).toLowerCase() });
|
|
30395
30395
|
blob.#size = span;
|
|
30396
30396
|
blob.#parts = blobParts;
|
|
30397
30397
|
return blob;
|
|
@@ -30408,17 +30408,17 @@ var init_fetch_blob = __esm({
|
|
|
30408
30408
|
type: { enumerable: true },
|
|
30409
30409
|
slice: { enumerable: true }
|
|
30410
30410
|
});
|
|
30411
|
-
|
|
30412
|
-
fetch_blob_default =
|
|
30411
|
+
Blob3 = _Blob;
|
|
30412
|
+
fetch_blob_default = Blob3;
|
|
30413
30413
|
}
|
|
30414
30414
|
});
|
|
30415
30415
|
|
|
30416
30416
|
// ../../node_modules/.pnpm/fetch-blob@3.2.0/node_modules/fetch-blob/file.js
|
|
30417
|
-
var _File,
|
|
30417
|
+
var _File, File3, file_default;
|
|
30418
30418
|
var init_file = __esm({
|
|
30419
30419
|
"../../node_modules/.pnpm/fetch-blob@3.2.0/node_modules/fetch-blob/file.js"() {
|
|
30420
30420
|
init_fetch_blob();
|
|
30421
|
-
_File = class
|
|
30421
|
+
_File = class File2 extends fetch_blob_default {
|
|
30422
30422
|
#lastModified = 0;
|
|
30423
30423
|
#name = "";
|
|
30424
30424
|
constructor(fileBits, fileName, options = {}) {
|
|
@@ -30447,8 +30447,8 @@ var init_file = __esm({
|
|
|
30447
30447
|
return !!object && object instanceof fetch_blob_default && /^(File)$/.test(object[Symbol.toStringTag]);
|
|
30448
30448
|
}
|
|
30449
30449
|
};
|
|
30450
|
-
|
|
30451
|
-
file_default =
|
|
30450
|
+
File3 = _File;
|
|
30451
|
+
file_default = File3;
|
|
30452
30452
|
}
|
|
30453
30453
|
});
|
|
30454
30454
|
|
|
@@ -30466,7 +30466,7 @@ Content-Type: ${v.type || "application/octet-stream"}\r
|
|
|
30466
30466
|
c.push(`--${b}--`);
|
|
30467
30467
|
return new B(c, { type: "multipart/form-data; boundary=" + b });
|
|
30468
30468
|
}
|
|
30469
|
-
var t, i, h, r, m, f, e, x,
|
|
30469
|
+
var t, i, h, r, m, f, e, x, FormData2;
|
|
30470
30470
|
var init_esm_min = __esm({
|
|
30471
30471
|
"../../node_modules/.pnpm/formdata-polyfill@4.0.10/node_modules/formdata-polyfill/esm.min.js"() {
|
|
30472
30472
|
init_fetch_blob();
|
|
@@ -30481,7 +30481,7 @@ var init_esm_min = __esm({
|
|
|
30481
30481
|
throw new TypeError(`Failed to execute '${n}' on 'FormData': ${e2} arguments required, but only ${a.length} present.`);
|
|
30482
30482
|
}
|
|
30483
30483
|
};
|
|
30484
|
-
|
|
30484
|
+
FormData2 = class FormData3 {
|
|
30485
30485
|
#d = [];
|
|
30486
30486
|
constructor(...a) {
|
|
30487
30487
|
if (a.length)
|
|
@@ -30647,7 +30647,7 @@ async function toFormData(Body2, ct) {
|
|
|
30647
30647
|
let contentType;
|
|
30648
30648
|
let filename;
|
|
30649
30649
|
const entryChunks = [];
|
|
30650
|
-
const formData = new
|
|
30650
|
+
const formData = new FormData2();
|
|
30651
30651
|
const onPartData = (ui8a) => {
|
|
30652
30652
|
entryValue += decoder.decode(ui8a, { stream: true });
|
|
30653
30653
|
};
|
|
@@ -65187,7 +65187,18 @@ var graphql2 = __toESM(require_graphql2(), 1);
|
|
|
65187
65187
|
var import_minimatch = __toESM(require_minimatch(), 1);
|
|
65188
65188
|
var import_node_url2 = require("node:url");
|
|
65189
65189
|
|
|
65190
|
+
// src/runtime/imports/config.ts
|
|
65191
|
+
var config_default = {};
|
|
65192
|
+
|
|
65193
|
+
// src/runtime/imports/pluginConfig.ts
|
|
65194
|
+
var configs = [];
|
|
65195
|
+
var pluginConfig_default = configs;
|
|
65196
|
+
|
|
65190
65197
|
// src/runtime/lib/config.ts
|
|
65198
|
+
var mockConfig = null;
|
|
65199
|
+
function getMockConfig() {
|
|
65200
|
+
return mockConfig;
|
|
65201
|
+
}
|
|
65191
65202
|
function defaultConfigValues(file) {
|
|
65192
65203
|
return {
|
|
65193
65204
|
defaultKeys: ["id"],
|
|
@@ -65215,6 +65226,106 @@ function computeID(configFile, type, data) {
|
|
|
65215
65226
|
}
|
|
65216
65227
|
return id.slice(0, -2);
|
|
65217
65228
|
}
|
|
65229
|
+
var _configFile = null;
|
|
65230
|
+
function getCurrentConfig() {
|
|
65231
|
+
const mockConfig2 = getMockConfig();
|
|
65232
|
+
if (mockConfig2) {
|
|
65233
|
+
return mockConfig2;
|
|
65234
|
+
}
|
|
65235
|
+
if (_configFile) {
|
|
65236
|
+
return _configFile;
|
|
65237
|
+
}
|
|
65238
|
+
let configFile = defaultConfigValues(config_default);
|
|
65239
|
+
for (const pluginConfig of pluginConfig_default) {
|
|
65240
|
+
configFile = pluginConfig(configFile);
|
|
65241
|
+
}
|
|
65242
|
+
_configFile = configFile;
|
|
65243
|
+
return configFile;
|
|
65244
|
+
}
|
|
65245
|
+
|
|
65246
|
+
// src/runtime/lib/deepEquals.ts
|
|
65247
|
+
function deepEquals(objA, objB, map = /* @__PURE__ */ new WeakMap()) {
|
|
65248
|
+
if (Object.is(objA, objB))
|
|
65249
|
+
return true;
|
|
65250
|
+
if (objA instanceof Date && objB instanceof Date) {
|
|
65251
|
+
return objA.getTime() === objB.getTime();
|
|
65252
|
+
}
|
|
65253
|
+
if (objA instanceof RegExp && objB instanceof RegExp) {
|
|
65254
|
+
return objA.toString() === objB.toString();
|
|
65255
|
+
}
|
|
65256
|
+
if (typeof objA !== "object" || objA === null || typeof objB !== "object" || objB === null) {
|
|
65257
|
+
return false;
|
|
65258
|
+
}
|
|
65259
|
+
if (map.get(objA) === objB)
|
|
65260
|
+
return true;
|
|
65261
|
+
map.set(objA, objB);
|
|
65262
|
+
const keysA = Reflect.ownKeys(objA);
|
|
65263
|
+
const keysB = Reflect.ownKeys(objB);
|
|
65264
|
+
if (keysA.length !== keysB.length) {
|
|
65265
|
+
return false;
|
|
65266
|
+
}
|
|
65267
|
+
for (let i2 = 0; i2 < keysA.length; i2++) {
|
|
65268
|
+
if (!Reflect.has(objB, keysA[i2]) || !deepEquals(objA[keysA[i2]], objB[keysA[i2]], map)) {
|
|
65269
|
+
return false;
|
|
65270
|
+
}
|
|
65271
|
+
}
|
|
65272
|
+
return true;
|
|
65273
|
+
}
|
|
65274
|
+
|
|
65275
|
+
// src/runtime/lib/selection.ts
|
|
65276
|
+
function getFieldsForType(selection2, __typename) {
|
|
65277
|
+
let targetSelection = selection2.fields || {};
|
|
65278
|
+
if (selection2.abstractFields && __typename) {
|
|
65279
|
+
const mappedType = selection2.abstractFields.typeMap[__typename];
|
|
65280
|
+
if (mappedType) {
|
|
65281
|
+
targetSelection = selection2.abstractFields.fields[mappedType];
|
|
65282
|
+
} else if (selection2.abstractFields.fields[__typename]) {
|
|
65283
|
+
targetSelection = selection2.abstractFields.fields[__typename];
|
|
65284
|
+
}
|
|
65285
|
+
}
|
|
65286
|
+
return targetSelection;
|
|
65287
|
+
}
|
|
65288
|
+
|
|
65289
|
+
// src/runtime/lib/scalars.ts
|
|
65290
|
+
async function marshalSelection({
|
|
65291
|
+
selection: selection2,
|
|
65292
|
+
data
|
|
65293
|
+
}) {
|
|
65294
|
+
const config4 = getCurrentConfig();
|
|
65295
|
+
if (data === null || typeof data === "undefined") {
|
|
65296
|
+
return data;
|
|
65297
|
+
}
|
|
65298
|
+
if (Array.isArray(data)) {
|
|
65299
|
+
return await Promise.all(data.map((val) => marshalSelection({ selection: selection2, data: val })));
|
|
65300
|
+
}
|
|
65301
|
+
const targetSelection = getFieldsForType(selection2, data["__typename"]);
|
|
65302
|
+
return Object.fromEntries(
|
|
65303
|
+
await Promise.all(
|
|
65304
|
+
Object.entries(data).map(async ([fieldName, value]) => {
|
|
65305
|
+
const { type, selection: selection3 } = targetSelection[fieldName];
|
|
65306
|
+
if (!type) {
|
|
65307
|
+
return [fieldName, value];
|
|
65308
|
+
}
|
|
65309
|
+
if (selection3) {
|
|
65310
|
+
return [fieldName, await marshalSelection({ selection: selection3, data: value })];
|
|
65311
|
+
}
|
|
65312
|
+
if (config4.scalars?.[type]) {
|
|
65313
|
+
const marshalFn = config4.scalars[type].marshal;
|
|
65314
|
+
if (!marshalFn) {
|
|
65315
|
+
throw new Error(
|
|
65316
|
+
`scalar type ${type} is missing a \`marshal\` function. see https://github.com/AlecAivazis/houdini#%EF%B8%8Fcustom-scalars`
|
|
65317
|
+
);
|
|
65318
|
+
}
|
|
65319
|
+
if (Array.isArray(value)) {
|
|
65320
|
+
return [fieldName, value.map(marshalFn)];
|
|
65321
|
+
}
|
|
65322
|
+
return [fieldName, marshalFn(value)];
|
|
65323
|
+
}
|
|
65324
|
+
return [fieldName, value];
|
|
65325
|
+
})
|
|
65326
|
+
)
|
|
65327
|
+
);
|
|
65328
|
+
}
|
|
65218
65329
|
|
|
65219
65330
|
// src/runtime/lib/types.ts
|
|
65220
65331
|
var CachePolicy = {
|
|
@@ -65238,6 +65349,27 @@ var RefetchUpdateMode = {
|
|
|
65238
65349
|
prepend: "prepend",
|
|
65239
65350
|
replace: "replace"
|
|
65240
65351
|
};
|
|
65352
|
+
var DataSource = {
|
|
65353
|
+
Cache: "cache",
|
|
65354
|
+
Network: "network",
|
|
65355
|
+
Ssr: "ssr"
|
|
65356
|
+
};
|
|
65357
|
+
|
|
65358
|
+
// src/runtime/lib/key.ts
|
|
65359
|
+
var computeKey = ({ field, args }) => {
|
|
65360
|
+
const keys = Object.keys(args ?? {});
|
|
65361
|
+
keys.sort();
|
|
65362
|
+
return args && keys.length > 0 ? `${field}(${keys.map((key) => `${key}: ${stringifyObjectWithNoQuotesOnKeys(args[key])}`).join(", ")})` : field;
|
|
65363
|
+
};
|
|
65364
|
+
var stringifyObjectWithNoQuotesOnKeys = (obj_from_json) => {
|
|
65365
|
+
if (Array.isArray(obj_from_json)) {
|
|
65366
|
+
return `[${obj_from_json.map((obj) => `${stringifyObjectWithNoQuotesOnKeys(obj)}`).join(", ")}]`;
|
|
65367
|
+
}
|
|
65368
|
+
if (typeof obj_from_json !== "object" || obj_from_json instanceof Date || obj_from_json === null) {
|
|
65369
|
+
return JSON.stringify(obj_from_json).replace(/"([^"]+)":/g, "$1: ");
|
|
65370
|
+
}
|
|
65371
|
+
return `{${Object.keys(obj_from_json).map((key) => `${key}: ${stringifyObjectWithNoQuotesOnKeys(obj_from_json[key])}`).join(", ")}}`;
|
|
65372
|
+
};
|
|
65241
65373
|
|
|
65242
65374
|
// src/lib/constants.ts
|
|
65243
65375
|
var siteURL = "https://houdinigraphql.com";
|
|
@@ -65683,7 +65815,7 @@ var Body = class {
|
|
|
65683
65815
|
} else if (ArrayBuffer.isView(body)) {
|
|
65684
65816
|
body = import_node_buffer.Buffer.from(body.buffer, body.byteOffset, body.byteLength);
|
|
65685
65817
|
} else if (body instanceof import_node_stream.default) {
|
|
65686
|
-
} else if (body instanceof
|
|
65818
|
+
} else if (body instanceof FormData2) {
|
|
65687
65819
|
body = formDataToBlob(body);
|
|
65688
65820
|
boundary = body.type.split("=")[1];
|
|
65689
65821
|
} else {
|
|
@@ -65723,7 +65855,7 @@ var Body = class {
|
|
|
65723
65855
|
async formData() {
|
|
65724
65856
|
const ct = this.headers.get("content-type");
|
|
65725
65857
|
if (ct.startsWith("application/x-www-form-urlencoded")) {
|
|
65726
|
-
const formData = new
|
|
65858
|
+
const formData = new FormData2();
|
|
65727
65859
|
const parameters = new URLSearchParams(await this.text());
|
|
65728
65860
|
for (const [name, value] of parameters) {
|
|
65729
65861
|
formData.append(name, value);
|
|
@@ -65849,7 +65981,7 @@ var extractContentType = (body, request) => {
|
|
|
65849
65981
|
if (import_node_buffer.Buffer.isBuffer(body) || import_node_util2.types.isAnyArrayBuffer(body) || ArrayBuffer.isView(body)) {
|
|
65850
65982
|
return null;
|
|
65851
65983
|
}
|
|
65852
|
-
if (body instanceof
|
|
65984
|
+
if (body instanceof FormData2) {
|
|
65853
65985
|
return `multipart/form-data; boundary=${request[INTERNALS].boundary}`;
|
|
65854
65986
|
}
|
|
65855
65987
|
if (body && typeof body.getBoundary === "function") {
|
|
@@ -66816,6 +66948,1995 @@ function plugin(name, hooks) {
|
|
|
66816
66948
|
return data;
|
|
66817
66949
|
}
|
|
66818
66950
|
|
|
66951
|
+
// src/runtime/lib/flatten.ts
|
|
66952
|
+
function flatten(source) {
|
|
66953
|
+
if (!source) {
|
|
66954
|
+
return [];
|
|
66955
|
+
}
|
|
66956
|
+
return source.reduce((acc, element) => {
|
|
66957
|
+
if (!element) {
|
|
66958
|
+
return acc;
|
|
66959
|
+
}
|
|
66960
|
+
if (Array.isArray(element)) {
|
|
66961
|
+
return acc.concat(flatten(element));
|
|
66962
|
+
}
|
|
66963
|
+
return acc.concat(element);
|
|
66964
|
+
}, []);
|
|
66965
|
+
}
|
|
66966
|
+
|
|
66967
|
+
// src/runtime/cache/gc.ts
|
|
66968
|
+
var GarbageCollector = class {
|
|
66969
|
+
cache;
|
|
66970
|
+
lifetimes = /* @__PURE__ */ new Map();
|
|
66971
|
+
get cacheBufferSize() {
|
|
66972
|
+
return this.cache._internal_unstable.config.cacheBufferSize ?? 10;
|
|
66973
|
+
}
|
|
66974
|
+
constructor(cache) {
|
|
66975
|
+
this.cache = cache;
|
|
66976
|
+
}
|
|
66977
|
+
resetLifetime(id, field) {
|
|
66978
|
+
if (!this.lifetimes.get(id)) {
|
|
66979
|
+
this.lifetimes.set(id, /* @__PURE__ */ new Map());
|
|
66980
|
+
}
|
|
66981
|
+
this.lifetimes.get(id).set(field, 0);
|
|
66982
|
+
}
|
|
66983
|
+
tick() {
|
|
66984
|
+
const dt_tick = Date.now().valueOf();
|
|
66985
|
+
const config_max_time = this.cache._internal_unstable.config.defaultLifetime;
|
|
66986
|
+
for (const [id, fieldMap] of this.lifetimes.entries()) {
|
|
66987
|
+
for (const [field, lifetime] of fieldMap.entries()) {
|
|
66988
|
+
if (this.cache._internal_unstable.subscriptions.get(id, field).length > 0) {
|
|
66989
|
+
continue;
|
|
66990
|
+
}
|
|
66991
|
+
fieldMap.set(field, lifetime + 1);
|
|
66992
|
+
if (fieldMap.get(field) > this.cacheBufferSize) {
|
|
66993
|
+
this.cache._internal_unstable.storage.deleteField(id, field);
|
|
66994
|
+
this.cache._internal_unstable.lists.deleteField(id, field);
|
|
66995
|
+
fieldMap.delete(field);
|
|
66996
|
+
if ([...fieldMap.keys()].length === 0) {
|
|
66997
|
+
this.lifetimes.delete(id);
|
|
66998
|
+
}
|
|
66999
|
+
this.cache._internal_unstable.staleManager.delete(id, field);
|
|
67000
|
+
}
|
|
67001
|
+
if (config_max_time && config_max_time > 0) {
|
|
67002
|
+
const dt_valueOf = this.cache.getFieldTime(id, field);
|
|
67003
|
+
if (dt_valueOf && dt_tick - dt_valueOf > config_max_time) {
|
|
67004
|
+
this.cache._internal_unstable.staleManager.markFieldStale(id, field);
|
|
67005
|
+
}
|
|
67006
|
+
}
|
|
67007
|
+
}
|
|
67008
|
+
}
|
|
67009
|
+
}
|
|
67010
|
+
};
|
|
67011
|
+
|
|
67012
|
+
// src/runtime/cache/lists.ts
|
|
67013
|
+
var ListManager = class {
|
|
67014
|
+
rootID;
|
|
67015
|
+
cache;
|
|
67016
|
+
constructor(cache, rootID2) {
|
|
67017
|
+
this.rootID = rootID2;
|
|
67018
|
+
this.cache = cache;
|
|
67019
|
+
}
|
|
67020
|
+
lists = /* @__PURE__ */ new Map();
|
|
67021
|
+
listsByField = /* @__PURE__ */ new Map();
|
|
67022
|
+
get(listName, id, allLists) {
|
|
67023
|
+
const matches = this.lists.get(listName);
|
|
67024
|
+
if (!matches || matches.size === 0) {
|
|
67025
|
+
return null;
|
|
67026
|
+
}
|
|
67027
|
+
if (allLists) {
|
|
67028
|
+
return new ListCollection(
|
|
67029
|
+
Array.from(matches, ([key, value]) => [...value.lists]).flat()
|
|
67030
|
+
);
|
|
67031
|
+
}
|
|
67032
|
+
const head = [...matches.values()][0];
|
|
67033
|
+
const { recordType } = head.lists[0];
|
|
67034
|
+
const parentID = id ? this.cache._internal_unstable.id(recordType || "", id) : this.rootID;
|
|
67035
|
+
if (matches?.size === 1) {
|
|
67036
|
+
if (!id) {
|
|
67037
|
+
return head;
|
|
67038
|
+
}
|
|
67039
|
+
return parentID === Array.from(matches.keys())[0] ? head : null;
|
|
67040
|
+
}
|
|
67041
|
+
if (!id) {
|
|
67042
|
+
console.error(
|
|
67043
|
+
`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 `
|
|
67044
|
+
);
|
|
67045
|
+
return null;
|
|
67046
|
+
}
|
|
67047
|
+
return this.lists.get(listName)?.get(parentID);
|
|
67048
|
+
}
|
|
67049
|
+
remove(listName, id) {
|
|
67050
|
+
this.lists.get(listName)?.delete(id || this.rootID);
|
|
67051
|
+
}
|
|
67052
|
+
add(list) {
|
|
67053
|
+
if (!this.lists.has(list.name)) {
|
|
67054
|
+
this.lists.set(list.name, /* @__PURE__ */ new Map());
|
|
67055
|
+
}
|
|
67056
|
+
const name = list.name;
|
|
67057
|
+
const parentID = list.recordID || this.rootID;
|
|
67058
|
+
if (this.lists.get(name)?.get(parentID)?.includes(list.key)) {
|
|
67059
|
+
return;
|
|
67060
|
+
}
|
|
67061
|
+
if (!this.lists.has(name)) {
|
|
67062
|
+
this.lists.set(name, /* @__PURE__ */ new Map());
|
|
67063
|
+
}
|
|
67064
|
+
if (!this.lists.get(name).has(parentID)) {
|
|
67065
|
+
this.lists.get(name).set(parentID, new ListCollection([]));
|
|
67066
|
+
}
|
|
67067
|
+
if (!this.listsByField.has(parentID)) {
|
|
67068
|
+
this.listsByField.set(parentID, /* @__PURE__ */ new Map());
|
|
67069
|
+
}
|
|
67070
|
+
if (!this.listsByField.get(parentID).has(list.key)) {
|
|
67071
|
+
this.listsByField.get(parentID)?.set(list.key, []);
|
|
67072
|
+
}
|
|
67073
|
+
const handler = new List({ ...list, manager: this });
|
|
67074
|
+
this.lists.get(list.name).get(parentID).lists.push(handler);
|
|
67075
|
+
this.listsByField.get(parentID).get(list.key).push(handler);
|
|
67076
|
+
}
|
|
67077
|
+
removeIDFromAllLists(id) {
|
|
67078
|
+
for (const fieldMap of this.lists.values()) {
|
|
67079
|
+
for (const list of fieldMap.values()) {
|
|
67080
|
+
list.removeID(id);
|
|
67081
|
+
}
|
|
67082
|
+
}
|
|
67083
|
+
}
|
|
67084
|
+
deleteField(parentID, field) {
|
|
67085
|
+
if (!this.listsByField.get(parentID)?.has(field)) {
|
|
67086
|
+
return;
|
|
67087
|
+
}
|
|
67088
|
+
for (const list of this.listsByField.get(parentID).get(field)) {
|
|
67089
|
+
this.lists.get(list.name)?.get(list.recordID)?.deleteListWithKey(field);
|
|
67090
|
+
if (this.lists.get(list.name)?.get(list.recordID)?.lists.length === 0) {
|
|
67091
|
+
this.lists.get(list.name)?.delete(list.recordID);
|
|
67092
|
+
}
|
|
67093
|
+
}
|
|
67094
|
+
this.listsByField.get(parentID).delete(field);
|
|
67095
|
+
}
|
|
67096
|
+
};
|
|
67097
|
+
var List = class {
|
|
67098
|
+
recordID;
|
|
67099
|
+
recordType;
|
|
67100
|
+
key;
|
|
67101
|
+
type;
|
|
67102
|
+
cache;
|
|
67103
|
+
selection;
|
|
67104
|
+
_when;
|
|
67105
|
+
filters;
|
|
67106
|
+
name;
|
|
67107
|
+
connection;
|
|
67108
|
+
manager;
|
|
67109
|
+
abstract;
|
|
67110
|
+
constructor({
|
|
67111
|
+
name,
|
|
67112
|
+
recordID,
|
|
67113
|
+
recordType,
|
|
67114
|
+
key,
|
|
67115
|
+
listType,
|
|
67116
|
+
selection: selection2,
|
|
67117
|
+
when,
|
|
67118
|
+
filters,
|
|
67119
|
+
connection,
|
|
67120
|
+
manager,
|
|
67121
|
+
abstract
|
|
67122
|
+
}) {
|
|
67123
|
+
this.recordID = recordID || rootID;
|
|
67124
|
+
this.recordType = recordType;
|
|
67125
|
+
this.key = key;
|
|
67126
|
+
this.type = listType;
|
|
67127
|
+
this.cache = manager.cache;
|
|
67128
|
+
this.selection = selection2;
|
|
67129
|
+
this._when = when;
|
|
67130
|
+
this.filters = filters;
|
|
67131
|
+
this.name = name;
|
|
67132
|
+
this.connection = connection;
|
|
67133
|
+
this.manager = manager;
|
|
67134
|
+
this.abstract = abstract;
|
|
67135
|
+
}
|
|
67136
|
+
when(when) {
|
|
67137
|
+
return this.manager.lists.get(this.name).get(this.recordID).when(when);
|
|
67138
|
+
}
|
|
67139
|
+
append(selection2, data, variables = {}) {
|
|
67140
|
+
return this.addToList(selection2, data, variables, "last");
|
|
67141
|
+
}
|
|
67142
|
+
prepend(selection2, data, variables = {}) {
|
|
67143
|
+
return this.addToList(selection2, data, variables, "first");
|
|
67144
|
+
}
|
|
67145
|
+
addToList(selection2, data, variables = {}, where) {
|
|
67146
|
+
const listType = this.listType(data);
|
|
67147
|
+
const dataID = this.cache._internal_unstable.id(listType, data);
|
|
67148
|
+
if (!this.validateWhen() || !dataID) {
|
|
67149
|
+
return;
|
|
67150
|
+
}
|
|
67151
|
+
let insertSelection = selection2;
|
|
67152
|
+
let insertData = data;
|
|
67153
|
+
if (this.connection) {
|
|
67154
|
+
insertSelection = {
|
|
67155
|
+
fields: {
|
|
67156
|
+
newEntry: {
|
|
67157
|
+
keyRaw: this.key,
|
|
67158
|
+
type: "Connection",
|
|
67159
|
+
selection: {
|
|
67160
|
+
fields: {
|
|
67161
|
+
edges: {
|
|
67162
|
+
keyRaw: "edges",
|
|
67163
|
+
type: "ConnectionEdge",
|
|
67164
|
+
updates: ["append", "prepend"],
|
|
67165
|
+
selection: {
|
|
67166
|
+
fields: {
|
|
67167
|
+
node: {
|
|
67168
|
+
type: listType,
|
|
67169
|
+
keyRaw: "node",
|
|
67170
|
+
selection: {
|
|
67171
|
+
...selection2,
|
|
67172
|
+
fields: {
|
|
67173
|
+
...selection2.fields,
|
|
67174
|
+
__typename: {
|
|
67175
|
+
keyRaw: "__typename",
|
|
67176
|
+
type: "String"
|
|
67177
|
+
}
|
|
67178
|
+
}
|
|
67179
|
+
}
|
|
67180
|
+
}
|
|
67181
|
+
}
|
|
67182
|
+
}
|
|
67183
|
+
}
|
|
67184
|
+
}
|
|
67185
|
+
}
|
|
67186
|
+
}
|
|
67187
|
+
}
|
|
67188
|
+
};
|
|
67189
|
+
insertData = {
|
|
67190
|
+
newEntry: {
|
|
67191
|
+
edges: [{ node: { ...data, __typename: listType } }]
|
|
67192
|
+
}
|
|
67193
|
+
};
|
|
67194
|
+
} else {
|
|
67195
|
+
insertSelection = {
|
|
67196
|
+
fields: {
|
|
67197
|
+
newEntries: {
|
|
67198
|
+
keyRaw: this.key,
|
|
67199
|
+
type: listType,
|
|
67200
|
+
updates: ["append", "prepend"],
|
|
67201
|
+
selection: {
|
|
67202
|
+
...selection2,
|
|
67203
|
+
fields: {
|
|
67204
|
+
...selection2.fields,
|
|
67205
|
+
__typename: {
|
|
67206
|
+
keyRaw: "__typename",
|
|
67207
|
+
type: "String"
|
|
67208
|
+
}
|
|
67209
|
+
}
|
|
67210
|
+
}
|
|
67211
|
+
}
|
|
67212
|
+
}
|
|
67213
|
+
};
|
|
67214
|
+
insertData = {
|
|
67215
|
+
newEntries: [{ ...data, __typename: listType }]
|
|
67216
|
+
};
|
|
67217
|
+
}
|
|
67218
|
+
this.cache.write({
|
|
67219
|
+
selection: insertSelection,
|
|
67220
|
+
data: insertData,
|
|
67221
|
+
variables,
|
|
67222
|
+
parent: this.recordID,
|
|
67223
|
+
applyUpdates: [where === "first" ? "prepend" : "append"]
|
|
67224
|
+
});
|
|
67225
|
+
}
|
|
67226
|
+
removeID(id, variables = {}) {
|
|
67227
|
+
if (!this.validateWhen()) {
|
|
67228
|
+
return;
|
|
67229
|
+
}
|
|
67230
|
+
let parentID = this.recordID;
|
|
67231
|
+
let targetID = id;
|
|
67232
|
+
let targetKey = this.key;
|
|
67233
|
+
if (this.connection) {
|
|
67234
|
+
const { value: embeddedConnection } = this.cache._internal_unstable.storage.get(
|
|
67235
|
+
this.recordID,
|
|
67236
|
+
this.key
|
|
67237
|
+
);
|
|
67238
|
+
if (!embeddedConnection) {
|
|
67239
|
+
return;
|
|
67240
|
+
}
|
|
67241
|
+
const embeddedConnectionID = embeddedConnection;
|
|
67242
|
+
const { value: edges } = this.cache._internal_unstable.storage.get(
|
|
67243
|
+
embeddedConnectionID,
|
|
67244
|
+
"edges"
|
|
67245
|
+
);
|
|
67246
|
+
for (const edge of flatten(edges) || []) {
|
|
67247
|
+
if (!edge) {
|
|
67248
|
+
continue;
|
|
67249
|
+
}
|
|
67250
|
+
const edgeID = edge;
|
|
67251
|
+
const { value: nodeID } = this.cache._internal_unstable.storage.get(edgeID, "node");
|
|
67252
|
+
if (!nodeID) {
|
|
67253
|
+
continue;
|
|
67254
|
+
}
|
|
67255
|
+
if (nodeID === id) {
|
|
67256
|
+
targetID = edgeID;
|
|
67257
|
+
}
|
|
67258
|
+
}
|
|
67259
|
+
parentID = embeddedConnectionID;
|
|
67260
|
+
targetKey = "edges";
|
|
67261
|
+
}
|
|
67262
|
+
let value = this.cache._internal_unstable.storage.get(parentID, targetKey).value;
|
|
67263
|
+
if (!value || !value.includes(targetID)) {
|
|
67264
|
+
return;
|
|
67265
|
+
}
|
|
67266
|
+
const subscribers = this.cache._internal_unstable.subscriptions.get(this.recordID, this.key);
|
|
67267
|
+
this.cache._internal_unstable.subscriptions.remove(
|
|
67268
|
+
targetID,
|
|
67269
|
+
this.connection ? this.selection.fields.edges.selection : this.selection,
|
|
67270
|
+
subscribers.map((sub) => sub[0]),
|
|
67271
|
+
variables
|
|
67272
|
+
);
|
|
67273
|
+
this.cache._internal_unstable.storage.remove(parentID, targetKey, targetID);
|
|
67274
|
+
for (const [spec] of subscribers) {
|
|
67275
|
+
spec.set(
|
|
67276
|
+
this.cache._internal_unstable.getSelection({
|
|
67277
|
+
parent: spec.parentID || this.manager.rootID,
|
|
67278
|
+
selection: spec.selection,
|
|
67279
|
+
variables: spec.variables?.() || {}
|
|
67280
|
+
}).data
|
|
67281
|
+
);
|
|
67282
|
+
}
|
|
67283
|
+
return true;
|
|
67284
|
+
}
|
|
67285
|
+
remove(data, variables = {}) {
|
|
67286
|
+
const targetID = this.cache._internal_unstable.id(this.listType(data), data);
|
|
67287
|
+
if (!targetID) {
|
|
67288
|
+
return;
|
|
67289
|
+
}
|
|
67290
|
+
return this.removeID(targetID, variables);
|
|
67291
|
+
}
|
|
67292
|
+
listType(data) {
|
|
67293
|
+
return data.__typename || this.type;
|
|
67294
|
+
}
|
|
67295
|
+
validateWhen(when) {
|
|
67296
|
+
let filters = when || this._when;
|
|
67297
|
+
let ok = true;
|
|
67298
|
+
if (filters) {
|
|
67299
|
+
const targets = this.filters;
|
|
67300
|
+
if (filters.must && targets) {
|
|
67301
|
+
ok = Object.entries(filters.must).reduce(
|
|
67302
|
+
(prev, [key, value]) => Boolean(prev && targets[key] == value),
|
|
67303
|
+
ok
|
|
67304
|
+
);
|
|
67305
|
+
}
|
|
67306
|
+
if (filters.must_not) {
|
|
67307
|
+
ok = !targets || Object.entries(filters.must_not).reduce(
|
|
67308
|
+
(prev, [key, value]) => Boolean(prev && targets[key] != value),
|
|
67309
|
+
ok
|
|
67310
|
+
);
|
|
67311
|
+
}
|
|
67312
|
+
}
|
|
67313
|
+
return ok;
|
|
67314
|
+
}
|
|
67315
|
+
toggleElement(selection2, data, variables = {}, where) {
|
|
67316
|
+
if (!this.remove(data, variables)) {
|
|
67317
|
+
this.addToList(selection2, data, variables, where);
|
|
67318
|
+
}
|
|
67319
|
+
}
|
|
67320
|
+
*[Symbol.iterator]() {
|
|
67321
|
+
let entries = [];
|
|
67322
|
+
let value = this.cache._internal_unstable.storage.get(this.recordID, this.key).value;
|
|
67323
|
+
if (!this.connection) {
|
|
67324
|
+
entries = flatten(value);
|
|
67325
|
+
} else {
|
|
67326
|
+
entries = this.cache._internal_unstable.storage.get(value, "edges").value;
|
|
67327
|
+
}
|
|
67328
|
+
for (let record2 of entries) {
|
|
67329
|
+
yield record2;
|
|
67330
|
+
}
|
|
67331
|
+
}
|
|
67332
|
+
};
|
|
67333
|
+
var ListCollection = class {
|
|
67334
|
+
lists = [];
|
|
67335
|
+
constructor(lists) {
|
|
67336
|
+
this.lists = lists;
|
|
67337
|
+
}
|
|
67338
|
+
get selection() {
|
|
67339
|
+
return this.lists[0].selection;
|
|
67340
|
+
}
|
|
67341
|
+
append(...args) {
|
|
67342
|
+
this.lists.forEach((list) => list.append(...args));
|
|
67343
|
+
}
|
|
67344
|
+
prepend(...args) {
|
|
67345
|
+
this.lists.forEach((list) => list.prepend(...args));
|
|
67346
|
+
}
|
|
67347
|
+
addToList(...args) {
|
|
67348
|
+
this.lists.forEach((list) => list.addToList(...args));
|
|
67349
|
+
}
|
|
67350
|
+
removeID(...args) {
|
|
67351
|
+
this.lists.forEach((list) => list.removeID(...args));
|
|
67352
|
+
}
|
|
67353
|
+
remove(...args) {
|
|
67354
|
+
this.lists.forEach((list) => list.remove(...args));
|
|
67355
|
+
}
|
|
67356
|
+
toggleElement(...args) {
|
|
67357
|
+
this.lists.forEach((list) => list.toggleElement(...args));
|
|
67358
|
+
}
|
|
67359
|
+
when(when) {
|
|
67360
|
+
return new ListCollection(
|
|
67361
|
+
this.lists.filter((list) => {
|
|
67362
|
+
return list.validateWhen(when);
|
|
67363
|
+
})
|
|
67364
|
+
);
|
|
67365
|
+
}
|
|
67366
|
+
includes(key) {
|
|
67367
|
+
return !!this.lists.find((list) => list.key === key);
|
|
67368
|
+
}
|
|
67369
|
+
deleteListWithKey(key) {
|
|
67370
|
+
return this.lists = this.lists.filter((list) => list.key !== key);
|
|
67371
|
+
}
|
|
67372
|
+
*[Symbol.iterator]() {
|
|
67373
|
+
for (let list of this.lists) {
|
|
67374
|
+
for (const entry of list) {
|
|
67375
|
+
yield entry;
|
|
67376
|
+
}
|
|
67377
|
+
}
|
|
67378
|
+
}
|
|
67379
|
+
};
|
|
67380
|
+
|
|
67381
|
+
// src/runtime/cache/schema.ts
|
|
67382
|
+
var SchemaManager = class {
|
|
67383
|
+
cache;
|
|
67384
|
+
fieldTypes = {};
|
|
67385
|
+
constructor(cache) {
|
|
67386
|
+
this.cache = cache;
|
|
67387
|
+
}
|
|
67388
|
+
setFieldType({
|
|
67389
|
+
parent,
|
|
67390
|
+
key,
|
|
67391
|
+
type,
|
|
67392
|
+
nullable = false,
|
|
67393
|
+
link
|
|
67394
|
+
}) {
|
|
67395
|
+
let parensIndex = key.indexOf("(");
|
|
67396
|
+
if (parensIndex !== -1) {
|
|
67397
|
+
key = key.substring(0, parensIndex);
|
|
67398
|
+
}
|
|
67399
|
+
if (parent === rootID) {
|
|
67400
|
+
parent = "Query";
|
|
67401
|
+
} else if (parent.includes(":")) {
|
|
67402
|
+
parent = parent.substring(0, parent.indexOf(":"));
|
|
67403
|
+
}
|
|
67404
|
+
if (!this.fieldTypes[parent]) {
|
|
67405
|
+
this.fieldTypes[parent] = {};
|
|
67406
|
+
}
|
|
67407
|
+
this.fieldTypes[parent][key] = {
|
|
67408
|
+
type,
|
|
67409
|
+
nullable,
|
|
67410
|
+
link: !!link
|
|
67411
|
+
};
|
|
67412
|
+
}
|
|
67413
|
+
fieldType(type, field) {
|
|
67414
|
+
return this.fieldTypes[type]?.[field] || null;
|
|
67415
|
+
}
|
|
67416
|
+
get config() {
|
|
67417
|
+
return this.cache._internal_unstable.config;
|
|
67418
|
+
}
|
|
67419
|
+
};
|
|
67420
|
+
|
|
67421
|
+
// src/runtime/cache/staleManager.ts
|
|
67422
|
+
var StaleManager = class {
|
|
67423
|
+
cache;
|
|
67424
|
+
fieldsTime = /* @__PURE__ */ new Map();
|
|
67425
|
+
constructor(cache) {
|
|
67426
|
+
this.cache = cache;
|
|
67427
|
+
}
|
|
67428
|
+
#initMapId = (id) => {
|
|
67429
|
+
if (!this.fieldsTime.get(id)) {
|
|
67430
|
+
this.fieldsTime.set(id, /* @__PURE__ */ new Map());
|
|
67431
|
+
}
|
|
67432
|
+
};
|
|
67433
|
+
getFieldTime(id, field) {
|
|
67434
|
+
return this.fieldsTime.get(id)?.get(field);
|
|
67435
|
+
}
|
|
67436
|
+
setFieldTimeToNow(id, field) {
|
|
67437
|
+
this.#initMapId(id);
|
|
67438
|
+
this.fieldsTime.get(id)?.set(field, new Date().valueOf());
|
|
67439
|
+
}
|
|
67440
|
+
markFieldStale(id, field) {
|
|
67441
|
+
this.#initMapId(id);
|
|
67442
|
+
this.fieldsTime.get(id)?.set(field, null);
|
|
67443
|
+
}
|
|
67444
|
+
markAllStale() {
|
|
67445
|
+
for (const [id, fieldMap] of this.fieldsTime.entries()) {
|
|
67446
|
+
for (const [field] of fieldMap.entries()) {
|
|
67447
|
+
this.markFieldStale(id, field);
|
|
67448
|
+
}
|
|
67449
|
+
}
|
|
67450
|
+
}
|
|
67451
|
+
markRecordStale(id) {
|
|
67452
|
+
const fieldsTimeOfType = this.fieldsTime.get(id);
|
|
67453
|
+
if (fieldsTimeOfType) {
|
|
67454
|
+
for (const [field] of fieldsTimeOfType.entries()) {
|
|
67455
|
+
this.markFieldStale(id, field);
|
|
67456
|
+
}
|
|
67457
|
+
}
|
|
67458
|
+
}
|
|
67459
|
+
markTypeStale(type) {
|
|
67460
|
+
for (const [id, fieldMap] of this.fieldsTime.entries()) {
|
|
67461
|
+
if (id.startsWith(`${type}:`)) {
|
|
67462
|
+
for (const [field] of fieldMap.entries()) {
|
|
67463
|
+
this.markFieldStale(id, field);
|
|
67464
|
+
}
|
|
67465
|
+
}
|
|
67466
|
+
}
|
|
67467
|
+
}
|
|
67468
|
+
markTypeFieldStale(type, field, when) {
|
|
67469
|
+
const key = computeKey({ field, args: when });
|
|
67470
|
+
for (const [id, fieldMap] of this.fieldsTime.entries()) {
|
|
67471
|
+
if (id.startsWith(`${type}:`)) {
|
|
67472
|
+
for (const local_field of fieldMap.keys()) {
|
|
67473
|
+
if (local_field === key) {
|
|
67474
|
+
this.markFieldStale(id, field);
|
|
67475
|
+
}
|
|
67476
|
+
}
|
|
67477
|
+
}
|
|
67478
|
+
}
|
|
67479
|
+
}
|
|
67480
|
+
delete(id, field) {
|
|
67481
|
+
if (this.fieldsTime.has(id)) {
|
|
67482
|
+
this.fieldsTime.get(id)?.delete(field);
|
|
67483
|
+
if (this.fieldsTime.get(id)?.size === 0) {
|
|
67484
|
+
this.fieldsTime.delete(id);
|
|
67485
|
+
}
|
|
67486
|
+
}
|
|
67487
|
+
}
|
|
67488
|
+
};
|
|
67489
|
+
|
|
67490
|
+
// src/runtime/cache/storage.ts
|
|
67491
|
+
var InMemoryStorage = class {
|
|
67492
|
+
data;
|
|
67493
|
+
idCount = 0;
|
|
67494
|
+
rank = 0;
|
|
67495
|
+
constructor() {
|
|
67496
|
+
this.data = [];
|
|
67497
|
+
}
|
|
67498
|
+
get layerCount() {
|
|
67499
|
+
return this.data.length;
|
|
67500
|
+
}
|
|
67501
|
+
get nextRank() {
|
|
67502
|
+
return this.rank++;
|
|
67503
|
+
}
|
|
67504
|
+
createLayer(optimistic = false) {
|
|
67505
|
+
const layer = new Layer(this.idCount++);
|
|
67506
|
+
layer.optimistic = optimistic;
|
|
67507
|
+
this.data.push(layer);
|
|
67508
|
+
return layer;
|
|
67509
|
+
}
|
|
67510
|
+
insert(id, field, location, target) {
|
|
67511
|
+
return this.topLayer.insert(id, field, location, target);
|
|
67512
|
+
}
|
|
67513
|
+
remove(id, field, target) {
|
|
67514
|
+
return this.topLayer.remove(id, field, target);
|
|
67515
|
+
}
|
|
67516
|
+
delete(id) {
|
|
67517
|
+
return this.topLayer.delete(id);
|
|
67518
|
+
}
|
|
67519
|
+
deleteField(id, field) {
|
|
67520
|
+
return this.topLayer.deleteField(id, field);
|
|
67521
|
+
}
|
|
67522
|
+
getLayer(id) {
|
|
67523
|
+
for (const layer of this.data) {
|
|
67524
|
+
if (layer.id === id) {
|
|
67525
|
+
return layer;
|
|
67526
|
+
}
|
|
67527
|
+
}
|
|
67528
|
+
throw new Error("Could not find layer with id: " + id);
|
|
67529
|
+
}
|
|
67530
|
+
replaceID(replacement) {
|
|
67531
|
+
for (const layer of this.data) {
|
|
67532
|
+
layer.replaceID(replacement);
|
|
67533
|
+
}
|
|
67534
|
+
}
|
|
67535
|
+
get(id, field) {
|
|
67536
|
+
const operations = {
|
|
67537
|
+
[OperationKind.insert]: {
|
|
67538
|
+
[OperationLocation.start]: [],
|
|
67539
|
+
[OperationLocation.end]: []
|
|
67540
|
+
},
|
|
67541
|
+
[OperationKind.remove]: /* @__PURE__ */ new Set()
|
|
67542
|
+
};
|
|
67543
|
+
const layerIDs = [];
|
|
67544
|
+
for (let i2 = this.data.length - 1; i2 >= 0; i2--) {
|
|
67545
|
+
const layer = this.data[i2];
|
|
67546
|
+
const [layerValue, kind] = layer.get(id, field);
|
|
67547
|
+
const layerOperations = layer.getOperations(id, field) || [];
|
|
67548
|
+
layer.deletedIDs.forEach((v) => {
|
|
67549
|
+
if (layer.operations[v]?.undoDeletesInList?.includes(field)) {
|
|
67550
|
+
return;
|
|
67551
|
+
}
|
|
67552
|
+
operations.remove.add(v);
|
|
67553
|
+
});
|
|
67554
|
+
if (typeof layerValue === "undefined" && layerOperations.length === 0) {
|
|
67555
|
+
if (layer.deletedIDs.size > 0) {
|
|
67556
|
+
layerIDs.push(layer.id);
|
|
67557
|
+
}
|
|
67558
|
+
continue;
|
|
67559
|
+
}
|
|
67560
|
+
if (typeof layerValue !== "undefined" && !Array.isArray(layerValue)) {
|
|
67561
|
+
return {
|
|
67562
|
+
value: layerValue,
|
|
67563
|
+
kind,
|
|
67564
|
+
displayLayers: [layer.id]
|
|
67565
|
+
};
|
|
67566
|
+
}
|
|
67567
|
+
layerIDs.push(layer.id);
|
|
67568
|
+
if (layerOperations.length > 0) {
|
|
67569
|
+
for (const op of layerOperations) {
|
|
67570
|
+
if (isRemoveOperation(op)) {
|
|
67571
|
+
operations.remove.add(op.id);
|
|
67572
|
+
}
|
|
67573
|
+
if (isInsertOperation(op)) {
|
|
67574
|
+
operations.insert[op.location].unshift(op.id);
|
|
67575
|
+
}
|
|
67576
|
+
if (isDeleteOperation(op)) {
|
|
67577
|
+
return {
|
|
67578
|
+
value: void 0,
|
|
67579
|
+
kind: "unknown",
|
|
67580
|
+
displayLayers: []
|
|
67581
|
+
};
|
|
67582
|
+
}
|
|
67583
|
+
}
|
|
67584
|
+
}
|
|
67585
|
+
if (typeof layerValue === "undefined") {
|
|
67586
|
+
continue;
|
|
67587
|
+
}
|
|
67588
|
+
if (!operations.remove.size && !operations.insert.start.length && !operations.insert.end.length) {
|
|
67589
|
+
return { value: layerValue, displayLayers: layerIDs, kind: "link" };
|
|
67590
|
+
}
|
|
67591
|
+
return {
|
|
67592
|
+
value: [...operations.insert.start, ...layerValue, ...operations.insert.end].filter(
|
|
67593
|
+
(value) => !operations.remove.has(value)
|
|
67594
|
+
),
|
|
67595
|
+
displayLayers: layerIDs,
|
|
67596
|
+
kind
|
|
67597
|
+
};
|
|
67598
|
+
}
|
|
67599
|
+
return {
|
|
67600
|
+
value: void 0,
|
|
67601
|
+
kind: "unknown",
|
|
67602
|
+
displayLayers: []
|
|
67603
|
+
};
|
|
67604
|
+
}
|
|
67605
|
+
writeLink(id, field, value) {
|
|
67606
|
+
return this.topLayer.writeLink(id, field, value);
|
|
67607
|
+
}
|
|
67608
|
+
writeField(id, field, value) {
|
|
67609
|
+
return this.topLayer.writeField(id, field, value);
|
|
67610
|
+
}
|
|
67611
|
+
resolveLayer(id) {
|
|
67612
|
+
let startingIndex = null;
|
|
67613
|
+
for (const [index, layer] of this.data.entries()) {
|
|
67614
|
+
if (layer.id !== id) {
|
|
67615
|
+
continue;
|
|
67616
|
+
}
|
|
67617
|
+
startingIndex = index - 1;
|
|
67618
|
+
this.data[index].optimistic = false;
|
|
67619
|
+
break;
|
|
67620
|
+
}
|
|
67621
|
+
if (startingIndex === null) {
|
|
67622
|
+
throw new Error("could not find layer with id: " + id);
|
|
67623
|
+
}
|
|
67624
|
+
if (startingIndex === -1) {
|
|
67625
|
+
startingIndex = 0;
|
|
67626
|
+
}
|
|
67627
|
+
if (this.data[startingIndex].optimistic) {
|
|
67628
|
+
startingIndex++;
|
|
67629
|
+
}
|
|
67630
|
+
const baseLayer = this.data[startingIndex];
|
|
67631
|
+
let layerIndex = startingIndex;
|
|
67632
|
+
while (layerIndex < this.data.length) {
|
|
67633
|
+
const layer = this.data[layerIndex++];
|
|
67634
|
+
if (layer.optimistic) {
|
|
67635
|
+
layerIndex--;
|
|
67636
|
+
break;
|
|
67637
|
+
}
|
|
67638
|
+
baseLayer.writeLayer(layer);
|
|
67639
|
+
}
|
|
67640
|
+
this.data.splice(startingIndex + 1, layerIndex - startingIndex - 1);
|
|
67641
|
+
}
|
|
67642
|
+
get topLayer() {
|
|
67643
|
+
if (this.data.length === 0) {
|
|
67644
|
+
this.createLayer();
|
|
67645
|
+
}
|
|
67646
|
+
if (this.data[this.data.length - 1]?.optimistic) {
|
|
67647
|
+
this.createLayer();
|
|
67648
|
+
}
|
|
67649
|
+
return this.data[this.data.length - 1];
|
|
67650
|
+
}
|
|
67651
|
+
};
|
|
67652
|
+
var Layer = class {
|
|
67653
|
+
id;
|
|
67654
|
+
optimistic = false;
|
|
67655
|
+
fields = {};
|
|
67656
|
+
links = {};
|
|
67657
|
+
operations = {};
|
|
67658
|
+
deletedIDs = /* @__PURE__ */ new Set();
|
|
67659
|
+
constructor(id) {
|
|
67660
|
+
this.id = id;
|
|
67661
|
+
}
|
|
67662
|
+
get(id, field) {
|
|
67663
|
+
if (typeof this.links[id]?.[field] !== "undefined") {
|
|
67664
|
+
return [this.links[id][field], "link"];
|
|
67665
|
+
}
|
|
67666
|
+
return [this.fields[id]?.[field], "scalar"];
|
|
67667
|
+
}
|
|
67668
|
+
getOperations(id, field) {
|
|
67669
|
+
if (this.operations[id]?.deleted) {
|
|
67670
|
+
return [
|
|
67671
|
+
{
|
|
67672
|
+
kind: OperationKind.delete,
|
|
67673
|
+
target: id
|
|
67674
|
+
}
|
|
67675
|
+
];
|
|
67676
|
+
}
|
|
67677
|
+
if (this.operations[id]?.fields?.[field]) {
|
|
67678
|
+
return this.operations[id].fields[field];
|
|
67679
|
+
}
|
|
67680
|
+
}
|
|
67681
|
+
writeField(id, field, value) {
|
|
67682
|
+
this.fields[id] = {
|
|
67683
|
+
...this.fields[id],
|
|
67684
|
+
[field]: value
|
|
67685
|
+
};
|
|
67686
|
+
return this.id;
|
|
67687
|
+
}
|
|
67688
|
+
writeLink(id, field, value) {
|
|
67689
|
+
const valueList = Array.isArray(value) ? value : [value];
|
|
67690
|
+
for (const value2 of flatten(valueList)) {
|
|
67691
|
+
if (!value2) {
|
|
67692
|
+
continue;
|
|
67693
|
+
}
|
|
67694
|
+
const fieldOperations = this.operations[id]?.fields[field];
|
|
67695
|
+
if (this.operations[value2]?.deleted || this.deletedIDs.has(value2)) {
|
|
67696
|
+
this.operations[value2] = {
|
|
67697
|
+
...this.operations[value2],
|
|
67698
|
+
undoDeletesInList: [...this.operations[id]?.undoDeletesInList || [], field]
|
|
67699
|
+
};
|
|
67700
|
+
} else if (value2 && fieldOperations?.length > 0) {
|
|
67701
|
+
this.operations[id].fields[field] = fieldOperations.filter(
|
|
67702
|
+
(op) => op.kind !== "remove" || op.id !== value2
|
|
67703
|
+
);
|
|
67704
|
+
}
|
|
67705
|
+
}
|
|
67706
|
+
this.links[id] = {
|
|
67707
|
+
...this.links[id],
|
|
67708
|
+
[field]: value
|
|
67709
|
+
};
|
|
67710
|
+
return this.id;
|
|
67711
|
+
}
|
|
67712
|
+
isDisplayLayer(displayLayers) {
|
|
67713
|
+
return displayLayers.length === 0 || displayLayers.includes(this.id) || Math.max(...displayLayers) < this.id;
|
|
67714
|
+
}
|
|
67715
|
+
clear() {
|
|
67716
|
+
this.links = {};
|
|
67717
|
+
this.fields = {};
|
|
67718
|
+
this.operations = {};
|
|
67719
|
+
this.deletedIDs = /* @__PURE__ */ new Set();
|
|
67720
|
+
}
|
|
67721
|
+
replaceID({ from, to }) {
|
|
67722
|
+
this.fields[to] = this.fields[from];
|
|
67723
|
+
this.links[to] = this.links[from];
|
|
67724
|
+
this.operations[to] = this.operations[from] || { fields: {} };
|
|
67725
|
+
if (this.deletedIDs.has(from)) {
|
|
67726
|
+
this.deletedIDs.add(to);
|
|
67727
|
+
}
|
|
67728
|
+
}
|
|
67729
|
+
removeUndefinedFields() {
|
|
67730
|
+
for (const [id, fields] of Object.entries(this.fields)) {
|
|
67731
|
+
for (const [field, value] of Object.entries(fields)) {
|
|
67732
|
+
if (typeof value === "undefined") {
|
|
67733
|
+
try {
|
|
67734
|
+
delete this.fields[id][field];
|
|
67735
|
+
} catch {
|
|
67736
|
+
}
|
|
67737
|
+
try {
|
|
67738
|
+
delete this.links[id][field];
|
|
67739
|
+
} catch {
|
|
67740
|
+
}
|
|
67741
|
+
}
|
|
67742
|
+
}
|
|
67743
|
+
if (Object.keys(fields || {}).length === 0) {
|
|
67744
|
+
delete this.fields[id];
|
|
67745
|
+
}
|
|
67746
|
+
if (Object.keys(this.links[id] || {}).length === 0) {
|
|
67747
|
+
delete this.links[id];
|
|
67748
|
+
}
|
|
67749
|
+
}
|
|
67750
|
+
}
|
|
67751
|
+
delete(id) {
|
|
67752
|
+
this.operations = {
|
|
67753
|
+
...this.operations,
|
|
67754
|
+
[id]: {
|
|
67755
|
+
...this.operations[id],
|
|
67756
|
+
deleted: true,
|
|
67757
|
+
undoDeletesInList: []
|
|
67758
|
+
}
|
|
67759
|
+
};
|
|
67760
|
+
this.deletedIDs.add(id);
|
|
67761
|
+
}
|
|
67762
|
+
deleteField(id, field) {
|
|
67763
|
+
this.fields[id] = {
|
|
67764
|
+
...this.fields[id],
|
|
67765
|
+
[field]: void 0
|
|
67766
|
+
};
|
|
67767
|
+
}
|
|
67768
|
+
insert(id, field, where, target) {
|
|
67769
|
+
this.addFieldOperation(id, field, {
|
|
67770
|
+
kind: OperationKind.insert,
|
|
67771
|
+
id: target,
|
|
67772
|
+
location: where
|
|
67773
|
+
});
|
|
67774
|
+
}
|
|
67775
|
+
remove(id, field, target) {
|
|
67776
|
+
this.addFieldOperation(id, field, {
|
|
67777
|
+
kind: OperationKind.remove,
|
|
67778
|
+
id: target
|
|
67779
|
+
});
|
|
67780
|
+
}
|
|
67781
|
+
writeLayer(layer) {
|
|
67782
|
+
if (layer.id === this.id) {
|
|
67783
|
+
return;
|
|
67784
|
+
}
|
|
67785
|
+
for (const [id, ops] of Object.entries(layer.operations)) {
|
|
67786
|
+
const fields = {};
|
|
67787
|
+
for (const opMap of [this.operations[id], layer.operations[id]].filter(Boolean)) {
|
|
67788
|
+
for (const [fieldName, operations] of Object.entries(opMap.fields || {})) {
|
|
67789
|
+
fields[fieldName] = [...fields[fieldName] || [], ...operations];
|
|
67790
|
+
}
|
|
67791
|
+
}
|
|
67792
|
+
if (Object.keys(fields).length > 0) {
|
|
67793
|
+
this.operations[id] = {
|
|
67794
|
+
...this.operations[id],
|
|
67795
|
+
fields
|
|
67796
|
+
};
|
|
67797
|
+
}
|
|
67798
|
+
if (ops?.deleted) {
|
|
67799
|
+
delete this.fields[id];
|
|
67800
|
+
delete this.links[id];
|
|
67801
|
+
}
|
|
67802
|
+
}
|
|
67803
|
+
for (const [id, values] of Object.entries(layer.fields)) {
|
|
67804
|
+
if (!values) {
|
|
67805
|
+
continue;
|
|
67806
|
+
}
|
|
67807
|
+
for (const [field, value] of Object.entries(values)) {
|
|
67808
|
+
this.writeField(id, field, value);
|
|
67809
|
+
}
|
|
67810
|
+
}
|
|
67811
|
+
for (const [id, values] of Object.entries(layer.links)) {
|
|
67812
|
+
if (!values) {
|
|
67813
|
+
continue;
|
|
67814
|
+
}
|
|
67815
|
+
for (const [field, value] of Object.entries(values)) {
|
|
67816
|
+
this.writeLink(id, field, value);
|
|
67817
|
+
}
|
|
67818
|
+
}
|
|
67819
|
+
layer.deletedIDs.forEach((v) => this.deletedIDs.add(v));
|
|
67820
|
+
}
|
|
67821
|
+
addFieldOperation(id, field, operation) {
|
|
67822
|
+
this.operations = {
|
|
67823
|
+
...this.operations,
|
|
67824
|
+
[id]: {
|
|
67825
|
+
...this.operations[id],
|
|
67826
|
+
fields: {
|
|
67827
|
+
[field]: [...this.operations[id]?.fields[field] || [], operation]
|
|
67828
|
+
}
|
|
67829
|
+
}
|
|
67830
|
+
};
|
|
67831
|
+
}
|
|
67832
|
+
};
|
|
67833
|
+
function isDeleteOperation(value) {
|
|
67834
|
+
return !!value && value.kind === OperationKind.delete;
|
|
67835
|
+
}
|
|
67836
|
+
function isInsertOperation(value) {
|
|
67837
|
+
return !!value && value.kind === OperationKind.insert;
|
|
67838
|
+
}
|
|
67839
|
+
function isRemoveOperation(value) {
|
|
67840
|
+
return !!value && value.kind === OperationKind.remove;
|
|
67841
|
+
}
|
|
67842
|
+
var OperationLocation = {
|
|
67843
|
+
start: "start",
|
|
67844
|
+
end: "end"
|
|
67845
|
+
};
|
|
67846
|
+
var OperationKind = {
|
|
67847
|
+
delete: "delete",
|
|
67848
|
+
insert: "insert",
|
|
67849
|
+
remove: "remove"
|
|
67850
|
+
};
|
|
67851
|
+
|
|
67852
|
+
// src/runtime/cache/stuff.ts
|
|
67853
|
+
function evaluateKey(key, variables = {}) {
|
|
67854
|
+
let evaluated = "";
|
|
67855
|
+
let varName = "";
|
|
67856
|
+
let inString = false;
|
|
67857
|
+
for (const char of key) {
|
|
67858
|
+
if (varName) {
|
|
67859
|
+
if (varChars.includes(char)) {
|
|
67860
|
+
varName += char;
|
|
67861
|
+
continue;
|
|
67862
|
+
}
|
|
67863
|
+
const value = variables[varName.slice(1)];
|
|
67864
|
+
evaluated += typeof value !== "undefined" ? JSON.stringify(value) : "undefined";
|
|
67865
|
+
varName = "";
|
|
67866
|
+
}
|
|
67867
|
+
if (char === "$" && !inString) {
|
|
67868
|
+
varName = "$";
|
|
67869
|
+
continue;
|
|
67870
|
+
}
|
|
67871
|
+
if (char === '"') {
|
|
67872
|
+
inString = !inString;
|
|
67873
|
+
}
|
|
67874
|
+
evaluated += char;
|
|
67875
|
+
}
|
|
67876
|
+
return evaluated;
|
|
67877
|
+
}
|
|
67878
|
+
var varChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789";
|
|
67879
|
+
|
|
67880
|
+
// src/runtime/cache/subscription.ts
|
|
67881
|
+
var InMemorySubscriptions = class {
|
|
67882
|
+
cache;
|
|
67883
|
+
constructor(cache) {
|
|
67884
|
+
this.cache = cache;
|
|
67885
|
+
}
|
|
67886
|
+
subscribers = {};
|
|
67887
|
+
referenceCounts = {};
|
|
67888
|
+
keyVersions = {};
|
|
67889
|
+
add({
|
|
67890
|
+
parent,
|
|
67891
|
+
spec,
|
|
67892
|
+
selection: selection2,
|
|
67893
|
+
variables,
|
|
67894
|
+
parentType
|
|
67895
|
+
}) {
|
|
67896
|
+
const __typename = this.cache._internal_unstable.storage.get(parent, "__typename").value;
|
|
67897
|
+
let targetSelection = getFieldsForType(selection2, __typename);
|
|
67898
|
+
for (const fieldSelection of Object.values(targetSelection || {})) {
|
|
67899
|
+
const { keyRaw, selection: innerSelection, type, list, filters } = fieldSelection;
|
|
67900
|
+
const key = evaluateKey(keyRaw, variables);
|
|
67901
|
+
let targetSelection2;
|
|
67902
|
+
if (innerSelection) {
|
|
67903
|
+
const __typename2 = this.cache._internal_unstable.storage.get(parent, "__typename").value;
|
|
67904
|
+
targetSelection2 = getFieldsForType(innerSelection, __typename2);
|
|
67905
|
+
}
|
|
67906
|
+
this.addFieldSubscription({
|
|
67907
|
+
id: parent,
|
|
67908
|
+
key,
|
|
67909
|
+
selection: [spec, targetSelection2],
|
|
67910
|
+
type
|
|
67911
|
+
});
|
|
67912
|
+
if (list) {
|
|
67913
|
+
this.registerList({
|
|
67914
|
+
list,
|
|
67915
|
+
filters,
|
|
67916
|
+
id: parent,
|
|
67917
|
+
key,
|
|
67918
|
+
variables,
|
|
67919
|
+
selection: innerSelection,
|
|
67920
|
+
parentType: parentType || spec.rootType
|
|
67921
|
+
});
|
|
67922
|
+
}
|
|
67923
|
+
if (innerSelection) {
|
|
67924
|
+
const { value: linkedRecord } = this.cache._internal_unstable.storage.get(
|
|
67925
|
+
parent,
|
|
67926
|
+
key
|
|
67927
|
+
);
|
|
67928
|
+
let children = !Array.isArray(linkedRecord) ? [linkedRecord] : flatten(linkedRecord) || [];
|
|
67929
|
+
for (const child of children) {
|
|
67930
|
+
if (!child) {
|
|
67931
|
+
continue;
|
|
67932
|
+
}
|
|
67933
|
+
this.add({
|
|
67934
|
+
parent: child,
|
|
67935
|
+
spec,
|
|
67936
|
+
selection: innerSelection,
|
|
67937
|
+
variables,
|
|
67938
|
+
parentType: type
|
|
67939
|
+
});
|
|
67940
|
+
}
|
|
67941
|
+
}
|
|
67942
|
+
}
|
|
67943
|
+
}
|
|
67944
|
+
addFieldSubscription({
|
|
67945
|
+
id,
|
|
67946
|
+
key,
|
|
67947
|
+
selection: selection2,
|
|
67948
|
+
type
|
|
67949
|
+
}) {
|
|
67950
|
+
const spec = selection2[0];
|
|
67951
|
+
if (!this.subscribers[id]) {
|
|
67952
|
+
this.subscribers[id] = {};
|
|
67953
|
+
}
|
|
67954
|
+
if (!this.subscribers[id][key]) {
|
|
67955
|
+
this.subscribers[id][key] = [];
|
|
67956
|
+
}
|
|
67957
|
+
if (!this.keyVersions[key]) {
|
|
67958
|
+
this.keyVersions[key] = /* @__PURE__ */ new Set();
|
|
67959
|
+
}
|
|
67960
|
+
this.keyVersions[key].add(key);
|
|
67961
|
+
if (!this.subscribers[id][key].map(([{ set }]) => set).includes(spec.set)) {
|
|
67962
|
+
this.subscribers[id][key].push([spec, selection2[1]]);
|
|
67963
|
+
}
|
|
67964
|
+
if (!this.referenceCounts[id]) {
|
|
67965
|
+
this.referenceCounts[id] = {};
|
|
67966
|
+
}
|
|
67967
|
+
if (!this.referenceCounts[id][key]) {
|
|
67968
|
+
this.referenceCounts[id][key] = /* @__PURE__ */ new Map();
|
|
67969
|
+
}
|
|
67970
|
+
const counts = this.referenceCounts[id][key];
|
|
67971
|
+
counts.set(spec.set, (counts.get(spec.set) || 0) + 1);
|
|
67972
|
+
this.cache._internal_unstable.lifetimes.resetLifetime(id, key);
|
|
67973
|
+
const { selection: innerSelection } = selection2[1]?.[key] ?? {};
|
|
67974
|
+
}
|
|
67975
|
+
registerList({
|
|
67976
|
+
list,
|
|
67977
|
+
id,
|
|
67978
|
+
key,
|
|
67979
|
+
parentType,
|
|
67980
|
+
selection: selection2,
|
|
67981
|
+
filters,
|
|
67982
|
+
variables
|
|
67983
|
+
}) {
|
|
67984
|
+
this.cache._internal_unstable.lists.add({
|
|
67985
|
+
name: list.name,
|
|
67986
|
+
connection: list.connection,
|
|
67987
|
+
recordID: id,
|
|
67988
|
+
recordType: this.cache._internal_unstable.storage.get(id, "__typename")?.value || parentType,
|
|
67989
|
+
listType: list.type,
|
|
67990
|
+
key,
|
|
67991
|
+
selection: selection2,
|
|
67992
|
+
filters: Object.entries(filters || {}).reduce((acc, [key2, { kind, value }]) => {
|
|
67993
|
+
return {
|
|
67994
|
+
...acc,
|
|
67995
|
+
[key2]: kind !== "Variable" ? value : variables[value]
|
|
67996
|
+
};
|
|
67997
|
+
}, {})
|
|
67998
|
+
});
|
|
67999
|
+
}
|
|
68000
|
+
addMany({
|
|
68001
|
+
parent,
|
|
68002
|
+
variables,
|
|
68003
|
+
subscribers,
|
|
68004
|
+
parentType
|
|
68005
|
+
}) {
|
|
68006
|
+
for (const [spec, targetSelection] of subscribers) {
|
|
68007
|
+
for (const selection2 of Object.values(targetSelection ?? {})) {
|
|
68008
|
+
const {
|
|
68009
|
+
type: linkedType,
|
|
68010
|
+
keyRaw,
|
|
68011
|
+
selection: innerSelection,
|
|
68012
|
+
list,
|
|
68013
|
+
filters
|
|
68014
|
+
} = selection2;
|
|
68015
|
+
const key = evaluateKey(keyRaw, variables);
|
|
68016
|
+
const fieldSelection = innerSelection ? getFieldsForType(innerSelection, parentType) : void 0;
|
|
68017
|
+
this.addFieldSubscription({
|
|
68018
|
+
id: parent,
|
|
68019
|
+
key,
|
|
68020
|
+
selection: [spec, fieldSelection],
|
|
68021
|
+
type: linkedType
|
|
68022
|
+
});
|
|
68023
|
+
if (list) {
|
|
68024
|
+
this.registerList({
|
|
68025
|
+
list,
|
|
68026
|
+
filters,
|
|
68027
|
+
id: parent,
|
|
68028
|
+
key,
|
|
68029
|
+
variables,
|
|
68030
|
+
selection: innerSelection,
|
|
68031
|
+
parentType: parentType || spec.rootType
|
|
68032
|
+
});
|
|
68033
|
+
}
|
|
68034
|
+
const childSelection = selection2.selection;
|
|
68035
|
+
if (childSelection) {
|
|
68036
|
+
const { value: link } = this.cache._internal_unstable.storage.get(parent, key);
|
|
68037
|
+
const children = !Array.isArray(link) ? [link] : flatten(link);
|
|
68038
|
+
for (const linkedRecord of children) {
|
|
68039
|
+
if (!linkedRecord) {
|
|
68040
|
+
continue;
|
|
68041
|
+
}
|
|
68042
|
+
const __typename = this.cache._internal_unstable.storage.get(
|
|
68043
|
+
linkedRecord,
|
|
68044
|
+
"__typename"
|
|
68045
|
+
).value;
|
|
68046
|
+
let targetSelection2 = getFieldsForType(childSelection, __typename);
|
|
68047
|
+
this.addMany({
|
|
68048
|
+
parent: linkedRecord,
|
|
68049
|
+
variables,
|
|
68050
|
+
subscribers: subscribers.map(([sub]) => [sub, targetSelection2]),
|
|
68051
|
+
parentType: linkedType
|
|
68052
|
+
});
|
|
68053
|
+
}
|
|
68054
|
+
}
|
|
68055
|
+
}
|
|
68056
|
+
}
|
|
68057
|
+
}
|
|
68058
|
+
get(id, field) {
|
|
68059
|
+
return this.subscribers[id]?.[field] || [];
|
|
68060
|
+
}
|
|
68061
|
+
remove(id, selection2, targets, variables, visited = []) {
|
|
68062
|
+
visited.push(id);
|
|
68063
|
+
const linkedIDs = [];
|
|
68064
|
+
const __typename = this.cache._internal_unstable.storage.get(id, "__typename").value;
|
|
68065
|
+
let targetSelection = getFieldsForType(selection2, __typename);
|
|
68066
|
+
for (const fieldSelection of Object.values(targetSelection || {})) {
|
|
68067
|
+
const key = evaluateKey(fieldSelection.keyRaw, variables);
|
|
68068
|
+
this.removeSubscribers(id, key, targets);
|
|
68069
|
+
if (!fieldSelection.selection) {
|
|
68070
|
+
continue;
|
|
68071
|
+
}
|
|
68072
|
+
const { value: previousValue } = this.cache._internal_unstable.storage.get(id, key);
|
|
68073
|
+
const links = !Array.isArray(previousValue) ? [previousValue] : flatten(previousValue);
|
|
68074
|
+
for (const link of links) {
|
|
68075
|
+
if (link !== null) {
|
|
68076
|
+
linkedIDs.push([link, fieldSelection.selection || {}]);
|
|
68077
|
+
}
|
|
68078
|
+
}
|
|
68079
|
+
}
|
|
68080
|
+
for (const [linkedRecordID, linkFields] of linkedIDs) {
|
|
68081
|
+
this.remove(linkedRecordID, linkFields, targets, visited);
|
|
68082
|
+
}
|
|
68083
|
+
}
|
|
68084
|
+
removeSubscribers(id, fieldName, specs) {
|
|
68085
|
+
let targets = [];
|
|
68086
|
+
for (const spec of specs) {
|
|
68087
|
+
if (!this.referenceCounts[id]?.[fieldName]?.has(spec.set)) {
|
|
68088
|
+
continue;
|
|
68089
|
+
}
|
|
68090
|
+
const counts = this.referenceCounts[id][fieldName];
|
|
68091
|
+
const newVal = (counts.get(spec.set) || 0) - 1;
|
|
68092
|
+
counts.set(spec.set, newVal);
|
|
68093
|
+
if (newVal <= 0) {
|
|
68094
|
+
targets.push(spec.set);
|
|
68095
|
+
counts.delete(spec.set);
|
|
68096
|
+
}
|
|
68097
|
+
}
|
|
68098
|
+
if (this.subscribers[id]) {
|
|
68099
|
+
this.subscribers[id][fieldName] = this.get(id, fieldName).filter(
|
|
68100
|
+
([{ set }]) => !targets.includes(set)
|
|
68101
|
+
);
|
|
68102
|
+
}
|
|
68103
|
+
}
|
|
68104
|
+
removeAllSubscribers(id, targets, visited = []) {
|
|
68105
|
+
visited.push(id);
|
|
68106
|
+
for (const field of Object.keys(this.subscribers[id] || [])) {
|
|
68107
|
+
const subscribers = targets || this.subscribers[id][field].map(([spec]) => spec);
|
|
68108
|
+
this.removeSubscribers(id, field, subscribers);
|
|
68109
|
+
const { value, kind } = this.cache._internal_unstable.storage.get(id, field);
|
|
68110
|
+
if (kind === "scalar") {
|
|
68111
|
+
continue;
|
|
68112
|
+
}
|
|
68113
|
+
const nextTargets = Array.isArray(value) ? flatten(value) : [value];
|
|
68114
|
+
for (const id2 of nextTargets) {
|
|
68115
|
+
if (visited.includes(id2)) {
|
|
68116
|
+
continue;
|
|
68117
|
+
}
|
|
68118
|
+
this.removeAllSubscribers(id2, subscribers, visited);
|
|
68119
|
+
}
|
|
68120
|
+
}
|
|
68121
|
+
}
|
|
68122
|
+
};
|
|
68123
|
+
|
|
68124
|
+
// src/runtime/cache/cache.ts
|
|
68125
|
+
var Cache = class {
|
|
68126
|
+
_internal_unstable;
|
|
68127
|
+
constructor(config4) {
|
|
68128
|
+
this._internal_unstable = new CacheInternal({
|
|
68129
|
+
cache: this,
|
|
68130
|
+
storage: new InMemoryStorage(),
|
|
68131
|
+
subscriptions: new InMemorySubscriptions(this),
|
|
68132
|
+
lists: new ListManager(this, rootID),
|
|
68133
|
+
lifetimes: new GarbageCollector(this),
|
|
68134
|
+
staleManager: new StaleManager(this),
|
|
68135
|
+
schema: new SchemaManager(this)
|
|
68136
|
+
});
|
|
68137
|
+
if (config4) {
|
|
68138
|
+
this.setConfig(defaultConfigValues(config4));
|
|
68139
|
+
}
|
|
68140
|
+
}
|
|
68141
|
+
write({
|
|
68142
|
+
layer: layerID,
|
|
68143
|
+
notifySubscribers = [],
|
|
68144
|
+
...args
|
|
68145
|
+
}) {
|
|
68146
|
+
const layer = layerID ? this._internal_unstable.storage.getLayer(layerID) : this._internal_unstable.storage.topLayer;
|
|
68147
|
+
const subscribers = this._internal_unstable.writeSelection({ ...args, layer }).map((sub) => sub[0]);
|
|
68148
|
+
const notified = [];
|
|
68149
|
+
for (const spec of subscribers.concat(notifySubscribers)) {
|
|
68150
|
+
if (!notified.includes(spec.set)) {
|
|
68151
|
+
notified.push(spec.set);
|
|
68152
|
+
spec.set(
|
|
68153
|
+
this._internal_unstable.getSelection({
|
|
68154
|
+
parent: spec.parentID || rootID,
|
|
68155
|
+
selection: spec.selection,
|
|
68156
|
+
variables: spec.variables?.() || {}
|
|
68157
|
+
}).data
|
|
68158
|
+
);
|
|
68159
|
+
}
|
|
68160
|
+
}
|
|
68161
|
+
return subscribers;
|
|
68162
|
+
}
|
|
68163
|
+
read(...args) {
|
|
68164
|
+
const { data, partial, stale, hasData } = this._internal_unstable.getSelection(...args);
|
|
68165
|
+
if (!hasData) {
|
|
68166
|
+
return { data: null, partial: false, stale: false };
|
|
68167
|
+
}
|
|
68168
|
+
return {
|
|
68169
|
+
data,
|
|
68170
|
+
partial,
|
|
68171
|
+
stale
|
|
68172
|
+
};
|
|
68173
|
+
}
|
|
68174
|
+
subscribe(spec, variables = {}) {
|
|
68175
|
+
return this._internal_unstable.subscriptions.add({
|
|
68176
|
+
parent: spec.parentID || rootID,
|
|
68177
|
+
spec,
|
|
68178
|
+
selection: spec.selection,
|
|
68179
|
+
variables
|
|
68180
|
+
});
|
|
68181
|
+
}
|
|
68182
|
+
unsubscribe(spec, variables = {}) {
|
|
68183
|
+
return this._internal_unstable.subscriptions.remove(
|
|
68184
|
+
spec.parentID || rootID,
|
|
68185
|
+
spec.selection,
|
|
68186
|
+
[spec],
|
|
68187
|
+
variables
|
|
68188
|
+
);
|
|
68189
|
+
}
|
|
68190
|
+
list(name, parentID, allLists) {
|
|
68191
|
+
const handler = this._internal_unstable.lists.get(name, parentID, allLists);
|
|
68192
|
+
if (!handler) {
|
|
68193
|
+
throw new Error(
|
|
68194
|
+
`Cannot find list with name: ${name}${parentID ? " under parent " + parentID : ""}. Is it possible that the query is not mounted?`
|
|
68195
|
+
);
|
|
68196
|
+
}
|
|
68197
|
+
return handler;
|
|
68198
|
+
}
|
|
68199
|
+
delete(id) {
|
|
68200
|
+
this._internal_unstable.subscriptions.removeAllSubscribers(id);
|
|
68201
|
+
this._internal_unstable.lists.removeIDFromAllLists(id);
|
|
68202
|
+
this._internal_unstable.storage.delete(id);
|
|
68203
|
+
}
|
|
68204
|
+
setConfig(config4) {
|
|
68205
|
+
this._internal_unstable.setConfig(config4);
|
|
68206
|
+
}
|
|
68207
|
+
markTypeStale(options) {
|
|
68208
|
+
if (!options) {
|
|
68209
|
+
this._internal_unstable.staleManager.markAllStale();
|
|
68210
|
+
} else if (!options.field) {
|
|
68211
|
+
this._internal_unstable.staleManager.markTypeStale(options.type);
|
|
68212
|
+
} else {
|
|
68213
|
+
this._internal_unstable.staleManager.markTypeFieldStale(
|
|
68214
|
+
options.type,
|
|
68215
|
+
options.field,
|
|
68216
|
+
options.when
|
|
68217
|
+
);
|
|
68218
|
+
}
|
|
68219
|
+
}
|
|
68220
|
+
markRecordStale(id, options) {
|
|
68221
|
+
if (options.field) {
|
|
68222
|
+
const key = computeKey({ field: options.field, args: options.when ?? {} });
|
|
68223
|
+
this._internal_unstable.staleManager.markFieldStale(id, key);
|
|
68224
|
+
} else {
|
|
68225
|
+
this._internal_unstable.staleManager.markRecordStale(id);
|
|
68226
|
+
}
|
|
68227
|
+
}
|
|
68228
|
+
getFieldTime(id, field) {
|
|
68229
|
+
return this._internal_unstable.staleManager.getFieldTime(id, field);
|
|
68230
|
+
}
|
|
68231
|
+
};
|
|
68232
|
+
var CacheInternal = class {
|
|
68233
|
+
_disabled = false;
|
|
68234
|
+
config = defaultConfigValues({
|
|
68235
|
+
plugins: {
|
|
68236
|
+
"houdini-svelte": {
|
|
68237
|
+
client: ""
|
|
68238
|
+
}
|
|
68239
|
+
}
|
|
68240
|
+
});
|
|
68241
|
+
storage;
|
|
68242
|
+
subscriptions;
|
|
68243
|
+
lists;
|
|
68244
|
+
cache;
|
|
68245
|
+
lifetimes;
|
|
68246
|
+
staleManager;
|
|
68247
|
+
schema;
|
|
68248
|
+
constructor({
|
|
68249
|
+
storage,
|
|
68250
|
+
subscriptions,
|
|
68251
|
+
lists,
|
|
68252
|
+
cache,
|
|
68253
|
+
lifetimes,
|
|
68254
|
+
staleManager,
|
|
68255
|
+
schema
|
|
68256
|
+
}) {
|
|
68257
|
+
this.storage = storage;
|
|
68258
|
+
this.subscriptions = subscriptions;
|
|
68259
|
+
this.lists = lists;
|
|
68260
|
+
this.cache = cache;
|
|
68261
|
+
this.lifetimes = lifetimes;
|
|
68262
|
+
this.staleManager = staleManager;
|
|
68263
|
+
this.schema = schema;
|
|
68264
|
+
this._disabled = typeof globalThis.window === "undefined";
|
|
68265
|
+
try {
|
|
68266
|
+
if (process.env.HOUDINI_TEST === "true") {
|
|
68267
|
+
this._disabled = false;
|
|
68268
|
+
}
|
|
68269
|
+
} catch {
|
|
68270
|
+
}
|
|
68271
|
+
}
|
|
68272
|
+
setConfig(config4) {
|
|
68273
|
+
this.config = config4;
|
|
68274
|
+
}
|
|
68275
|
+
writeSelection({
|
|
68276
|
+
data,
|
|
68277
|
+
selection: selection2,
|
|
68278
|
+
variables = {},
|
|
68279
|
+
parent = rootID,
|
|
68280
|
+
applyUpdates,
|
|
68281
|
+
layer,
|
|
68282
|
+
toNotify = [],
|
|
68283
|
+
forceNotify,
|
|
68284
|
+
forceStale
|
|
68285
|
+
}) {
|
|
68286
|
+
if (this._disabled) {
|
|
68287
|
+
return [];
|
|
68288
|
+
}
|
|
68289
|
+
let targetSelection = getFieldsForType(selection2, data["__typename"]);
|
|
68290
|
+
for (const [field, value] of Object.entries(data)) {
|
|
68291
|
+
if (!selection2 || !targetSelection[field]) {
|
|
68292
|
+
throw new Error(
|
|
68293
|
+
"Could not find field listing in selection for " + field + " @ " + JSON.stringify(selection2)
|
|
68294
|
+
);
|
|
68295
|
+
}
|
|
68296
|
+
let {
|
|
68297
|
+
type: linkedType,
|
|
68298
|
+
keyRaw,
|
|
68299
|
+
selection: fieldSelection,
|
|
68300
|
+
operations,
|
|
68301
|
+
abstract: isAbstract,
|
|
68302
|
+
updates,
|
|
68303
|
+
nullable
|
|
68304
|
+
} = targetSelection[field];
|
|
68305
|
+
const key = evaluateKey(keyRaw, variables);
|
|
68306
|
+
this.schema.setFieldType({
|
|
68307
|
+
parent,
|
|
68308
|
+
key: keyRaw,
|
|
68309
|
+
type: linkedType,
|
|
68310
|
+
nullable,
|
|
68311
|
+
link: !!fieldSelection
|
|
68312
|
+
});
|
|
68313
|
+
const currentSubscribers = this.subscriptions.get(parent, key);
|
|
68314
|
+
const specs = currentSubscribers.map((sub) => sub[0]);
|
|
68315
|
+
const { value: previousValue, displayLayers } = this.storage.get(parent, key);
|
|
68316
|
+
const displayLayer = layer.isDisplayLayer(displayLayers);
|
|
68317
|
+
if (displayLayer) {
|
|
68318
|
+
this.lifetimes.resetLifetime(parent, key);
|
|
68319
|
+
if (forceStale) {
|
|
68320
|
+
this.staleManager.markFieldStale(parent, key);
|
|
68321
|
+
} else {
|
|
68322
|
+
this.staleManager.setFieldTimeToNow(parent, key);
|
|
68323
|
+
}
|
|
68324
|
+
}
|
|
68325
|
+
if (!fieldSelection) {
|
|
68326
|
+
let newValue = value;
|
|
68327
|
+
if (updates && applyUpdates && Array.isArray(value)) {
|
|
68328
|
+
for (const update of applyUpdates) {
|
|
68329
|
+
if (!updates.includes(update)) {
|
|
68330
|
+
continue;
|
|
68331
|
+
}
|
|
68332
|
+
if (update === "append") {
|
|
68333
|
+
newValue = (previousValue || []).concat(value);
|
|
68334
|
+
} else if (update === "prepend") {
|
|
68335
|
+
newValue = value.concat(previousValue || []);
|
|
68336
|
+
}
|
|
68337
|
+
}
|
|
68338
|
+
}
|
|
68339
|
+
if (updates && applyUpdates?.includes("prepend") && ["endCursor", "hasNextPage"].includes(key)) {
|
|
68340
|
+
newValue = previousValue;
|
|
68341
|
+
} else if (updates && applyUpdates?.includes("append") && ["startCursor", "hasPreviousPage"].includes(key)) {
|
|
68342
|
+
newValue = previousValue;
|
|
68343
|
+
}
|
|
68344
|
+
const valueChanged = !deepEquals(newValue, previousValue);
|
|
68345
|
+
if (displayLayer && (valueChanged || forceNotify)) {
|
|
68346
|
+
toNotify.push(...currentSubscribers);
|
|
68347
|
+
}
|
|
68348
|
+
layer.writeField(parent, key, newValue);
|
|
68349
|
+
} else if (value === null) {
|
|
68350
|
+
if (previousValue === null) {
|
|
68351
|
+
continue;
|
|
68352
|
+
}
|
|
68353
|
+
const previousLinks = flatten([previousValue]);
|
|
68354
|
+
for (const link of previousLinks) {
|
|
68355
|
+
this.subscriptions.remove(link, fieldSelection, specs, variables);
|
|
68356
|
+
}
|
|
68357
|
+
layer.writeLink(parent, key, null);
|
|
68358
|
+
toNotify.push(...currentSubscribers);
|
|
68359
|
+
} else if (value instanceof Object && !Array.isArray(value)) {
|
|
68360
|
+
if (isAbstract) {
|
|
68361
|
+
if (!value.__typename) {
|
|
68362
|
+
throw new Error(
|
|
68363
|
+
"Encountered interface type without __typename in the payload"
|
|
68364
|
+
);
|
|
68365
|
+
}
|
|
68366
|
+
linkedType = value.__typename;
|
|
68367
|
+
}
|
|
68368
|
+
const embedded = this.idFields(linkedType)?.filter(
|
|
68369
|
+
(field2) => typeof value[field2] === "undefined"
|
|
68370
|
+
).length > 0;
|
|
68371
|
+
let linkedID = null;
|
|
68372
|
+
if (value !== null) {
|
|
68373
|
+
linkedID = !embedded ? this.id(linkedType, value) : `${parent}.${key}`;
|
|
68374
|
+
}
|
|
68375
|
+
let linkChange = linkedID !== previousValue;
|
|
68376
|
+
layer.writeLink(parent, key, linkedID);
|
|
68377
|
+
if (linkedID && displayLayer && (linkChange || forceNotify)) {
|
|
68378
|
+
if (previousValue && typeof previousValue === "string") {
|
|
68379
|
+
this.subscriptions.remove(previousValue, fieldSelection, specs, variables);
|
|
68380
|
+
}
|
|
68381
|
+
this.subscriptions.addMany({
|
|
68382
|
+
parent: linkedID,
|
|
68383
|
+
subscribers: currentSubscribers,
|
|
68384
|
+
variables,
|
|
68385
|
+
parentType: linkedType
|
|
68386
|
+
});
|
|
68387
|
+
toNotify.push(...currentSubscribers);
|
|
68388
|
+
}
|
|
68389
|
+
if (linkedID) {
|
|
68390
|
+
this.writeSelection({
|
|
68391
|
+
selection: fieldSelection,
|
|
68392
|
+
parent: linkedID,
|
|
68393
|
+
data: value,
|
|
68394
|
+
variables,
|
|
68395
|
+
toNotify,
|
|
68396
|
+
applyUpdates,
|
|
68397
|
+
layer,
|
|
68398
|
+
forceNotify
|
|
68399
|
+
});
|
|
68400
|
+
}
|
|
68401
|
+
} else if (Array.isArray(value) && (typeof previousValue === "undefined" || Array.isArray(previousValue))) {
|
|
68402
|
+
let oldIDs = [...previousValue || []];
|
|
68403
|
+
const emptyEdges = !updates ? [] : oldIDs.map((id) => {
|
|
68404
|
+
if (!id) {
|
|
68405
|
+
return "";
|
|
68406
|
+
}
|
|
68407
|
+
const { value: cursorField } = this.storage.get(id, "cursor");
|
|
68408
|
+
if (cursorField) {
|
|
68409
|
+
return "";
|
|
68410
|
+
}
|
|
68411
|
+
const { value: node } = this.storage.get(id, "node");
|
|
68412
|
+
if (!node) {
|
|
68413
|
+
return "";
|
|
68414
|
+
}
|
|
68415
|
+
return node;
|
|
68416
|
+
});
|
|
68417
|
+
let linkedIDs = [];
|
|
68418
|
+
const { newIDs, nestedIDs } = this.extractNestedListIDs({
|
|
68419
|
+
value,
|
|
68420
|
+
abstract: Boolean(isAbstract),
|
|
68421
|
+
specs: toNotify,
|
|
68422
|
+
applyUpdates,
|
|
68423
|
+
recordID: parent,
|
|
68424
|
+
key,
|
|
68425
|
+
linkedType,
|
|
68426
|
+
variables,
|
|
68427
|
+
fields: fieldSelection,
|
|
68428
|
+
layer,
|
|
68429
|
+
forceNotify
|
|
68430
|
+
});
|
|
68431
|
+
if (applyUpdates && updates) {
|
|
68432
|
+
if (key === "edges") {
|
|
68433
|
+
const newNodeIDs = [];
|
|
68434
|
+
for (const id of newIDs) {
|
|
68435
|
+
if (!id) {
|
|
68436
|
+
continue;
|
|
68437
|
+
}
|
|
68438
|
+
const { value: node } = this.storage.get(id, "node");
|
|
68439
|
+
if (typeof node !== "string") {
|
|
68440
|
+
continue;
|
|
68441
|
+
}
|
|
68442
|
+
if (!node || !this.storage.get(node, "__typename")) {
|
|
68443
|
+
continue;
|
|
68444
|
+
}
|
|
68445
|
+
newNodeIDs.push(node);
|
|
68446
|
+
}
|
|
68447
|
+
oldIDs = oldIDs.filter((id) => {
|
|
68448
|
+
if (!id) {
|
|
68449
|
+
return true;
|
|
68450
|
+
}
|
|
68451
|
+
const { value: value2 } = this.storage.get(id, "node");
|
|
68452
|
+
const node = value2;
|
|
68453
|
+
if (newNodeIDs.includes(node) && emptyEdges.includes(node)) {
|
|
68454
|
+
return false;
|
|
68455
|
+
}
|
|
68456
|
+
return true;
|
|
68457
|
+
});
|
|
68458
|
+
}
|
|
68459
|
+
for (const update of applyUpdates) {
|
|
68460
|
+
if (update !== "replace" && !updates.includes(update)) {
|
|
68461
|
+
continue;
|
|
68462
|
+
}
|
|
68463
|
+
if (update === "prepend") {
|
|
68464
|
+
linkedIDs = newIDs.concat(oldIDs);
|
|
68465
|
+
} else if (update === "append") {
|
|
68466
|
+
linkedIDs = oldIDs.concat(newIDs);
|
|
68467
|
+
} else if (update === "replace") {
|
|
68468
|
+
linkedIDs = newIDs;
|
|
68469
|
+
}
|
|
68470
|
+
}
|
|
68471
|
+
} else {
|
|
68472
|
+
linkedIDs = nestedIDs;
|
|
68473
|
+
}
|
|
68474
|
+
const contentChanged = !deepEquals(linkedIDs, oldIDs);
|
|
68475
|
+
if (contentChanged || forceNotify) {
|
|
68476
|
+
toNotify.push(...currentSubscribers);
|
|
68477
|
+
}
|
|
68478
|
+
for (const lostID of oldIDs) {
|
|
68479
|
+
if (linkedIDs.includes(lostID) || !lostID) {
|
|
68480
|
+
continue;
|
|
68481
|
+
}
|
|
68482
|
+
this.subscriptions.remove(lostID, fieldSelection, specs, variables);
|
|
68483
|
+
}
|
|
68484
|
+
if (contentChanged || oldIDs.length === 0 && newIDs.length === 0) {
|
|
68485
|
+
layer.writeLink(parent, key, linkedIDs);
|
|
68486
|
+
}
|
|
68487
|
+
for (const id of newIDs.filter((id2) => !oldIDs.includes(id2))) {
|
|
68488
|
+
if (id == null) {
|
|
68489
|
+
continue;
|
|
68490
|
+
}
|
|
68491
|
+
this.subscriptions.addMany({
|
|
68492
|
+
parent: id,
|
|
68493
|
+
subscribers: currentSubscribers,
|
|
68494
|
+
variables,
|
|
68495
|
+
parentType: linkedType
|
|
68496
|
+
});
|
|
68497
|
+
}
|
|
68498
|
+
}
|
|
68499
|
+
for (const operation of operations || []) {
|
|
68500
|
+
let parentID;
|
|
68501
|
+
if (operation.parentID) {
|
|
68502
|
+
if (operation.parentID.kind !== "Variable") {
|
|
68503
|
+
parentID = operation.parentID.value;
|
|
68504
|
+
} else {
|
|
68505
|
+
const id = variables[operation.parentID.value];
|
|
68506
|
+
if (typeof id !== "string") {
|
|
68507
|
+
throw new Error("parentID value must be a string");
|
|
68508
|
+
}
|
|
68509
|
+
parentID = id;
|
|
68510
|
+
}
|
|
68511
|
+
}
|
|
68512
|
+
if (operation.list && !this.lists.get(operation.list, parentID, operation.target === "all")) {
|
|
68513
|
+
continue;
|
|
68514
|
+
}
|
|
68515
|
+
const targets = Array.isArray(value) ? value : [value];
|
|
68516
|
+
for (const target of targets) {
|
|
68517
|
+
if (operation.action === "insert" && target instanceof Object && fieldSelection && operation.list) {
|
|
68518
|
+
this.cache.list(operation.list, parentID, operation.target === "all").when(operation.when).addToList(
|
|
68519
|
+
fieldSelection,
|
|
68520
|
+
target,
|
|
68521
|
+
variables,
|
|
68522
|
+
operation.position || "last"
|
|
68523
|
+
);
|
|
68524
|
+
} else if (operation.action === "remove" && target instanceof Object && fieldSelection && operation.list) {
|
|
68525
|
+
this.cache.list(operation.list, parentID, operation.target === "all").when(operation.when).remove(target, variables);
|
|
68526
|
+
} else if (operation.action === "delete" && operation.type) {
|
|
68527
|
+
if (typeof target !== "string") {
|
|
68528
|
+
throw new Error("Cannot delete a record with a non-string ID");
|
|
68529
|
+
}
|
|
68530
|
+
const targetID = this.id(operation.type, target);
|
|
68531
|
+
if (!targetID) {
|
|
68532
|
+
continue;
|
|
68533
|
+
}
|
|
68534
|
+
this.cache.delete(targetID);
|
|
68535
|
+
} else if (operation.action === "toggle" && target instanceof Object && fieldSelection && operation.list) {
|
|
68536
|
+
this.cache.list(operation.list, parentID, operation.target === "all").when(operation.when).toggleElement(
|
|
68537
|
+
fieldSelection,
|
|
68538
|
+
target,
|
|
68539
|
+
variables,
|
|
68540
|
+
operation.position || "last"
|
|
68541
|
+
);
|
|
68542
|
+
}
|
|
68543
|
+
}
|
|
68544
|
+
}
|
|
68545
|
+
}
|
|
68546
|
+
return toNotify;
|
|
68547
|
+
}
|
|
68548
|
+
getSelection({
|
|
68549
|
+
selection: selection2,
|
|
68550
|
+
parent = rootID,
|
|
68551
|
+
variables,
|
|
68552
|
+
stepsFromConnection = null
|
|
68553
|
+
}) {
|
|
68554
|
+
if (parent === null) {
|
|
68555
|
+
return { data: null, partial: false, stale: false, hasData: true };
|
|
68556
|
+
}
|
|
68557
|
+
const target = {};
|
|
68558
|
+
let hasData = false;
|
|
68559
|
+
let partial = false;
|
|
68560
|
+
let cascadeNull = false;
|
|
68561
|
+
let stale = false;
|
|
68562
|
+
const typename = this.storage.get(parent, "__typename").value;
|
|
68563
|
+
let targetSelection = getFieldsForType(selection2, typename);
|
|
68564
|
+
for (const [
|
|
68565
|
+
attributeName,
|
|
68566
|
+
{ type, keyRaw, selection: fieldSelection, nullable, list }
|
|
68567
|
+
] of Object.entries(targetSelection)) {
|
|
68568
|
+
const key = evaluateKey(keyRaw, variables);
|
|
68569
|
+
const { value } = this.storage.get(parent, key);
|
|
68570
|
+
const dt_field = this.staleManager.getFieldTime(parent, key);
|
|
68571
|
+
if (dt_field === null) {
|
|
68572
|
+
stale = true;
|
|
68573
|
+
}
|
|
68574
|
+
let nextStep = stepsFromConnection;
|
|
68575
|
+
if (nextStep !== null) {
|
|
68576
|
+
if (nextStep >= 2) {
|
|
68577
|
+
nextStep = null;
|
|
68578
|
+
} else {
|
|
68579
|
+
nextStep += 1;
|
|
68580
|
+
}
|
|
68581
|
+
}
|
|
68582
|
+
if (list?.connection) {
|
|
68583
|
+
nextStep = 0;
|
|
68584
|
+
}
|
|
68585
|
+
const embeddedCursor = key === "cursor" && stepsFromConnection === 1;
|
|
68586
|
+
if (typeof value === "undefined" && !embeddedCursor) {
|
|
68587
|
+
partial = true;
|
|
68588
|
+
}
|
|
68589
|
+
if (typeof value === "undefined" || value === null) {
|
|
68590
|
+
target[attributeName] = null;
|
|
68591
|
+
if (typeof value !== "undefined") {
|
|
68592
|
+
hasData = true;
|
|
68593
|
+
}
|
|
68594
|
+
} else if (!fieldSelection) {
|
|
68595
|
+
const fnUnmarshal = this.config?.scalars?.[type]?.unmarshal;
|
|
68596
|
+
if (fnUnmarshal) {
|
|
68597
|
+
target[attributeName] = fnUnmarshal(value);
|
|
68598
|
+
} else {
|
|
68599
|
+
target[attributeName] = value;
|
|
68600
|
+
}
|
|
68601
|
+
hasData = true;
|
|
68602
|
+
} else if (Array.isArray(value)) {
|
|
68603
|
+
const listValue = this.hydrateNestedList({
|
|
68604
|
+
fields: fieldSelection,
|
|
68605
|
+
variables,
|
|
68606
|
+
linkedList: value,
|
|
68607
|
+
stepsFromConnection: nextStep
|
|
68608
|
+
});
|
|
68609
|
+
target[attributeName] = listValue.data;
|
|
68610
|
+
if (listValue.partial) {
|
|
68611
|
+
partial = true;
|
|
68612
|
+
}
|
|
68613
|
+
if (listValue.stale) {
|
|
68614
|
+
stale = true;
|
|
68615
|
+
}
|
|
68616
|
+
if (listValue.hasData || value.length === 0) {
|
|
68617
|
+
hasData = true;
|
|
68618
|
+
}
|
|
68619
|
+
} else {
|
|
68620
|
+
const objectFields = this.getSelection({
|
|
68621
|
+
parent: value,
|
|
68622
|
+
selection: fieldSelection,
|
|
68623
|
+
variables,
|
|
68624
|
+
stepsFromConnection: nextStep
|
|
68625
|
+
});
|
|
68626
|
+
target[attributeName] = objectFields.data;
|
|
68627
|
+
if (objectFields.partial) {
|
|
68628
|
+
partial = true;
|
|
68629
|
+
}
|
|
68630
|
+
if (objectFields.stale) {
|
|
68631
|
+
stale = true;
|
|
68632
|
+
}
|
|
68633
|
+
if (objectFields.hasData) {
|
|
68634
|
+
hasData = true;
|
|
68635
|
+
}
|
|
68636
|
+
}
|
|
68637
|
+
if (target[attributeName] === null && !nullable && !embeddedCursor) {
|
|
68638
|
+
cascadeNull = true;
|
|
68639
|
+
}
|
|
68640
|
+
}
|
|
68641
|
+
return {
|
|
68642
|
+
data: cascadeNull ? null : target,
|
|
68643
|
+
partial: hasData && partial,
|
|
68644
|
+
stale: hasData && stale,
|
|
68645
|
+
hasData
|
|
68646
|
+
};
|
|
68647
|
+
}
|
|
68648
|
+
id(type, data) {
|
|
68649
|
+
const id = typeof data === "string" ? data : this.computeID(type, data);
|
|
68650
|
+
if (!id) {
|
|
68651
|
+
return null;
|
|
68652
|
+
}
|
|
68653
|
+
if (!type) {
|
|
68654
|
+
return id;
|
|
68655
|
+
}
|
|
68656
|
+
return type + ":" + id;
|
|
68657
|
+
}
|
|
68658
|
+
idFields(type) {
|
|
68659
|
+
return keyFieldsForType(this.config, type);
|
|
68660
|
+
}
|
|
68661
|
+
computeID(type, data) {
|
|
68662
|
+
return computeID(this.config, type, data);
|
|
68663
|
+
}
|
|
68664
|
+
hydrateNestedList({
|
|
68665
|
+
fields,
|
|
68666
|
+
variables,
|
|
68667
|
+
linkedList,
|
|
68668
|
+
stepsFromConnection
|
|
68669
|
+
}) {
|
|
68670
|
+
const result = [];
|
|
68671
|
+
let partialData = false;
|
|
68672
|
+
let stale = false;
|
|
68673
|
+
let hasValues = false;
|
|
68674
|
+
for (const entry of linkedList) {
|
|
68675
|
+
if (Array.isArray(entry)) {
|
|
68676
|
+
const nestedValue = this.hydrateNestedList({
|
|
68677
|
+
fields,
|
|
68678
|
+
variables,
|
|
68679
|
+
linkedList: entry,
|
|
68680
|
+
stepsFromConnection
|
|
68681
|
+
});
|
|
68682
|
+
result.push(nestedValue.data);
|
|
68683
|
+
if (nestedValue.partial) {
|
|
68684
|
+
partialData = true;
|
|
68685
|
+
}
|
|
68686
|
+
continue;
|
|
68687
|
+
}
|
|
68688
|
+
if (entry === null) {
|
|
68689
|
+
result.push(entry);
|
|
68690
|
+
continue;
|
|
68691
|
+
}
|
|
68692
|
+
const {
|
|
68693
|
+
data,
|
|
68694
|
+
partial,
|
|
68695
|
+
stale: local_stale,
|
|
68696
|
+
hasData
|
|
68697
|
+
} = this.getSelection({
|
|
68698
|
+
parent: entry,
|
|
68699
|
+
selection: fields,
|
|
68700
|
+
variables,
|
|
68701
|
+
stepsFromConnection
|
|
68702
|
+
});
|
|
68703
|
+
result.push(data);
|
|
68704
|
+
if (partial) {
|
|
68705
|
+
partialData = true;
|
|
68706
|
+
}
|
|
68707
|
+
if (local_stale) {
|
|
68708
|
+
stale = true;
|
|
68709
|
+
}
|
|
68710
|
+
if (hasData) {
|
|
68711
|
+
hasValues = true;
|
|
68712
|
+
}
|
|
68713
|
+
}
|
|
68714
|
+
return {
|
|
68715
|
+
data: result,
|
|
68716
|
+
partial: partialData,
|
|
68717
|
+
stale,
|
|
68718
|
+
hasData: hasValues
|
|
68719
|
+
};
|
|
68720
|
+
}
|
|
68721
|
+
extractNestedListIDs({
|
|
68722
|
+
value,
|
|
68723
|
+
abstract,
|
|
68724
|
+
recordID,
|
|
68725
|
+
key,
|
|
68726
|
+
linkedType,
|
|
68727
|
+
fields,
|
|
68728
|
+
variables,
|
|
68729
|
+
applyUpdates,
|
|
68730
|
+
specs,
|
|
68731
|
+
layer,
|
|
68732
|
+
forceNotify
|
|
68733
|
+
}) {
|
|
68734
|
+
const nestedIDs = [];
|
|
68735
|
+
const newIDs = [];
|
|
68736
|
+
for (const [i2, entry] of value.entries()) {
|
|
68737
|
+
if (Array.isArray(entry)) {
|
|
68738
|
+
const inner = this.extractNestedListIDs({
|
|
68739
|
+
value: entry,
|
|
68740
|
+
abstract,
|
|
68741
|
+
recordID,
|
|
68742
|
+
key,
|
|
68743
|
+
linkedType,
|
|
68744
|
+
fields,
|
|
68745
|
+
variables,
|
|
68746
|
+
applyUpdates,
|
|
68747
|
+
specs,
|
|
68748
|
+
layer,
|
|
68749
|
+
forceNotify
|
|
68750
|
+
});
|
|
68751
|
+
newIDs.push(...inner.newIDs);
|
|
68752
|
+
nestedIDs[i2] = inner.nestedIDs;
|
|
68753
|
+
continue;
|
|
68754
|
+
}
|
|
68755
|
+
if (entry === null || typeof entry === "undefined") {
|
|
68756
|
+
newIDs.push(null);
|
|
68757
|
+
nestedIDs[i2] = null;
|
|
68758
|
+
continue;
|
|
68759
|
+
}
|
|
68760
|
+
const entryObj = entry;
|
|
68761
|
+
let linkedID = `${recordID}.${key}[${this.storage.nextRank}]`;
|
|
68762
|
+
const embedded = this.idFields(linkedType)?.filter(
|
|
68763
|
+
(field) => typeof entry[field] === "undefined"
|
|
68764
|
+
).length > 0;
|
|
68765
|
+
const typename = entryObj.__typename;
|
|
68766
|
+
let innerType = linkedType;
|
|
68767
|
+
if (abstract) {
|
|
68768
|
+
if (!typename) {
|
|
68769
|
+
throw new Error("Encountered interface type without __typename in the payload");
|
|
68770
|
+
}
|
|
68771
|
+
innerType = typename;
|
|
68772
|
+
}
|
|
68773
|
+
if (!embedded) {
|
|
68774
|
+
const id = this.id(innerType, entry);
|
|
68775
|
+
if (id) {
|
|
68776
|
+
linkedID = id;
|
|
68777
|
+
} else {
|
|
68778
|
+
continue;
|
|
68779
|
+
}
|
|
68780
|
+
}
|
|
68781
|
+
this.writeSelection({
|
|
68782
|
+
root: rootID,
|
|
68783
|
+
selection: fields,
|
|
68784
|
+
parent: linkedID,
|
|
68785
|
+
data: entryObj,
|
|
68786
|
+
variables,
|
|
68787
|
+
toNotify: specs,
|
|
68788
|
+
applyUpdates,
|
|
68789
|
+
layer,
|
|
68790
|
+
forceNotify
|
|
68791
|
+
});
|
|
68792
|
+
newIDs.push(linkedID);
|
|
68793
|
+
nestedIDs[i2] = linkedID;
|
|
68794
|
+
}
|
|
68795
|
+
return { newIDs, nestedIDs };
|
|
68796
|
+
}
|
|
68797
|
+
collectGarbage() {
|
|
68798
|
+
this.lifetimes.tick();
|
|
68799
|
+
if (this.storage.layerCount === 1) {
|
|
68800
|
+
this.storage.topLayer.removeUndefinedFields();
|
|
68801
|
+
}
|
|
68802
|
+
}
|
|
68803
|
+
};
|
|
68804
|
+
var rootID = "_ROOT_";
|
|
68805
|
+
|
|
68806
|
+
// src/runtime/cache/index.ts
|
|
68807
|
+
var cache_default = new Cache();
|
|
68808
|
+
|
|
68809
|
+
// src/runtime/client/utils/documentPlugins.ts
|
|
68810
|
+
var documentPlugin = (kind, source) => {
|
|
68811
|
+
return () => {
|
|
68812
|
+
const sourceHandlers = source();
|
|
68813
|
+
const enterWrapper = (handler) => {
|
|
68814
|
+
return !handler ? void 0 : (ctx, handlers) => {
|
|
68815
|
+
if (ctx.artifact.kind !== kind) {
|
|
68816
|
+
return handlers.next(ctx);
|
|
68817
|
+
}
|
|
68818
|
+
return handler(ctx, handlers);
|
|
68819
|
+
};
|
|
68820
|
+
};
|
|
68821
|
+
const exitWrapper = (handler) => {
|
|
68822
|
+
return !handler ? void 0 : (ctx, handlers) => {
|
|
68823
|
+
if (ctx.artifact.kind !== kind) {
|
|
68824
|
+
return handlers.resolve(ctx);
|
|
68825
|
+
}
|
|
68826
|
+
return handler(ctx, handlers);
|
|
68827
|
+
};
|
|
68828
|
+
};
|
|
68829
|
+
return {
|
|
68830
|
+
start: enterWrapper(sourceHandlers.start),
|
|
68831
|
+
network: enterWrapper(sourceHandlers.network),
|
|
68832
|
+
afterNetwork: exitWrapper(sourceHandlers.afterNetwork),
|
|
68833
|
+
end: exitWrapper(sourceHandlers.end),
|
|
68834
|
+
catch: sourceHandlers.catch ? (ctx, handlers) => sourceHandlers.catch(ctx, handlers) : void 0,
|
|
68835
|
+
cleanup: (...args) => sourceHandlers.cleanup?.(...args)
|
|
68836
|
+
};
|
|
68837
|
+
};
|
|
68838
|
+
};
|
|
68839
|
+
|
|
68840
|
+
// src/runtime/client/plugins/query.ts
|
|
68841
|
+
var query = documentPlugin(ArtifactKind.Query, function() {
|
|
68842
|
+
let subscriptionSpec = null;
|
|
68843
|
+
let lastVariables = null;
|
|
68844
|
+
let artifactName = "";
|
|
68845
|
+
return {
|
|
68846
|
+
start(ctx, { next }) {
|
|
68847
|
+
ctx.variables = {
|
|
68848
|
+
...lastVariables,
|
|
68849
|
+
...ctx.variables
|
|
68850
|
+
};
|
|
68851
|
+
next(ctx);
|
|
68852
|
+
},
|
|
68853
|
+
end(ctx, { resolve: resolve2, marshalVariables, variablesChanged }) {
|
|
68854
|
+
if (variablesChanged(ctx)) {
|
|
68855
|
+
artifactName = ctx.artifact.name;
|
|
68856
|
+
if (subscriptionSpec) {
|
|
68857
|
+
cache_default.unsubscribe(subscriptionSpec, subscriptionSpec.variables?.() || {});
|
|
68858
|
+
}
|
|
68859
|
+
lastVariables = { ...marshalVariables(ctx) };
|
|
68860
|
+
subscriptionSpec = {
|
|
68861
|
+
rootType: ctx.artifact.rootType,
|
|
68862
|
+
selection: ctx.artifact.selection,
|
|
68863
|
+
variables: () => lastVariables,
|
|
68864
|
+
set: (newValue) => {
|
|
68865
|
+
resolve2(ctx, {
|
|
68866
|
+
data: newValue,
|
|
68867
|
+
errors: null,
|
|
68868
|
+
fetching: false,
|
|
68869
|
+
partial: false,
|
|
68870
|
+
stale: false,
|
|
68871
|
+
source: DataSource.Cache,
|
|
68872
|
+
variables: ctx.variables ?? null
|
|
68873
|
+
});
|
|
68874
|
+
}
|
|
68875
|
+
};
|
|
68876
|
+
cache_default.subscribe(subscriptionSpec, lastVariables ?? {});
|
|
68877
|
+
}
|
|
68878
|
+
resolve2(ctx);
|
|
68879
|
+
},
|
|
68880
|
+
cleanup() {
|
|
68881
|
+
if (subscriptionSpec) {
|
|
68882
|
+
cache_default.unsubscribe(subscriptionSpec, subscriptionSpec.variables?.() ?? {});
|
|
68883
|
+
lastVariables = null;
|
|
68884
|
+
}
|
|
68885
|
+
}
|
|
68886
|
+
};
|
|
68887
|
+
});
|
|
68888
|
+
|
|
68889
|
+
// src/runtime/client/plugins/mutation.ts
|
|
68890
|
+
var mutation = documentPlugin(ArtifactKind.Mutation, () => {
|
|
68891
|
+
return {
|
|
68892
|
+
async start(ctx, { next, marshalVariables }) {
|
|
68893
|
+
const layer = cache_default._internal_unstable.storage.createLayer(true);
|
|
68894
|
+
const optimisticResponse = ctx.stuff.optimisticResponse;
|
|
68895
|
+
let toNotify = [];
|
|
68896
|
+
if (optimisticResponse) {
|
|
68897
|
+
toNotify = cache_default.write({
|
|
68898
|
+
selection: ctx.artifact.selection,
|
|
68899
|
+
data: await marshalSelection({
|
|
68900
|
+
selection: ctx.artifact.selection,
|
|
68901
|
+
data: optimisticResponse
|
|
68902
|
+
}),
|
|
68903
|
+
variables: marshalVariables(ctx),
|
|
68904
|
+
layer: layer.id
|
|
68905
|
+
});
|
|
68906
|
+
}
|
|
68907
|
+
ctx.cacheParams = {
|
|
68908
|
+
...ctx.cacheParams,
|
|
68909
|
+
layer,
|
|
68910
|
+
notifySubscribers: toNotify,
|
|
68911
|
+
forceNotify: true
|
|
68912
|
+
};
|
|
68913
|
+
next(ctx);
|
|
68914
|
+
},
|
|
68915
|
+
afterNetwork(ctx, { resolve: resolve2 }) {
|
|
68916
|
+
ctx.cacheParams?.layer?.clear();
|
|
68917
|
+
resolve2(ctx);
|
|
68918
|
+
},
|
|
68919
|
+
end(ctx, { resolve: resolve2, value }) {
|
|
68920
|
+
const hasErrors = value.errors && value.errors.length > 0;
|
|
68921
|
+
if (hasErrors) {
|
|
68922
|
+
ctx.cacheParams?.layer?.clear();
|
|
68923
|
+
}
|
|
68924
|
+
if (ctx.cacheParams?.layer) {
|
|
68925
|
+
cache_default._internal_unstable.storage.resolveLayer(ctx.cacheParams.layer.id);
|
|
68926
|
+
}
|
|
68927
|
+
resolve2(ctx);
|
|
68928
|
+
},
|
|
68929
|
+
catch(ctx, { error }) {
|
|
68930
|
+
if (ctx.cacheParams?.layer) {
|
|
68931
|
+
const { layer } = ctx.cacheParams;
|
|
68932
|
+
layer.clear();
|
|
68933
|
+
cache_default._internal_unstable.storage.resolveLayer(layer.id);
|
|
68934
|
+
}
|
|
68935
|
+
throw error;
|
|
68936
|
+
}
|
|
68937
|
+
};
|
|
68938
|
+
});
|
|
68939
|
+
|
|
66819
68940
|
// src/lib/types.ts
|
|
66820
68941
|
var LogLevel = {
|
|
66821
68942
|
Full: "full",
|
|
@@ -67253,8 +69374,10 @@ var Config = class {
|
|
|
67253
69374
|
return node.name.value === "CachePolicy";
|
|
67254
69375
|
}
|
|
67255
69376
|
isInternalDirective(name) {
|
|
67256
|
-
const internalDirectives = this.#newSchemaInstance?.getDirectives().
|
|
67257
|
-
|
|
69377
|
+
const internalDirectives = this.#newSchemaInstance?.getDirectives().reduce((list, directive) => {
|
|
69378
|
+
return list.concat(directive.name);
|
|
69379
|
+
}, []) ?? [];
|
|
69380
|
+
return !defaultDirectives.includes(name) && (internalDirectives.includes(name) || this.isDeleteDirective(name));
|
|
67258
69381
|
}
|
|
67259
69382
|
isListFragment(name) {
|
|
67260
69383
|
return name.endsWith(this.insertFragmentSuffix) || name.endsWith(this.removeFragmentSuffix) || name.endsWith(this.toggleFragmentSuffix);
|
|
@@ -67361,7 +69484,13 @@ async function getConfig({
|
|
|
67361
69484
|
const plugins = pluginsNested.flat();
|
|
67362
69485
|
for (const plugin2 of plugins) {
|
|
67363
69486
|
if (plugin2.config) {
|
|
67364
|
-
|
|
69487
|
+
try {
|
|
69488
|
+
const configFactory = await import(plugin2.config);
|
|
69489
|
+
const newValue = typeof configFactory === "function" ? configFactory(configFile) : configFactory;
|
|
69490
|
+
configFile = deepMerge(configPath, configFile, newValue);
|
|
69491
|
+
} catch {
|
|
69492
|
+
console.log("could not load config file" + plugin2.config);
|
|
69493
|
+
}
|
|
67365
69494
|
}
|
|
67366
69495
|
}
|
|
67367
69496
|
_config = new Config({
|
|
@@ -67519,6 +69648,8 @@ async function loadSchemaFile(schemaPath) {
|
|
|
67519
69648
|
}
|
|
67520
69649
|
return graphql2.buildClientSchema(jsonContents);
|
|
67521
69650
|
}
|
|
69651
|
+
var emptySchema = graphql2.buildSchema("type Query { hello: String }");
|
|
69652
|
+
var defaultDirectives = emptySchema.getDirectives().map((dir) => dir.name);
|
|
67522
69653
|
|
|
67523
69654
|
// src/lib/graphql.ts
|
|
67524
69655
|
var graphql3 = __toESM(require_graphql2(), 1);
|
|
@@ -70182,22 +72313,12 @@ function artifactGenerator(stats) {
|
|
|
70182
72313
|
document: doc
|
|
70183
72314
|
})
|
|
70184
72315
|
};
|
|
70185
|
-
|
|
70186
|
-
|
|
70187
|
-
|
|
70188
|
-
|
|
70189
|
-
|
|
70190
|
-
|
|
70191
|
-
const dataToAdd = plugin2.artifactData({ config: config4, document: doc }) ?? {};
|
|
70192
|
-
if (Object.keys(dataToAdd)) {
|
|
70193
|
-
result[plugin2.name] = dataToAdd;
|
|
70194
|
-
}
|
|
70195
|
-
return result;
|
|
70196
|
-
},
|
|
70197
|
-
{}
|
|
70198
|
-
);
|
|
70199
|
-
if (Object.keys(plugin_data).length > 0) {
|
|
70200
|
-
artifact.pluginData = plugin_data;
|
|
72316
|
+
artifact.pluginData = {};
|
|
72317
|
+
for (const plugin2 of config4.plugins) {
|
|
72318
|
+
if (!plugin2.artifactData) {
|
|
72319
|
+
continue;
|
|
72320
|
+
}
|
|
72321
|
+
artifact.pluginData[plugin2.name] = plugin2.artifactData({ config: config4, document: doc }) ?? {};
|
|
70201
72322
|
}
|
|
70202
72323
|
if (inputs && inputs.length > 0) {
|
|
70203
72324
|
artifact.input = inputObject(config4, inputs);
|
|
@@ -70371,6 +72492,30 @@ async function generatePluginIndex({
|
|
|
70371
72492
|
]);
|
|
70372
72493
|
}
|
|
70373
72494
|
|
|
72495
|
+
// src/codegen/generators/runtime/runtimeConfig.ts
|
|
72496
|
+
async function injectConfig({
|
|
72497
|
+
config: config4,
|
|
72498
|
+
content,
|
|
72499
|
+
importStatement,
|
|
72500
|
+
exportStatement
|
|
72501
|
+
}) {
|
|
72502
|
+
const extraConfigs = config4.plugins.reduce((acc, plugin2) => {
|
|
72503
|
+
if (!plugin2.config) {
|
|
72504
|
+
return acc;
|
|
72505
|
+
}
|
|
72506
|
+
return [...acc, plugin2.config];
|
|
72507
|
+
}, []);
|
|
72508
|
+
return extraConfigs.length > 0 ? `
|
|
72509
|
+
${extraConfigs.map((plugin2, i2) => importStatement(plugin2, `plugin${i2}`))}
|
|
72510
|
+
|
|
72511
|
+
const plugins = [
|
|
72512
|
+
${extraConfigs.map((_, i2) => `plugin${i2}`).join(",\n")}
|
|
72513
|
+
]
|
|
72514
|
+
|
|
72515
|
+
${exportStatement("plugins")}
|
|
72516
|
+
` : content;
|
|
72517
|
+
}
|
|
72518
|
+
|
|
70374
72519
|
// src/codegen/generators/runtime/index.ts
|
|
70375
72520
|
async function runtimeGenerator(config4, docs) {
|
|
70376
72521
|
const importStatement = config4.module === "commonjs" ? importDefaultFrom : (where, as) => `import ${as} from '${where}'`;
|
|
@@ -70381,6 +72526,9 @@ async function runtimeGenerator(config4, docs) {
|
|
|
70381
72526
|
[path_exports.join(config4.runtimeSource, "lib", "constants.js")]: (content) => {
|
|
70382
72527
|
return content.replace("SITE_URL", siteURL);
|
|
70383
72528
|
},
|
|
72529
|
+
[path_exports.join(config4.runtimeSource, "imports", "pluginConfig.js")]: (content) => {
|
|
72530
|
+
return injectConfig({ config: config4, importStatement, exportStatement, content });
|
|
72531
|
+
},
|
|
70384
72532
|
[path_exports.join(config4.runtimeSource, "imports", "config.js")]: (content) => {
|
|
70385
72533
|
const configFilePath = path_exports.join(config4.runtimeDirectory, "imports", "config.js");
|
|
70386
72534
|
const relativePath = path_exports.relative(path_exports.dirname(configFilePath), config4.filepath);
|
|
@@ -71608,13 +73756,19 @@ async function definitionsGenerator(config4) {
|
|
|
71608
73756
|
})
|
|
71609
73757
|
)
|
|
71610
73758
|
).code;
|
|
71611
|
-
const typeDefinitions2 =
|
|
71612
|
-
|
|
71613
|
-
|
|
71614
|
-
|
|
71615
|
-
|
|
71616
|
-
`
|
|
71617
|
-
|
|
73759
|
+
const typeDefinitions2 = `
|
|
73760
|
+
type ValuesOf<T> = T[keyof T]
|
|
73761
|
+
` + enums.sort((a, b) => a.name.value.localeCompare(b.name.value)).map((definition) => {
|
|
73762
|
+
const name = definition.name.value;
|
|
73763
|
+
const values = definition.values;
|
|
73764
|
+
return `
|
|
73765
|
+
export declare const ${name}: {
|
|
73766
|
+
${values?.map((value) => ` readonly ${value.name.value}: "${value.name.value}";`).join("\n")}
|
|
73767
|
+
}
|
|
73768
|
+
|
|
73769
|
+
export type ${name}$options = ValuesOf<typeof ${name}>
|
|
73770
|
+
`;
|
|
73771
|
+
}).join("");
|
|
71618
73772
|
const definitionsIndex = `
|
|
71619
73773
|
export * from './enums.js'
|
|
71620
73774
|
`;
|