@tinacms/graphql 1.5.12 → 1.5.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/database/datalayer.d.ts +5 -1
- package/dist/database/index.d.ts +2 -0
- package/dist/index.js +319 -120
- package/dist/index.mjs +310 -115
- package/dist/resolver/index.d.ts +12 -1
- package/package.json +14 -14
package/dist/index.mjs
CHANGED
|
@@ -3019,7 +3019,7 @@ var validateField = async (field) => {
|
|
|
3019
3019
|
// package.json
|
|
3020
3020
|
var package_default = {
|
|
3021
3021
|
name: "@tinacms/graphql",
|
|
3022
|
-
version: "1.5.
|
|
3022
|
+
version: "1.5.14",
|
|
3023
3023
|
main: "dist/index.js",
|
|
3024
3024
|
module: "dist/index.mjs",
|
|
3025
3025
|
typings: "dist/index.d.ts",
|
|
@@ -3055,12 +3055,12 @@ var package_default = {
|
|
|
3055
3055
|
"@tinacms/schema-tools": "workspace:*",
|
|
3056
3056
|
"abstract-level": "^1.0.4",
|
|
3057
3057
|
"date-fns": "^2.30.0",
|
|
3058
|
-
"fast-glob": "^3.3.
|
|
3059
|
-
"fs-extra": "^11.
|
|
3058
|
+
"fast-glob": "^3.3.3",
|
|
3059
|
+
"fs-extra": "^11.3.0",
|
|
3060
3060
|
"glob-parent": "^6.0.2",
|
|
3061
3061
|
graphql: "15.8.0",
|
|
3062
3062
|
"gray-matter": "^4.0.3",
|
|
3063
|
-
"isomorphic-git": "^1.
|
|
3063
|
+
"isomorphic-git": "^1.29.0",
|
|
3064
3064
|
"js-sha1": "^0.6.0",
|
|
3065
3065
|
"js-yaml": "^3.14.1",
|
|
3066
3066
|
"jsonpath-plus": "10.1.0",
|
|
@@ -3070,7 +3070,7 @@ var package_default = {
|
|
|
3070
3070
|
"many-level": "^2.0.0",
|
|
3071
3071
|
micromatch: "4.0.8",
|
|
3072
3072
|
"normalize-path": "^3.0.0",
|
|
3073
|
-
"readable-stream": "^4.
|
|
3073
|
+
"readable-stream": "^4.7.0",
|
|
3074
3074
|
scmp: "^2.1.0",
|
|
3075
3075
|
yup: "^0.32.11"
|
|
3076
3076
|
},
|
|
@@ -3094,17 +3094,17 @@ var package_default = {
|
|
|
3094
3094
|
"@types/lru-cache": "^5.1.1",
|
|
3095
3095
|
"@types/mdast": "^3.0.15",
|
|
3096
3096
|
"@types/micromatch": "^4.0.9",
|
|
3097
|
-
"@types/node": "^22.
|
|
3097
|
+
"@types/node": "^22.13.1",
|
|
3098
3098
|
"@types/normalize-path": "^3.0.2",
|
|
3099
3099
|
"@types/ws": "^7.4.7",
|
|
3100
3100
|
"@types/yup": "^0.29.14",
|
|
3101
3101
|
"jest-file-snapshot": "^0.5.0",
|
|
3102
3102
|
"memory-level": "^1.0.0",
|
|
3103
3103
|
nodemon: "3.1.4",
|
|
3104
|
-
typescript: "^5.
|
|
3105
|
-
vite: "^4.
|
|
3106
|
-
vitest: "^0.32.
|
|
3107
|
-
zod: "^3.
|
|
3104
|
+
typescript: "^5.7.3",
|
|
3105
|
+
vite: "^4.5.9",
|
|
3106
|
+
vitest: "^0.32.4",
|
|
3107
|
+
zod: "^3.24.2"
|
|
3108
3108
|
}
|
|
3109
3109
|
};
|
|
3110
3110
|
|
|
@@ -3960,6 +3960,9 @@ var loadAndParseWithAliases = async (bridge, filepath, collection, templateInfo)
|
|
|
3960
3960
|
|
|
3961
3961
|
// src/database/datalayer.ts
|
|
3962
3962
|
var DEFAULT_COLLECTION_SORT_KEY = "__filepath__";
|
|
3963
|
+
var REFS_COLLECTIONS_SORT_KEY = "__refs__";
|
|
3964
|
+
var REFS_REFERENCE_FIELD = "__tina_ref__";
|
|
3965
|
+
var REFS_PATH_FIELD = "__tina_ref_path__";
|
|
3963
3966
|
var DEFAULT_NUMERIC_LPAD = 4;
|
|
3964
3967
|
var applyPadding = (input, pad) => {
|
|
3965
3968
|
if (pad) {
|
|
@@ -4533,6 +4536,57 @@ var makeIndexOpsForDocument = (filepath, collection, indexDefinitions, data, opT
|
|
|
4533
4536
|
}
|
|
4534
4537
|
return result;
|
|
4535
4538
|
};
|
|
4539
|
+
var makeRefOpsForDocument = (filepath, collection, references, data, opType, level) => {
|
|
4540
|
+
const result = [];
|
|
4541
|
+
if (collection) {
|
|
4542
|
+
for (const [c, referencePaths] of Object.entries(references || {})) {
|
|
4543
|
+
if (!referencePaths.length) {
|
|
4544
|
+
continue;
|
|
4545
|
+
}
|
|
4546
|
+
const collectionSublevel = level.sublevel(c, SUBLEVEL_OPTIONS);
|
|
4547
|
+
const refSublevel = collectionSublevel.sublevel(
|
|
4548
|
+
REFS_COLLECTIONS_SORT_KEY,
|
|
4549
|
+
SUBLEVEL_OPTIONS
|
|
4550
|
+
);
|
|
4551
|
+
const references2 = {};
|
|
4552
|
+
for (const path7 of referencePaths) {
|
|
4553
|
+
const ref = JSONPath({ path: path7, json: data });
|
|
4554
|
+
if (!ref) {
|
|
4555
|
+
continue;
|
|
4556
|
+
}
|
|
4557
|
+
if (Array.isArray(ref)) {
|
|
4558
|
+
for (const r of ref) {
|
|
4559
|
+
if (!r) {
|
|
4560
|
+
continue;
|
|
4561
|
+
}
|
|
4562
|
+
if (references2[r]) {
|
|
4563
|
+
references2[r].push(path7);
|
|
4564
|
+
} else {
|
|
4565
|
+
references2[r] = [path7];
|
|
4566
|
+
}
|
|
4567
|
+
}
|
|
4568
|
+
} else {
|
|
4569
|
+
if (references2[ref]) {
|
|
4570
|
+
references2[ref].push(path7);
|
|
4571
|
+
} else {
|
|
4572
|
+
references2[ref] = [path7];
|
|
4573
|
+
}
|
|
4574
|
+
}
|
|
4575
|
+
}
|
|
4576
|
+
for (const ref of Object.keys(references2)) {
|
|
4577
|
+
for (const path7 of references2[ref]) {
|
|
4578
|
+
result.push({
|
|
4579
|
+
type: opType,
|
|
4580
|
+
key: `${ref}${INDEX_KEY_FIELD_SEPARATOR}${path7}${INDEX_KEY_FIELD_SEPARATOR}${filepath}`,
|
|
4581
|
+
sublevel: refSublevel,
|
|
4582
|
+
value: opType === "put" ? {} : void 0
|
|
4583
|
+
});
|
|
4584
|
+
}
|
|
4585
|
+
}
|
|
4586
|
+
}
|
|
4587
|
+
}
|
|
4588
|
+
return result;
|
|
4589
|
+
};
|
|
4536
4590
|
var makeStringEscaper = (regex, replacement) => {
|
|
4537
4591
|
return (input) => {
|
|
4538
4592
|
if (Array.isArray(input)) {
|
|
@@ -4753,24 +4807,29 @@ var transformDocumentIntoPayload = async (fullPath, rawData, tinaSchema, config,
|
|
|
4753
4807
|
throw e;
|
|
4754
4808
|
}
|
|
4755
4809
|
};
|
|
4756
|
-
var updateObjectWithJsonPath = (obj, path7, newValue) => {
|
|
4810
|
+
var updateObjectWithJsonPath = (obj, path7, oldValue, newValue) => {
|
|
4811
|
+
let updated = false;
|
|
4757
4812
|
if (!path7.includes(".") && !path7.includes("[")) {
|
|
4758
|
-
if (path7 in obj) {
|
|
4813
|
+
if (path7 in obj && obj[path7] === oldValue) {
|
|
4759
4814
|
obj[path7] = newValue;
|
|
4815
|
+
updated = true;
|
|
4760
4816
|
}
|
|
4761
|
-
return obj;
|
|
4817
|
+
return { object: obj, updated };
|
|
4762
4818
|
}
|
|
4763
|
-
const parentPath = path7.replace(/\.[
|
|
4764
|
-
const keyToUpdate = path7.match(/[
|
|
4819
|
+
const parentPath = path7.replace(/\.[^.\[\]]+$/, "");
|
|
4820
|
+
const keyToUpdate = path7.match(/[^.\[\]]+$/)[0];
|
|
4765
4821
|
const parents = JSONPath2({ path: parentPath, json: obj, resultType: "value" });
|
|
4766
4822
|
if (parents.length > 0) {
|
|
4767
4823
|
parents.forEach((parent) => {
|
|
4768
4824
|
if (parent && typeof parent === "object" && keyToUpdate in parent) {
|
|
4769
|
-
parent[keyToUpdate]
|
|
4825
|
+
if (parent[keyToUpdate] === oldValue) {
|
|
4826
|
+
parent[keyToUpdate] = newValue;
|
|
4827
|
+
updated = true;
|
|
4828
|
+
}
|
|
4770
4829
|
}
|
|
4771
4830
|
});
|
|
4772
4831
|
}
|
|
4773
|
-
return obj;
|
|
4832
|
+
return { object: obj, updated };
|
|
4774
4833
|
};
|
|
4775
4834
|
var Resolver = class {
|
|
4776
4835
|
constructor(init) {
|
|
@@ -5148,17 +5207,35 @@ var Resolver = class {
|
|
|
5148
5207
|
await this.deleteDocument(realPath);
|
|
5149
5208
|
if (await this.hasReferences(realPath, collection)) {
|
|
5150
5209
|
const collRefs = await this.findReferences(realPath, collection);
|
|
5151
|
-
for (const [collection2,
|
|
5152
|
-
for (const [
|
|
5153
|
-
|
|
5154
|
-
|
|
5155
|
-
|
|
5210
|
+
for (const [collection2, docsWithRefs] of Object.entries(collRefs)) {
|
|
5211
|
+
for (const [pathToDocWithRef, referencePaths] of Object.entries(
|
|
5212
|
+
docsWithRefs
|
|
5213
|
+
)) {
|
|
5214
|
+
let refDoc = await this.getRaw(pathToDocWithRef);
|
|
5215
|
+
let hasUpdate = false;
|
|
5216
|
+
for (const path7 of referencePaths) {
|
|
5217
|
+
const { object: object2, updated } = updateObjectWithJsonPath(
|
|
5156
5218
|
refDoc,
|
|
5157
|
-
|
|
5219
|
+
path7,
|
|
5220
|
+
realPath,
|
|
5158
5221
|
null
|
|
5159
5222
|
);
|
|
5223
|
+
refDoc = object2;
|
|
5224
|
+
hasUpdate = updated || hasUpdate;
|
|
5225
|
+
}
|
|
5226
|
+
if (hasUpdate) {
|
|
5227
|
+
const collectionWithRef = this.tinaSchema.getCollectionByFullPath(pathToDocWithRef);
|
|
5228
|
+
if (!collectionWithRef) {
|
|
5229
|
+
throw new Error(
|
|
5230
|
+
`Unable to find collection for ${pathToDocWithRef}`
|
|
5231
|
+
);
|
|
5232
|
+
}
|
|
5233
|
+
await this.database.put(
|
|
5234
|
+
pathToDocWithRef,
|
|
5235
|
+
refDoc,
|
|
5236
|
+
collectionWithRef.name
|
|
5237
|
+
);
|
|
5160
5238
|
}
|
|
5161
|
-
await this.database.put(refPath, refDoc, collection2);
|
|
5162
5239
|
}
|
|
5163
5240
|
}
|
|
5164
5241
|
}
|
|
@@ -5178,20 +5255,41 @@ var Resolver = class {
|
|
|
5178
5255
|
collection?.path,
|
|
5179
5256
|
args.params.relativePath
|
|
5180
5257
|
);
|
|
5258
|
+
if (newRealPath === realPath) {
|
|
5259
|
+
return doc;
|
|
5260
|
+
}
|
|
5181
5261
|
await this.database.put(newRealPath, doc._rawData, collection.name);
|
|
5182
5262
|
await this.deleteDocument(realPath);
|
|
5183
5263
|
const collRefs = await this.findReferences(realPath, collection);
|
|
5184
|
-
for (const [collection2,
|
|
5185
|
-
for (const [
|
|
5186
|
-
|
|
5187
|
-
|
|
5188
|
-
|
|
5189
|
-
|
|
5190
|
-
|
|
5264
|
+
for (const [collection2, docsWithRefs] of Object.entries(collRefs)) {
|
|
5265
|
+
for (const [pathToDocWithRef, referencePaths] of Object.entries(
|
|
5266
|
+
docsWithRefs
|
|
5267
|
+
)) {
|
|
5268
|
+
let docWithRef = await this.getRaw(pathToDocWithRef);
|
|
5269
|
+
let hasUpdate = false;
|
|
5270
|
+
for (const path7 of referencePaths) {
|
|
5271
|
+
const { object: object2, updated } = updateObjectWithJsonPath(
|
|
5272
|
+
docWithRef,
|
|
5273
|
+
path7,
|
|
5274
|
+
realPath,
|
|
5191
5275
|
newRealPath
|
|
5192
5276
|
);
|
|
5277
|
+
docWithRef = object2;
|
|
5278
|
+
hasUpdate = updated || hasUpdate;
|
|
5279
|
+
}
|
|
5280
|
+
if (hasUpdate) {
|
|
5281
|
+
const collectionWithRef = this.tinaSchema.getCollectionByFullPath(pathToDocWithRef);
|
|
5282
|
+
if (!collectionWithRef) {
|
|
5283
|
+
throw new Error(
|
|
5284
|
+
`Unable to find collection for ${pathToDocWithRef}`
|
|
5285
|
+
);
|
|
5286
|
+
}
|
|
5287
|
+
await this.database.put(
|
|
5288
|
+
pathToDocWithRef,
|
|
5289
|
+
docWithRef,
|
|
5290
|
+
collectionWithRef.name
|
|
5291
|
+
);
|
|
5193
5292
|
}
|
|
5194
|
-
await this.database.put(refPath, refDoc, collection2);
|
|
5195
5293
|
}
|
|
5196
5294
|
}
|
|
5197
5295
|
return this.getDocument(newRealPath);
|
|
@@ -5323,35 +5421,30 @@ var Resolver = class {
|
|
|
5323
5421
|
*/
|
|
5324
5422
|
this.hasReferences = async (id, c) => {
|
|
5325
5423
|
let count = 0;
|
|
5326
|
-
|
|
5327
|
-
|
|
5328
|
-
|
|
5329
|
-
|
|
5330
|
-
|
|
5331
|
-
|
|
5332
|
-
|
|
5333
|
-
|
|
5334
|
-
|
|
5335
|
-
|
|
5336
|
-
|
|
5337
|
-
|
|
5338
|
-
|
|
5339
|
-
|
|
5340
|
-
|
|
5341
|
-
|
|
5342
|
-
|
|
5343
|
-
|
|
5344
|
-
|
|
5345
|
-
|
|
5346
|
-
(refId) => {
|
|
5347
|
-
count++;
|
|
5348
|
-
return refId;
|
|
5349
|
-
}
|
|
5350
|
-
);
|
|
5351
|
-
if (count) {
|
|
5352
|
-
return true;
|
|
5353
|
-
}
|
|
5424
|
+
await this.database.query(
|
|
5425
|
+
{
|
|
5426
|
+
collection: c.name,
|
|
5427
|
+
filterChain: makeFilterChain({
|
|
5428
|
+
conditions: [
|
|
5429
|
+
{
|
|
5430
|
+
filterPath: REFS_REFERENCE_FIELD,
|
|
5431
|
+
filterExpression: {
|
|
5432
|
+
_type: "string",
|
|
5433
|
+
_list: false,
|
|
5434
|
+
eq: id
|
|
5435
|
+
}
|
|
5436
|
+
}
|
|
5437
|
+
]
|
|
5438
|
+
}),
|
|
5439
|
+
sort: REFS_COLLECTIONS_SORT_KEY
|
|
5440
|
+
},
|
|
5441
|
+
(refId) => {
|
|
5442
|
+
count++;
|
|
5443
|
+
return refId;
|
|
5354
5444
|
}
|
|
5445
|
+
);
|
|
5446
|
+
if (count) {
|
|
5447
|
+
return true;
|
|
5355
5448
|
}
|
|
5356
5449
|
return false;
|
|
5357
5450
|
};
|
|
@@ -5359,46 +5452,41 @@ var Resolver = class {
|
|
|
5359
5452
|
* Finds references to a document
|
|
5360
5453
|
* @param id the id of the document to find references to
|
|
5361
5454
|
* @param c the collection to find references in
|
|
5362
|
-
* @returns
|
|
5455
|
+
* @returns a map of references to the document
|
|
5363
5456
|
*/
|
|
5364
5457
|
this.findReferences = async (id, c) => {
|
|
5365
5458
|
const references = {};
|
|
5366
|
-
|
|
5367
|
-
|
|
5368
|
-
|
|
5369
|
-
|
|
5370
|
-
|
|
5371
|
-
|
|
5372
|
-
|
|
5373
|
-
|
|
5374
|
-
|
|
5375
|
-
|
|
5376
|
-
|
|
5377
|
-
|
|
5378
|
-
_list: false,
|
|
5379
|
-
eq: id
|
|
5380
|
-
}
|
|
5381
|
-
}
|
|
5382
|
-
]
|
|
5383
|
-
}),
|
|
5384
|
-
sort: ref.field.name
|
|
5385
|
-
},
|
|
5386
|
-
(refId) => {
|
|
5387
|
-
if (!references[collection]) {
|
|
5388
|
-
references[collection] = {};
|
|
5389
|
-
}
|
|
5390
|
-
if (!references[collection][refId]) {
|
|
5391
|
-
references[collection][refId] = [];
|
|
5459
|
+
await this.database.query(
|
|
5460
|
+
{
|
|
5461
|
+
collection: c.name,
|
|
5462
|
+
filterChain: makeFilterChain({
|
|
5463
|
+
conditions: [
|
|
5464
|
+
{
|
|
5465
|
+
filterPath: REFS_REFERENCE_FIELD,
|
|
5466
|
+
filterExpression: {
|
|
5467
|
+
_type: "string",
|
|
5468
|
+
_list: false,
|
|
5469
|
+
eq: id
|
|
5470
|
+
}
|
|
5392
5471
|
}
|
|
5393
|
-
|
|
5394
|
-
|
|
5395
|
-
|
|
5396
|
-
|
|
5397
|
-
|
|
5398
|
-
|
|
5399
|
-
|
|
5472
|
+
]
|
|
5473
|
+
}),
|
|
5474
|
+
sort: REFS_COLLECTIONS_SORT_KEY
|
|
5475
|
+
},
|
|
5476
|
+
(refId, rawItem) => {
|
|
5477
|
+
if (!references[c.name]) {
|
|
5478
|
+
references[c.name] = {};
|
|
5479
|
+
}
|
|
5480
|
+
if (!references[c.name][refId]) {
|
|
5481
|
+
references[c.name][refId] = [];
|
|
5482
|
+
}
|
|
5483
|
+
const referencePath = rawItem?.[REFS_PATH_FIELD];
|
|
5484
|
+
if (referencePath) {
|
|
5485
|
+
references[c.name][refId].push(referencePath);
|
|
5486
|
+
}
|
|
5487
|
+
return refId;
|
|
5400
5488
|
}
|
|
5401
|
-
|
|
5489
|
+
);
|
|
5402
5490
|
return references;
|
|
5403
5491
|
};
|
|
5404
5492
|
this.buildFieldMutations = async (fieldParams, template, existingData) => {
|
|
@@ -6142,6 +6230,7 @@ var Database = class {
|
|
|
6142
6230
|
);
|
|
6143
6231
|
const indexDefinitions = await this.getIndexDefinitions(this.contentLevel);
|
|
6144
6232
|
const collectionIndexDefinitions = indexDefinitions?.[collection.name];
|
|
6233
|
+
const collectionReferences = (await this.getCollectionReferences())?.[collection.name];
|
|
6145
6234
|
const normalizedPath = normalizePath(filepath);
|
|
6146
6235
|
if (!collection?.isDetached) {
|
|
6147
6236
|
if (this.bridge) {
|
|
@@ -6170,6 +6259,14 @@ var Database = class {
|
|
|
6170
6259
|
let delOps = [];
|
|
6171
6260
|
if (!isGitKeep(normalizedPath, collection)) {
|
|
6172
6261
|
putOps = [
|
|
6262
|
+
...makeRefOpsForDocument(
|
|
6263
|
+
normalizedPath,
|
|
6264
|
+
collection?.name,
|
|
6265
|
+
collectionReferences,
|
|
6266
|
+
dataFields,
|
|
6267
|
+
"put",
|
|
6268
|
+
level
|
|
6269
|
+
),
|
|
6173
6270
|
...makeIndexOpsForDocument(
|
|
6174
6271
|
normalizedPath,
|
|
6175
6272
|
collection?.name,
|
|
@@ -6193,6 +6290,14 @@ var Database = class {
|
|
|
6193
6290
|
SUBLEVEL_OPTIONS
|
|
6194
6291
|
).get(normalizedPath);
|
|
6195
6292
|
delOps = existingItem ? [
|
|
6293
|
+
...makeRefOpsForDocument(
|
|
6294
|
+
normalizedPath,
|
|
6295
|
+
collection?.name,
|
|
6296
|
+
collectionReferences,
|
|
6297
|
+
existingItem,
|
|
6298
|
+
"del",
|
|
6299
|
+
level
|
|
6300
|
+
),
|
|
6196
6301
|
...makeIndexOpsForDocument(
|
|
6197
6302
|
normalizedPath,
|
|
6198
6303
|
collection?.name,
|
|
@@ -6240,6 +6345,7 @@ var Database = class {
|
|
|
6240
6345
|
);
|
|
6241
6346
|
collectionIndexDefinitions = indexDefinitions?.[collectionName];
|
|
6242
6347
|
}
|
|
6348
|
+
const collectionReferences = (await this.getCollectionReferences())?.[collectionName];
|
|
6243
6349
|
const normalizedPath = normalizePath(filepath);
|
|
6244
6350
|
const dataFields = await this.formatBodyOnPayload(filepath, data);
|
|
6245
6351
|
const collection = await this.collectionForPath(filepath);
|
|
@@ -6287,6 +6393,14 @@ var Database = class {
|
|
|
6287
6393
|
let delOps = [];
|
|
6288
6394
|
if (!isGitKeep(normalizedPath, collection)) {
|
|
6289
6395
|
putOps = [
|
|
6396
|
+
...makeRefOpsForDocument(
|
|
6397
|
+
normalizedPath,
|
|
6398
|
+
collectionName,
|
|
6399
|
+
collectionReferences,
|
|
6400
|
+
dataFields,
|
|
6401
|
+
"put",
|
|
6402
|
+
level
|
|
6403
|
+
),
|
|
6290
6404
|
...makeIndexOpsForDocument(
|
|
6291
6405
|
normalizedPath,
|
|
6292
6406
|
collectionName,
|
|
@@ -6310,6 +6424,14 @@ var Database = class {
|
|
|
6310
6424
|
SUBLEVEL_OPTIONS
|
|
6311
6425
|
).get(normalizedPath);
|
|
6312
6426
|
delOps = existingItem ? [
|
|
6427
|
+
...makeRefOpsForDocument(
|
|
6428
|
+
normalizedPath,
|
|
6429
|
+
collectionName,
|
|
6430
|
+
collectionReferences,
|
|
6431
|
+
existingItem,
|
|
6432
|
+
"del",
|
|
6433
|
+
level
|
|
6434
|
+
),
|
|
6313
6435
|
...makeIndexOpsForDocument(
|
|
6314
6436
|
normalizedPath,
|
|
6315
6437
|
collectionName,
|
|
@@ -6472,6 +6594,22 @@ var Database = class {
|
|
|
6472
6594
|
this.tinaSchema = await createSchema({ schema });
|
|
6473
6595
|
return this.tinaSchema;
|
|
6474
6596
|
};
|
|
6597
|
+
this.getCollectionReferences = async (level) => {
|
|
6598
|
+
if (this.collectionReferences) {
|
|
6599
|
+
return this.collectionReferences;
|
|
6600
|
+
}
|
|
6601
|
+
const result = {};
|
|
6602
|
+
const schema = await this.getSchema(level || this.contentLevel);
|
|
6603
|
+
const collections = schema.getCollections();
|
|
6604
|
+
for (const collection of collections) {
|
|
6605
|
+
const collectionReferences = this.tinaSchema.findReferencesFromCollection(
|
|
6606
|
+
collection.name
|
|
6607
|
+
);
|
|
6608
|
+
result[collection.name] = collectionReferences;
|
|
6609
|
+
}
|
|
6610
|
+
this.collectionReferences = result;
|
|
6611
|
+
return result;
|
|
6612
|
+
};
|
|
6475
6613
|
this.getIndexDefinitions = async (level) => {
|
|
6476
6614
|
if (!this.collectionIndexDefinitions) {
|
|
6477
6615
|
await new Promise(async (resolve2, reject) => {
|
|
@@ -6481,8 +6619,23 @@ var Database = class {
|
|
|
6481
6619
|
const collections = schema.getCollections();
|
|
6482
6620
|
for (const collection of collections) {
|
|
6483
6621
|
const indexDefinitions = {
|
|
6484
|
-
[DEFAULT_COLLECTION_SORT_KEY]: { fields: [] }
|
|
6622
|
+
[DEFAULT_COLLECTION_SORT_KEY]: { fields: [] },
|
|
6485
6623
|
// provide a default sort key which is the file sort
|
|
6624
|
+
// pseudo-index for the collection's references
|
|
6625
|
+
[REFS_COLLECTIONS_SORT_KEY]: {
|
|
6626
|
+
fields: [
|
|
6627
|
+
{
|
|
6628
|
+
name: REFS_REFERENCE_FIELD,
|
|
6629
|
+
type: "string",
|
|
6630
|
+
list: false
|
|
6631
|
+
},
|
|
6632
|
+
{
|
|
6633
|
+
name: REFS_PATH_FIELD,
|
|
6634
|
+
type: "string",
|
|
6635
|
+
list: false
|
|
6636
|
+
}
|
|
6637
|
+
]
|
|
6638
|
+
}
|
|
6486
6639
|
};
|
|
6487
6640
|
if (collection.fields) {
|
|
6488
6641
|
for (const field of collection.fields) {
|
|
@@ -6633,29 +6786,36 @@ var Database = class {
|
|
|
6633
6786
|
}
|
|
6634
6787
|
startKey = startKey || key || "";
|
|
6635
6788
|
endKey = key || "";
|
|
6636
|
-
edges = [...edges, { cursor: key, path: filepath }];
|
|
6789
|
+
edges = [...edges, { cursor: key, path: filepath, value: itemRecord }];
|
|
6637
6790
|
}
|
|
6638
6791
|
return {
|
|
6639
|
-
edges: await sequential(
|
|
6640
|
-
|
|
6641
|
-
|
|
6642
|
-
|
|
6643
|
-
|
|
6644
|
-
|
|
6645
|
-
|
|
6646
|
-
|
|
6647
|
-
|
|
6648
|
-
|
|
6649
|
-
|
|
6650
|
-
|
|
6651
|
-
|
|
6652
|
-
|
|
6653
|
-
|
|
6654
|
-
|
|
6792
|
+
edges: await sequential(
|
|
6793
|
+
edges,
|
|
6794
|
+
async ({
|
|
6795
|
+
cursor,
|
|
6796
|
+
path: path7,
|
|
6797
|
+
value
|
|
6798
|
+
}) => {
|
|
6799
|
+
try {
|
|
6800
|
+
const node = await hydrator(path7, value);
|
|
6801
|
+
return {
|
|
6802
|
+
node,
|
|
6803
|
+
cursor: btoa(cursor)
|
|
6804
|
+
};
|
|
6805
|
+
} catch (error) {
|
|
6806
|
+
console.log(error);
|
|
6807
|
+
if (error instanceof Error && (!path7.includes(".tina/__generated__/_graphql.json") || !path7.includes("tina/__generated__/_graphql.json"))) {
|
|
6808
|
+
throw new TinaQueryError({
|
|
6809
|
+
originalError: error,
|
|
6810
|
+
file: path7,
|
|
6811
|
+
collection: collection.name,
|
|
6812
|
+
stack: error.stack
|
|
6813
|
+
});
|
|
6814
|
+
}
|
|
6815
|
+
throw error;
|
|
6655
6816
|
}
|
|
6656
|
-
throw error;
|
|
6657
6817
|
}
|
|
6658
|
-
|
|
6818
|
+
),
|
|
6659
6819
|
pageInfo: {
|
|
6660
6820
|
hasPreviousPage,
|
|
6661
6821
|
hasNextPage,
|
|
@@ -6801,6 +6961,7 @@ var Database = class {
|
|
|
6801
6961
|
throw new Error(`No collection found for path: ${filepath}`);
|
|
6802
6962
|
}
|
|
6803
6963
|
const indexDefinitions = await this.getIndexDefinitions(this.contentLevel);
|
|
6964
|
+
const collectionReferences = (await this.getCollectionReferences())?.[collection.name];
|
|
6804
6965
|
const collectionIndexDefinitions = indexDefinitions?.[collection.name];
|
|
6805
6966
|
let level = this.contentLevel;
|
|
6806
6967
|
if (collection?.isDetached) {
|
|
@@ -6819,6 +6980,14 @@ var Database = class {
|
|
|
6819
6980
|
collection.path || ""
|
|
6820
6981
|
);
|
|
6821
6982
|
await this.contentLevel.batch([
|
|
6983
|
+
...makeRefOpsForDocument(
|
|
6984
|
+
normalizedPath,
|
|
6985
|
+
collection.name,
|
|
6986
|
+
collectionReferences,
|
|
6987
|
+
item,
|
|
6988
|
+
"del",
|
|
6989
|
+
level
|
|
6990
|
+
),
|
|
6822
6991
|
...makeIndexOpsForDocument(
|
|
6823
6992
|
normalizedPath,
|
|
6824
6993
|
collection.name,
|
|
@@ -7046,6 +7215,7 @@ var _indexContent = async (database, level, documentPaths, enqueueOps, collectio
|
|
|
7046
7215
|
}
|
|
7047
7216
|
collectionPath = collection.path;
|
|
7048
7217
|
}
|
|
7218
|
+
const collectionReferences = (await database.getCollectionReferences())?.[collection?.name];
|
|
7049
7219
|
const tinaSchema = await database.getSchema();
|
|
7050
7220
|
let templateInfo = null;
|
|
7051
7221
|
if (collection) {
|
|
@@ -7078,6 +7248,14 @@ var _indexContent = async (database, level, documentPaths, enqueueOps, collectio
|
|
|
7078
7248
|
const item = await rootSublevel.get(normalizedPath);
|
|
7079
7249
|
if (item) {
|
|
7080
7250
|
await database.contentLevel.batch([
|
|
7251
|
+
...makeRefOpsForDocument(
|
|
7252
|
+
normalizedPath,
|
|
7253
|
+
collection?.name,
|
|
7254
|
+
collectionReferences,
|
|
7255
|
+
item,
|
|
7256
|
+
"del",
|
|
7257
|
+
level
|
|
7258
|
+
),
|
|
7081
7259
|
...makeIndexOpsForDocument(
|
|
7082
7260
|
normalizedPath,
|
|
7083
7261
|
collection.name,
|
|
@@ -7104,6 +7282,14 @@ var _indexContent = async (database, level, documentPaths, enqueueOps, collectio
|
|
|
7104
7282
|
}
|
|
7105
7283
|
if (!isGitKeep(filepath, collection)) {
|
|
7106
7284
|
await enqueueOps([
|
|
7285
|
+
...makeRefOpsForDocument(
|
|
7286
|
+
normalizedPath,
|
|
7287
|
+
collection?.name,
|
|
7288
|
+
collectionReferences,
|
|
7289
|
+
aliasedData,
|
|
7290
|
+
"put",
|
|
7291
|
+
level
|
|
7292
|
+
),
|
|
7107
7293
|
...makeIndexOpsForDocument(
|
|
7108
7294
|
normalizedPath,
|
|
7109
7295
|
collection?.name,
|
|
@@ -7167,6 +7353,7 @@ var _deleteIndexContent = async (database, documentPaths, enqueueOps, collection
|
|
|
7167
7353
|
throw new Error(`No indexDefinitions for collection ${collection.name}`);
|
|
7168
7354
|
}
|
|
7169
7355
|
}
|
|
7356
|
+
const collectionReferences = (await database.getCollectionReferences())?.[collection?.name];
|
|
7170
7357
|
const tinaSchema = await database.getSchema();
|
|
7171
7358
|
let templateInfo = null;
|
|
7172
7359
|
if (collection) {
|
|
@@ -7190,6 +7377,14 @@ var _deleteIndexContent = async (database, documentPaths, enqueueOps, collection
|
|
|
7190
7377
|
item
|
|
7191
7378
|
) : item;
|
|
7192
7379
|
await enqueueOps([
|
|
7380
|
+
...makeRefOpsForDocument(
|
|
7381
|
+
itemKey,
|
|
7382
|
+
collection?.name,
|
|
7383
|
+
collectionReferences,
|
|
7384
|
+
aliasedData,
|
|
7385
|
+
"del",
|
|
7386
|
+
database.contentLevel
|
|
7387
|
+
),
|
|
7193
7388
|
...makeIndexOpsForDocument(
|
|
7194
7389
|
itemKey,
|
|
7195
7390
|
collection.name,
|
package/dist/resolver/index.d.ts
CHANGED
|
@@ -40,6 +40,17 @@ export declare const transformDocumentIntoPayload: (fullPath: string, rawData: {
|
|
|
40
40
|
__typename: string;
|
|
41
41
|
id: string;
|
|
42
42
|
}>;
|
|
43
|
+
/**
|
|
44
|
+
* Updates a property in an object using a JSONPath.
|
|
45
|
+
* @param obj - The object to update.
|
|
46
|
+
* @param path - The JSONPath string.
|
|
47
|
+
* @param newValue - The new value to set at the specified path.
|
|
48
|
+
* @returns the updated object.
|
|
49
|
+
*/
|
|
50
|
+
export declare const updateObjectWithJsonPath: (obj: any, path: string, oldValue: any, newValue: any) => {
|
|
51
|
+
object: any;
|
|
52
|
+
updated: boolean;
|
|
53
|
+
};
|
|
43
54
|
/**
|
|
44
55
|
* The resolver provides functions for all possible types of lookup
|
|
45
56
|
* values and retrieves them from the database
|
|
@@ -346,7 +357,7 @@ export declare class Resolver {
|
|
|
346
357
|
* Finds references to a document
|
|
347
358
|
* @param id the id of the document to find references to
|
|
348
359
|
* @param c the collection to find references in
|
|
349
|
-
* @returns
|
|
360
|
+
* @returns a map of references to the document
|
|
350
361
|
*/
|
|
351
362
|
private findReferences;
|
|
352
363
|
private buildFieldMutations;
|