@tinacms/graphql 0.0.0-20230922170629 → 0.0.0-20230922192012
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/builder/static-definitions.d.ts +0 -1
- package/dist/index.js +41 -42
- package/dist/index.mjs +40 -42
- package/dist/resolver/index.d.ts +5 -0
- package/package.json +7 -7
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
/**
|
|
2
2
|
|
|
3
3
|
*/
|
|
4
|
-
export declare const sysFilter: import("graphql").InputValueDefinitionNode;
|
|
5
4
|
export declare const staticDefinitions: (import("graphql").ScalarTypeDefinitionNode | import("graphql").ObjectTypeDefinitionNode | import("graphql").InterfaceTypeDefinitionNode[])[];
|
package/dist/index.js
CHANGED
|
@@ -1322,34 +1322,7 @@ var scalarDefinitions = [
|
|
|
1322
1322
|
]
|
|
1323
1323
|
})
|
|
1324
1324
|
];
|
|
1325
|
-
var
|
|
1326
|
-
name: "_sys",
|
|
1327
|
-
type: astBuilder.InputObjectTypeDefinition({
|
|
1328
|
-
name: `SysFilter`,
|
|
1329
|
-
fields: [
|
|
1330
|
-
astBuilder.InputValueDefinition({
|
|
1331
|
-
name: "relativePath",
|
|
1332
|
-
type: astBuilder.InputObjectTypeDefinition({
|
|
1333
|
-
name: "SysFilterOperations",
|
|
1334
|
-
fields: [
|
|
1335
|
-
astBuilder.InputValueDefinition({
|
|
1336
|
-
name: "startsWith",
|
|
1337
|
-
type: astBuilder.TYPES.String
|
|
1338
|
-
}),
|
|
1339
|
-
astBuilder.InputValueDefinition({
|
|
1340
|
-
name: "eq",
|
|
1341
|
-
type: astBuilder.TYPES.String
|
|
1342
|
-
})
|
|
1343
|
-
]
|
|
1344
|
-
})
|
|
1345
|
-
})
|
|
1346
|
-
]
|
|
1347
|
-
})
|
|
1348
|
-
});
|
|
1349
|
-
var staticDefinitions = [
|
|
1350
|
-
...scalarDefinitions,
|
|
1351
|
-
interfaceDefinitions
|
|
1352
|
-
];
|
|
1325
|
+
var staticDefinitions = [...scalarDefinitions, interfaceDefinitions];
|
|
1353
1326
|
|
|
1354
1327
|
// src/builder/index.ts
|
|
1355
1328
|
var createBuilder = async ({
|
|
@@ -1619,10 +1592,6 @@ var Builder = class {
|
|
|
1619
1592
|
this._getCollectionFragmentSelections = async (collection, depth) => {
|
|
1620
1593
|
var _a;
|
|
1621
1594
|
const selections = [];
|
|
1622
|
-
selections.push({
|
|
1623
|
-
name: { kind: "Name", value: "__typename" },
|
|
1624
|
-
kind: "Field"
|
|
1625
|
-
});
|
|
1626
1595
|
if (((_a = collection.fields) == null ? void 0 : _a.length) > 0) {
|
|
1627
1596
|
await sequential(collection.fields, async (x) => {
|
|
1628
1597
|
const field = await this._buildFieldNodeForFragments(x, depth);
|
|
@@ -1886,7 +1855,7 @@ var Builder = class {
|
|
|
1886
1855
|
});
|
|
1887
1856
|
return astBuilder.InputObjectTypeDefinition({
|
|
1888
1857
|
name: NAMER.dataFilterTypeName(template.namespace),
|
|
1889
|
-
fields
|
|
1858
|
+
fields
|
|
1890
1859
|
});
|
|
1891
1860
|
};
|
|
1892
1861
|
this._updateCollectionDocumentMutationType = async (collection) => {
|
|
@@ -2246,14 +2215,12 @@ var Builder = class {
|
|
|
2246
2215
|
name: "filter",
|
|
2247
2216
|
type: astBuilder.InputObjectTypeDefinition({
|
|
2248
2217
|
name: NAMER.dataFilterTypeName(namespace),
|
|
2249
|
-
fields:
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
})
|
|
2256
|
-
]
|
|
2218
|
+
fields: await sequential(collections, async (collection2) => {
|
|
2219
|
+
return astBuilder.InputValueDefinition({
|
|
2220
|
+
name: collection2.name,
|
|
2221
|
+
type: NAMER.dataFilterTypeName(collection2.namespace)
|
|
2222
|
+
});
|
|
2223
|
+
})
|
|
2257
2224
|
})
|
|
2258
2225
|
});
|
|
2259
2226
|
} else if (collection) {
|
|
@@ -4498,7 +4465,7 @@ var Resolver = class {
|
|
|
4498
4465
|
isCollectionSpecific
|
|
4499
4466
|
}) => {
|
|
4500
4467
|
const doc = await this.getDocument(realPath);
|
|
4501
|
-
const oldDoc = (doc == null ? void 0 : doc._rawData) || {};
|
|
4468
|
+
const oldDoc = this.resolveLegacyValues((doc == null ? void 0 : doc._rawData) || {}, collection);
|
|
4502
4469
|
if (isAddPendingDocument === true) {
|
|
4503
4470
|
const templateInfo = this.tinaSchema.getTemplatesForCollectable(collection);
|
|
4504
4471
|
const params2 = this.buildParams(args);
|
|
@@ -4543,6 +4510,38 @@ var Resolver = class {
|
|
|
4543
4510
|
await this.database.put(realPath, { ...oldDoc, ...params }, collection.name);
|
|
4544
4511
|
return this.getDocument(realPath);
|
|
4545
4512
|
};
|
|
4513
|
+
this.resolveLegacyValues = (oldDoc, collection) => {
|
|
4514
|
+
const legacyValues = {};
|
|
4515
|
+
Object.entries(oldDoc).forEach(([key, value]) => {
|
|
4516
|
+
var _a;
|
|
4517
|
+
const reservedKeys = [
|
|
4518
|
+
"$_body",
|
|
4519
|
+
"_collection",
|
|
4520
|
+
"_keepTemplateKey",
|
|
4521
|
+
"_template",
|
|
4522
|
+
"_relativePath",
|
|
4523
|
+
"_id"
|
|
4524
|
+
];
|
|
4525
|
+
if (reservedKeys.includes(key)) {
|
|
4526
|
+
return;
|
|
4527
|
+
}
|
|
4528
|
+
if (oldDoc._template) {
|
|
4529
|
+
const template = (_a = collection.templates) == null ? void 0 : _a.find(
|
|
4530
|
+
({ name }) => name === oldDoc._template
|
|
4531
|
+
);
|
|
4532
|
+
if (template) {
|
|
4533
|
+
if (!template.fields.find(({ name }) => name === key)) {
|
|
4534
|
+
legacyValues[key] = value;
|
|
4535
|
+
}
|
|
4536
|
+
}
|
|
4537
|
+
} else {
|
|
4538
|
+
if (!collection.fields.find(({ name }) => name === key)) {
|
|
4539
|
+
legacyValues[key] = value;
|
|
4540
|
+
}
|
|
4541
|
+
}
|
|
4542
|
+
});
|
|
4543
|
+
return legacyValues;
|
|
4544
|
+
};
|
|
4546
4545
|
this.resolveDocument = async ({
|
|
4547
4546
|
args,
|
|
4548
4547
|
collection: collectionName,
|
package/dist/index.mjs
CHANGED
|
@@ -1266,34 +1266,7 @@ var scalarDefinitions = [
|
|
|
1266
1266
|
]
|
|
1267
1267
|
})
|
|
1268
1268
|
];
|
|
1269
|
-
var
|
|
1270
|
-
name: "_sys",
|
|
1271
|
-
type: astBuilder.InputObjectTypeDefinition({
|
|
1272
|
-
name: `SysFilter`,
|
|
1273
|
-
fields: [
|
|
1274
|
-
astBuilder.InputValueDefinition({
|
|
1275
|
-
name: "relativePath",
|
|
1276
|
-
type: astBuilder.InputObjectTypeDefinition({
|
|
1277
|
-
name: "SysFilterOperations",
|
|
1278
|
-
fields: [
|
|
1279
|
-
astBuilder.InputValueDefinition({
|
|
1280
|
-
name: "startsWith",
|
|
1281
|
-
type: astBuilder.TYPES.String
|
|
1282
|
-
}),
|
|
1283
|
-
astBuilder.InputValueDefinition({
|
|
1284
|
-
name: "eq",
|
|
1285
|
-
type: astBuilder.TYPES.String
|
|
1286
|
-
})
|
|
1287
|
-
]
|
|
1288
|
-
})
|
|
1289
|
-
})
|
|
1290
|
-
]
|
|
1291
|
-
})
|
|
1292
|
-
});
|
|
1293
|
-
var staticDefinitions = [
|
|
1294
|
-
...scalarDefinitions,
|
|
1295
|
-
interfaceDefinitions
|
|
1296
|
-
];
|
|
1269
|
+
var staticDefinitions = [...scalarDefinitions, interfaceDefinitions];
|
|
1297
1270
|
|
|
1298
1271
|
// src/builder/index.ts
|
|
1299
1272
|
var createBuilder = async ({
|
|
@@ -1562,10 +1535,6 @@ var Builder = class {
|
|
|
1562
1535
|
};
|
|
1563
1536
|
this._getCollectionFragmentSelections = async (collection, depth) => {
|
|
1564
1537
|
const selections = [];
|
|
1565
|
-
selections.push({
|
|
1566
|
-
name: { kind: "Name", value: "__typename" },
|
|
1567
|
-
kind: "Field"
|
|
1568
|
-
});
|
|
1569
1538
|
if (collection.fields?.length > 0) {
|
|
1570
1539
|
await sequential(collection.fields, async (x) => {
|
|
1571
1540
|
const field = await this._buildFieldNodeForFragments(x, depth);
|
|
@@ -1828,7 +1797,7 @@ var Builder = class {
|
|
|
1828
1797
|
});
|
|
1829
1798
|
return astBuilder.InputObjectTypeDefinition({
|
|
1830
1799
|
name: NAMER.dataFilterTypeName(template.namespace),
|
|
1831
|
-
fields
|
|
1800
|
+
fields
|
|
1832
1801
|
});
|
|
1833
1802
|
};
|
|
1834
1803
|
this._updateCollectionDocumentMutationType = async (collection) => {
|
|
@@ -2188,14 +2157,12 @@ var Builder = class {
|
|
|
2188
2157
|
name: "filter",
|
|
2189
2158
|
type: astBuilder.InputObjectTypeDefinition({
|
|
2190
2159
|
name: NAMER.dataFilterTypeName(namespace),
|
|
2191
|
-
fields:
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
})
|
|
2198
|
-
]
|
|
2160
|
+
fields: await sequential(collections, async (collection2) => {
|
|
2161
|
+
return astBuilder.InputValueDefinition({
|
|
2162
|
+
name: collection2.name,
|
|
2163
|
+
type: NAMER.dataFilterTypeName(collection2.namespace)
|
|
2164
|
+
});
|
|
2165
|
+
})
|
|
2199
2166
|
})
|
|
2200
2167
|
});
|
|
2201
2168
|
} else if (collection) {
|
|
@@ -4433,7 +4400,7 @@ var Resolver = class {
|
|
|
4433
4400
|
isCollectionSpecific
|
|
4434
4401
|
}) => {
|
|
4435
4402
|
const doc = await this.getDocument(realPath);
|
|
4436
|
-
const oldDoc = doc?._rawData || {};
|
|
4403
|
+
const oldDoc = this.resolveLegacyValues(doc?._rawData || {}, collection);
|
|
4437
4404
|
if (isAddPendingDocument === true) {
|
|
4438
4405
|
const templateInfo = this.tinaSchema.getTemplatesForCollectable(collection);
|
|
4439
4406
|
const params2 = this.buildParams(args);
|
|
@@ -4478,6 +4445,37 @@ var Resolver = class {
|
|
|
4478
4445
|
await this.database.put(realPath, { ...oldDoc, ...params }, collection.name);
|
|
4479
4446
|
return this.getDocument(realPath);
|
|
4480
4447
|
};
|
|
4448
|
+
this.resolveLegacyValues = (oldDoc, collection) => {
|
|
4449
|
+
const legacyValues = {};
|
|
4450
|
+
Object.entries(oldDoc).forEach(([key, value]) => {
|
|
4451
|
+
const reservedKeys = [
|
|
4452
|
+
"$_body",
|
|
4453
|
+
"_collection",
|
|
4454
|
+
"_keepTemplateKey",
|
|
4455
|
+
"_template",
|
|
4456
|
+
"_relativePath",
|
|
4457
|
+
"_id"
|
|
4458
|
+
];
|
|
4459
|
+
if (reservedKeys.includes(key)) {
|
|
4460
|
+
return;
|
|
4461
|
+
}
|
|
4462
|
+
if (oldDoc._template) {
|
|
4463
|
+
const template = collection.templates?.find(
|
|
4464
|
+
({ name }) => name === oldDoc._template
|
|
4465
|
+
);
|
|
4466
|
+
if (template) {
|
|
4467
|
+
if (!template.fields.find(({ name }) => name === key)) {
|
|
4468
|
+
legacyValues[key] = value;
|
|
4469
|
+
}
|
|
4470
|
+
}
|
|
4471
|
+
} else {
|
|
4472
|
+
if (!collection.fields.find(({ name }) => name === key)) {
|
|
4473
|
+
legacyValues[key] = value;
|
|
4474
|
+
}
|
|
4475
|
+
}
|
|
4476
|
+
});
|
|
4477
|
+
return legacyValues;
|
|
4478
|
+
};
|
|
4481
4479
|
this.resolveDocument = async ({
|
|
4482
4480
|
args,
|
|
4483
4481
|
collection: collectionName,
|
package/dist/resolver/index.d.ts
CHANGED
|
@@ -228,6 +228,11 @@ export declare class Resolver {
|
|
|
228
228
|
__typename: string;
|
|
229
229
|
id: string;
|
|
230
230
|
}>;
|
|
231
|
+
/**
|
|
232
|
+
* Returns top-level fields which are not defined in the collection, so their
|
|
233
|
+
* values are not eliminated from Tina when new values are saved
|
|
234
|
+
*/
|
|
235
|
+
resolveLegacyValues: (oldDoc: any, collection: Collection<true>) => {};
|
|
231
236
|
resolveDocument: ({ args, collection: collectionName, isMutation, isCreation, isDeletion, isAddPendingDocument, isCollectionSpecific, isUpdateName, }: {
|
|
232
237
|
args: unknown;
|
|
233
238
|
collection?: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tinacms/graphql",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-20230922192012",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"module": "dist/index.mjs",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
@@ -24,8 +24,6 @@
|
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"@iarna/toml": "^2.2.5",
|
|
27
|
-
"@tinacms/mdx": "1.3.18",
|
|
28
|
-
"@tinacms/schema-tools": "1.4.12",
|
|
29
27
|
"abstract-level": "^1.0.3",
|
|
30
28
|
"body-parser": "^1.19.0",
|
|
31
29
|
"cors": "^2.8.5",
|
|
@@ -47,7 +45,9 @@
|
|
|
47
45
|
"micromatch": "4.0.5",
|
|
48
46
|
"normalize-path": "^3.0.0",
|
|
49
47
|
"readable-stream": "^4.3.0",
|
|
50
|
-
"yup": "^0.32.9"
|
|
48
|
+
"yup": "^0.32.9",
|
|
49
|
+
"@tinacms/mdx": "0.0.0-20230922192012",
|
|
50
|
+
"@tinacms/schema-tools": "1.4.12"
|
|
51
51
|
},
|
|
52
52
|
"publishConfig": {
|
|
53
53
|
"registry": "https://registry.npmjs.org"
|
|
@@ -57,8 +57,6 @@
|
|
|
57
57
|
"directory": "packages/tina-graphql"
|
|
58
58
|
},
|
|
59
59
|
"devDependencies": {
|
|
60
|
-
"@tinacms/schema-tools": "1.4.12",
|
|
61
|
-
"@tinacms/scripts": "1.1.2",
|
|
62
60
|
"@types/cors": "^2.8.7",
|
|
63
61
|
"@types/estree": "^0.0.50",
|
|
64
62
|
"@types/express": "^4.17.8",
|
|
@@ -81,7 +79,9 @@
|
|
|
81
79
|
"jest-matcher-utils": "^29.5.0",
|
|
82
80
|
"memory-level": "^1.0.0",
|
|
83
81
|
"nodemon": "2.0.19",
|
|
84
|
-
"typescript": "4.3.5"
|
|
82
|
+
"typescript": "4.3.5",
|
|
83
|
+
"@tinacms/schema-tools": "1.4.12",
|
|
84
|
+
"@tinacms/scripts": "1.1.2"
|
|
85
85
|
},
|
|
86
86
|
"scripts": {
|
|
87
87
|
"types": "pnpm tsc",
|