@tinacms/graphql 1.4.3 → 1.4.5

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.
@@ -1,6 +1,6 @@
1
1
  import type { DocumentNode } from 'graphql';
2
- import type { CollectionTemplateable, TinaCloudCollection, Schema, TinaSchema } from '@tinacms/schema-tools';
3
- import type { Bridge } from '../database/bridge';
2
+ import type { CollectionTemplateable, Schema, TinaCloudCollection, TinaSchema } from '@tinacms/schema-tools';
3
+ import type { Bridge } from './bridge';
4
4
  import { BinaryFilter, IndexDefinition, TernaryFilter } from './datalayer';
5
5
  import { Level } from './level';
6
6
  declare type IndexStatusEvent = {
package/dist/index.es.js CHANGED
@@ -2491,7 +2491,7 @@ var validateField = async (field) => {
2491
2491
  // package.json
2492
2492
  var package_default = {
2493
2493
  name: "@tinacms/graphql",
2494
- version: "1.4.3",
2494
+ version: "1.4.5",
2495
2495
  main: "dist/index.js",
2496
2496
  module: "dist/index.es.js",
2497
2497
  typings: "dist/index.d.ts",
@@ -3000,6 +3000,17 @@ var resolveMediaCloudToRelative = (value, config = { useRelativeMedia: true }, s
3000
3000
  const strippedURL = value.replace(assetsURL, "");
3001
3001
  return `${cleanMediaRoot}${strippedURL}`;
3002
3002
  }
3003
+ if (Array.isArray(value)) {
3004
+ return value.map((v) => {
3005
+ if (!v || typeof v !== "string")
3006
+ return v;
3007
+ const cleanMediaRoot = cleanUpSlashes(
3008
+ schema.config.media.tina.mediaRoot
3009
+ );
3010
+ const strippedURL = v.replace(assetsURL, "");
3011
+ return `${cleanMediaRoot}${strippedURL}`;
3012
+ });
3013
+ }
3003
3014
  return value;
3004
3015
  }
3005
3016
  return value;
@@ -3014,8 +3025,18 @@ var resolveMediaRelativeToCloud = (value, config = { useRelativeMedia: true }, s
3014
3025
  }
3015
3026
  if (hasTinaMediaConfig(schema) === true) {
3016
3027
  const cleanMediaRoot = cleanUpSlashes(schema.config.media.tina.mediaRoot);
3017
- const strippedValue = value.replace(cleanMediaRoot, "");
3018
- return `https://${config.assetsHost}/${config.clientId}${strippedValue}`;
3028
+ if (typeof value === "string") {
3029
+ const strippedValue = value.replace(cleanMediaRoot, "");
3030
+ return `https://${config.assetsHost}/${config.clientId}${strippedValue}`;
3031
+ }
3032
+ if (Array.isArray(value)) {
3033
+ return value.map((v) => {
3034
+ if (!v || typeof v !== "string")
3035
+ return v;
3036
+ const strippedValue = v.replace(cleanMediaRoot, "");
3037
+ return `https://${config.assetsHost}/${config.clientId}${strippedValue}`;
3038
+ });
3039
+ }
3019
3040
  }
3020
3041
  return value;
3021
3042
  } else {
@@ -5095,49 +5116,53 @@ var Database = class {
5095
5116
  throw new Error("No bridge configured");
5096
5117
  }
5097
5118
  await this.initLevel();
5098
- const result = await this.indexStatusCallbackWrapper(async () => {
5099
- const lookup = lookupFromLockFile || JSON.parse(
5100
- await this.bridge.get(
5101
- normalizePath(path2.join(this.getGeneratedFolder(), "_lookup.json"))
5102
- )
5103
- );
5104
- let nextLevel;
5105
- let nextVersion;
5106
- if (!this.config.version) {
5107
- await this.level.clear();
5108
- nextLevel = this.level;
5109
- } else {
5110
- const version = await this.getDatabaseVersion();
5111
- nextVersion = version ? `${parseInt(version) + 1}` : "0";
5112
- nextLevel = this.rootLevel.sublevel(nextVersion, SUBLEVEL_OPTIONS);
5113
- }
5114
- const contentRootLevel = nextLevel.sublevel(
5115
- CONTENT_ROOT_PREFIX,
5116
- SUBLEVEL_OPTIONS
5117
- );
5118
- await contentRootLevel.put(
5119
- normalizePath(path2.join(this.getGeneratedFolder(), "_graphql.json")),
5120
- graphQLSchema
5121
- );
5122
- await contentRootLevel.put(
5123
- normalizePath(path2.join(this.getGeneratedFolder(), "_schema.json")),
5124
- tinaSchema.schema
5125
- );
5126
- await contentRootLevel.put(
5127
- normalizePath(path2.join(this.getGeneratedFolder(), "_lookup.json")),
5128
- lookup
5129
- );
5130
- const result2 = await this._indexAllContent(nextLevel);
5131
- if (this.config.version) {
5132
- await this.updateDatabaseVersion(nextVersion);
5133
- if (this.level) {
5119
+ let nextLevel;
5120
+ return await this.indexStatusCallbackWrapper(
5121
+ async () => {
5122
+ const lookup = lookupFromLockFile || JSON.parse(
5123
+ await this.bridge.get(
5124
+ normalizePath(
5125
+ path2.join(this.getGeneratedFolder(), "_lookup.json")
5126
+ )
5127
+ )
5128
+ );
5129
+ let nextVersion;
5130
+ if (!this.config.version) {
5134
5131
  await this.level.clear();
5132
+ nextLevel = this.level;
5133
+ } else {
5134
+ const version = await this.getDatabaseVersion();
5135
+ nextVersion = version ? `${parseInt(version) + 1}` : "0";
5136
+ nextLevel = this.rootLevel.sublevel(nextVersion, SUBLEVEL_OPTIONS);
5137
+ }
5138
+ const contentRootLevel = nextLevel.sublevel(CONTENT_ROOT_PREFIX, SUBLEVEL_OPTIONS);
5139
+ await contentRootLevel.put(
5140
+ normalizePath(path2.join(this.getGeneratedFolder(), "_graphql.json")),
5141
+ graphQLSchema
5142
+ );
5143
+ await contentRootLevel.put(
5144
+ normalizePath(path2.join(this.getGeneratedFolder(), "_schema.json")),
5145
+ tinaSchema.schema
5146
+ );
5147
+ await contentRootLevel.put(
5148
+ normalizePath(path2.join(this.getGeneratedFolder(), "_lookup.json")),
5149
+ lookup
5150
+ );
5151
+ const result = await this._indexAllContent(nextLevel);
5152
+ if (this.config.version) {
5153
+ await this.updateDatabaseVersion(nextVersion);
5154
+ }
5155
+ return result;
5156
+ },
5157
+ async () => {
5158
+ if (this.config.version) {
5159
+ if (this.level) {
5160
+ await this.level.clear();
5161
+ }
5162
+ this.level = nextLevel;
5135
5163
  }
5136
- this.level = nextLevel;
5137
5164
  }
5138
- return result2;
5139
- });
5140
- return result;
5165
+ );
5141
5166
  };
5142
5167
  this.deleteContentByPaths = async (documentPaths) => {
5143
5168
  await this.initLevel();
@@ -5375,11 +5400,14 @@ This will be an error in the future. See https://tina.io/docs/errors/file-in-mut
5375
5400
  this.tinaSchema = null;
5376
5401
  this._lookup = null;
5377
5402
  }
5378
- async indexStatusCallbackWrapper(fn) {
5403
+ async indexStatusCallbackWrapper(fn, post) {
5379
5404
  await this.indexStatusCallback({ status: "inprogress" });
5380
5405
  try {
5381
5406
  const result = await fn();
5382
5407
  await this.indexStatusCallback({ status: "complete" });
5408
+ if (post) {
5409
+ await post();
5410
+ }
5383
5411
  return result;
5384
5412
  } catch (error) {
5385
5413
  await this.indexStatusCallback({ status: "failed", error });
package/dist/index.js CHANGED
@@ -2542,7 +2542,7 @@ var validateField = async (field) => {
2542
2542
  // package.json
2543
2543
  var package_default = {
2544
2544
  name: "@tinacms/graphql",
2545
- version: "1.4.3",
2545
+ version: "1.4.5",
2546
2546
  main: "dist/index.js",
2547
2547
  module: "dist/index.es.js",
2548
2548
  typings: "dist/index.d.ts",
@@ -3045,6 +3045,17 @@ var resolveMediaCloudToRelative = (value, config = { useRelativeMedia: true }, s
3045
3045
  const strippedURL = value.replace(assetsURL, "");
3046
3046
  return `${cleanMediaRoot}${strippedURL}`;
3047
3047
  }
3048
+ if (Array.isArray(value)) {
3049
+ return value.map((v) => {
3050
+ if (!v || typeof v !== "string")
3051
+ return v;
3052
+ const cleanMediaRoot = cleanUpSlashes(
3053
+ schema.config.media.tina.mediaRoot
3054
+ );
3055
+ const strippedURL = v.replace(assetsURL, "");
3056
+ return `${cleanMediaRoot}${strippedURL}`;
3057
+ });
3058
+ }
3048
3059
  return value;
3049
3060
  }
3050
3061
  return value;
@@ -3059,8 +3070,18 @@ var resolveMediaRelativeToCloud = (value, config = { useRelativeMedia: true }, s
3059
3070
  }
3060
3071
  if (hasTinaMediaConfig(schema) === true) {
3061
3072
  const cleanMediaRoot = cleanUpSlashes(schema.config.media.tina.mediaRoot);
3062
- const strippedValue = value.replace(cleanMediaRoot, "");
3063
- return `https://${config.assetsHost}/${config.clientId}${strippedValue}`;
3073
+ if (typeof value === "string") {
3074
+ const strippedValue = value.replace(cleanMediaRoot, "");
3075
+ return `https://${config.assetsHost}/${config.clientId}${strippedValue}`;
3076
+ }
3077
+ if (Array.isArray(value)) {
3078
+ return value.map((v) => {
3079
+ if (!v || typeof v !== "string")
3080
+ return v;
3081
+ const strippedValue = v.replace(cleanMediaRoot, "");
3082
+ return `https://${config.assetsHost}/${config.clientId}${strippedValue}`;
3083
+ });
3084
+ }
3064
3085
  }
3065
3086
  return value;
3066
3087
  } else {
@@ -5153,49 +5174,53 @@ var Database = class {
5153
5174
  throw new Error("No bridge configured");
5154
5175
  }
5155
5176
  await this.initLevel();
5156
- const result = await this.indexStatusCallbackWrapper(async () => {
5157
- const lookup = lookupFromLockFile || JSON.parse(
5158
- await this.bridge.get(
5159
- (0, import_schema_tools3.normalizePath)(import_path2.default.join(this.getGeneratedFolder(), "_lookup.json"))
5160
- )
5161
- );
5162
- let nextLevel;
5163
- let nextVersion;
5164
- if (!this.config.version) {
5165
- await this.level.clear();
5166
- nextLevel = this.level;
5167
- } else {
5168
- const version = await this.getDatabaseVersion();
5169
- nextVersion = version ? `${parseInt(version) + 1}` : "0";
5170
- nextLevel = this.rootLevel.sublevel(nextVersion, SUBLEVEL_OPTIONS);
5171
- }
5172
- const contentRootLevel = nextLevel.sublevel(
5173
- CONTENT_ROOT_PREFIX,
5174
- SUBLEVEL_OPTIONS
5175
- );
5176
- await contentRootLevel.put(
5177
- (0, import_schema_tools3.normalizePath)(import_path2.default.join(this.getGeneratedFolder(), "_graphql.json")),
5178
- graphQLSchema
5179
- );
5180
- await contentRootLevel.put(
5181
- (0, import_schema_tools3.normalizePath)(import_path2.default.join(this.getGeneratedFolder(), "_schema.json")),
5182
- tinaSchema.schema
5183
- );
5184
- await contentRootLevel.put(
5185
- (0, import_schema_tools3.normalizePath)(import_path2.default.join(this.getGeneratedFolder(), "_lookup.json")),
5186
- lookup
5187
- );
5188
- const result2 = await this._indexAllContent(nextLevel);
5189
- if (this.config.version) {
5190
- await this.updateDatabaseVersion(nextVersion);
5191
- if (this.level) {
5177
+ let nextLevel;
5178
+ return await this.indexStatusCallbackWrapper(
5179
+ async () => {
5180
+ const lookup = lookupFromLockFile || JSON.parse(
5181
+ await this.bridge.get(
5182
+ (0, import_schema_tools3.normalizePath)(
5183
+ import_path2.default.join(this.getGeneratedFolder(), "_lookup.json")
5184
+ )
5185
+ )
5186
+ );
5187
+ let nextVersion;
5188
+ if (!this.config.version) {
5192
5189
  await this.level.clear();
5190
+ nextLevel = this.level;
5191
+ } else {
5192
+ const version = await this.getDatabaseVersion();
5193
+ nextVersion = version ? `${parseInt(version) + 1}` : "0";
5194
+ nextLevel = this.rootLevel.sublevel(nextVersion, SUBLEVEL_OPTIONS);
5195
+ }
5196
+ const contentRootLevel = nextLevel.sublevel(CONTENT_ROOT_PREFIX, SUBLEVEL_OPTIONS);
5197
+ await contentRootLevel.put(
5198
+ (0, import_schema_tools3.normalizePath)(import_path2.default.join(this.getGeneratedFolder(), "_graphql.json")),
5199
+ graphQLSchema
5200
+ );
5201
+ await contentRootLevel.put(
5202
+ (0, import_schema_tools3.normalizePath)(import_path2.default.join(this.getGeneratedFolder(), "_schema.json")),
5203
+ tinaSchema.schema
5204
+ );
5205
+ await contentRootLevel.put(
5206
+ (0, import_schema_tools3.normalizePath)(import_path2.default.join(this.getGeneratedFolder(), "_lookup.json")),
5207
+ lookup
5208
+ );
5209
+ const result = await this._indexAllContent(nextLevel);
5210
+ if (this.config.version) {
5211
+ await this.updateDatabaseVersion(nextVersion);
5212
+ }
5213
+ return result;
5214
+ },
5215
+ async () => {
5216
+ if (this.config.version) {
5217
+ if (this.level) {
5218
+ await this.level.clear();
5219
+ }
5220
+ this.level = nextLevel;
5193
5221
  }
5194
- this.level = nextLevel;
5195
5222
  }
5196
- return result2;
5197
- });
5198
- return result;
5223
+ );
5199
5224
  };
5200
5225
  this.deleteContentByPaths = async (documentPaths) => {
5201
5226
  await this.initLevel();
@@ -5433,11 +5458,14 @@ This will be an error in the future. See https://tina.io/docs/errors/file-in-mut
5433
5458
  this.tinaSchema = null;
5434
5459
  this._lookup = null;
5435
5460
  }
5436
- async indexStatusCallbackWrapper(fn) {
5461
+ async indexStatusCallbackWrapper(fn, post) {
5437
5462
  await this.indexStatusCallback({ status: "inprogress" });
5438
5463
  try {
5439
5464
  const result = await fn();
5440
5465
  await this.indexStatusCallback({ status: "complete" });
5466
+ if (post) {
5467
+ await post();
5468
+ }
5441
5469
  return result;
5442
5470
  } catch (error) {
5443
5471
  await this.indexStatusCallback({ status: "failed", error });
@@ -6,16 +6,16 @@ import type { Schema } from '@tinacms/schema-tools';
6
6
  /**
7
7
  * Strips away the Tina Cloud Asset URL from an `image` value
8
8
  *
9
- * @param {string} value
9
+ * @param {string | string[]} value
10
10
  * @param {GraphQLConfig} config
11
11
  * @returns {string}
12
12
  */
13
- export declare const resolveMediaCloudToRelative: (value: string, config: GraphQLConfig, schema: Schema<true>) => string;
13
+ export declare const resolveMediaCloudToRelative: (value: string | string[], config: GraphQLConfig, schema: Schema<true>) => string | string[];
14
14
  /**
15
15
  * Adds Tina Cloud Asset URL to an `image` value
16
16
  *
17
- * @param {string} value
17
+ * @param {string | string[]} value
18
18
  * @param {GraphQLConfig} config
19
19
  * @returns {string}
20
20
  */
21
- export declare const resolveMediaRelativeToCloud: (value: string, config: GraphQLConfig, schema: Schema<true>) => string;
21
+ export declare const resolveMediaRelativeToCloud: (value: string | string[], config: GraphQLConfig, schema: Schema<true>) => string | string[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tinacms/graphql",
3
- "version": "1.4.3",
3
+ "version": "1.4.5",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.es.js",
6
6
  "typings": "dist/index.d.ts",
@@ -25,6 +25,8 @@
25
25
  "dependencies": {
26
26
  "@graphql-tools/relay-operation-optimizer": "^6.4.1",
27
27
  "@iarna/toml": "^2.2.5",
28
+ "@tinacms/mdx": "1.3.7",
29
+ "@tinacms/schema-tools": "1.4.2",
28
30
  "abstract-level": "^1.0.3",
29
31
  "body-parser": "^1.19.0",
30
32
  "cors": "^2.8.5",
@@ -71,9 +73,7 @@
71
73
  "unist-util-visit": "^4.0.0",
72
74
  "vfile": "^4.2.0",
73
75
  "ws": "^7.3.1",
74
- "yup": "^0.32.9",
75
- "@tinacms/mdx": "1.3.7",
76
- "@tinacms/schema-tools": "1.4.2"
76
+ "yup": "^0.32.9"
77
77
  },
78
78
  "publishConfig": {
79
79
  "registry": "https://registry.npmjs.org"
@@ -83,6 +83,8 @@
83
83
  "directory": "packages/tina-graphql"
84
84
  },
85
85
  "devDependencies": {
86
+ "@tinacms/schema-tools": "1.4.2",
87
+ "@tinacms/scripts": "1.1.0",
86
88
  "@types/cors": "^2.8.7",
87
89
  "@types/estree": "^0.0.50",
88
90
  "@types/express": "^4.17.8",
@@ -105,9 +107,7 @@
105
107
  "jest-matcher-utils": "27.0.6",
106
108
  "memory-level": "^1.0.0",
107
109
  "nodemon": "2.0.19",
108
- "typescript": "4.3.5",
109
- "@tinacms/schema-tools": "1.4.2",
110
- "@tinacms/scripts": "1.1.0"
110
+ "typescript": "4.3.5"
111
111
  },
112
112
  "scripts": {
113
113
  "types": "pnpm tsc",