@tinacms/graphql 0.0.0-20230922191950 → 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/index.js CHANGED
@@ -4465,7 +4465,7 @@ var Resolver = class {
4465
4465
  isCollectionSpecific
4466
4466
  }) => {
4467
4467
  const doc = await this.getDocument(realPath);
4468
- const oldDoc = (doc == null ? void 0 : doc._rawData) || {};
4468
+ const oldDoc = this.resolveLegacyValues((doc == null ? void 0 : doc._rawData) || {}, collection);
4469
4469
  if (isAddPendingDocument === true) {
4470
4470
  const templateInfo = this.tinaSchema.getTemplatesForCollectable(collection);
4471
4471
  const params2 = this.buildParams(args);
@@ -4510,6 +4510,38 @@ var Resolver = class {
4510
4510
  await this.database.put(realPath, { ...oldDoc, ...params }, collection.name);
4511
4511
  return this.getDocument(realPath);
4512
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
+ };
4513
4545
  this.resolveDocument = async ({
4514
4546
  args,
4515
4547
  collection: collectionName,
package/dist/index.mjs CHANGED
@@ -4400,7 +4400,7 @@ var Resolver = class {
4400
4400
  isCollectionSpecific
4401
4401
  }) => {
4402
4402
  const doc = await this.getDocument(realPath);
4403
- const oldDoc = doc?._rawData || {};
4403
+ const oldDoc = this.resolveLegacyValues(doc?._rawData || {}, collection);
4404
4404
  if (isAddPendingDocument === true) {
4405
4405
  const templateInfo = this.tinaSchema.getTemplatesForCollectable(collection);
4406
4406
  const params2 = this.buildParams(args);
@@ -4445,6 +4445,37 @@ var Resolver = class {
4445
4445
  await this.database.put(realPath, { ...oldDoc, ...params }, collection.name);
4446
4446
  return this.getDocument(realPath);
4447
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
+ };
4448
4479
  this.resolveDocument = async ({
4449
4480
  args,
4450
4481
  collection: collectionName,
@@ -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-20230922191950",
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": "0.0.0-20230922191950",
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",