@tinacms/graphql 1.3.5 → 1.4.0

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.es.js CHANGED
@@ -1,11 +1,8 @@
1
1
  // src/index.ts
2
- import fs4 from "fs-extra";
3
- import path5 from "path";
4
2
  import { buildASTSchema as buildASTSchema2 } from "graphql";
5
3
 
6
4
  // src/build.ts
7
5
  import _3 from "lodash";
8
- import fs from "fs-extra";
9
6
  import { print } from "graphql";
10
7
 
11
8
  // src/ast-builder/index.ts
@@ -2388,19 +2385,26 @@ var validationCollectionsPathAndMatch = (collections) => {
2388
2385
  }
2389
2386
  const noMatchCollections = collections.filter((x) => {
2390
2387
  return typeof x?.match === "undefined";
2391
- }).map((x) => x.path);
2388
+ }).map((x) => `${x.path}${x.format || "md"}`);
2392
2389
  if (noMatchCollections.length !== new Set(noMatchCollections).size) {
2393
- throw new Error("path must be unique");
2390
+ throw new Error(
2391
+ "Two collections without match can not have the same `path`. Please make the `path` unique or add a matches property to the collection."
2392
+ );
2394
2393
  }
2395
2394
  const hasMatchAndPath = collections.filter((x) => {
2396
2395
  return typeof x.path !== "undefined" && typeof x.match !== "undefined";
2397
- }).map((x) => `${x.path}|${x.match}`);
2396
+ }).map(
2397
+ (x) => `${x.path}|${x?.match?.exclude || ""}|${x?.match?.include || ""}|${x.format || "md"}`
2398
+ );
2398
2399
  if (hasMatchAndPath.length !== new Set(hasMatchAndPath).size) {
2399
- throw new Error("Both `match` and `path` can not be the same");
2400
+ throw new Error(
2401
+ "Can not have two or more collections with the same path and match. Please update either the path or the match to be unique."
2402
+ );
2400
2403
  }
2401
2404
  const groupbyPath = collections.reduce((r, a) => {
2402
- r[a.path] = r[a.path] || [];
2403
- r[a.path].push(a);
2405
+ const key = `${a.path}|${a.format || "md"}`;
2406
+ r[key] = r[key] || [];
2407
+ r[key].push(a);
2404
2408
  return r;
2405
2409
  }, /* @__PURE__ */ Object.create(null));
2406
2410
  Object.keys(groupbyPath).forEach((key) => {
@@ -2408,12 +2412,20 @@ var validationCollectionsPathAndMatch = (collections) => {
2408
2412
  if (collectionsArr.length === 1) {
2409
2413
  return;
2410
2414
  }
2411
- const matches = collectionsArr.filter((x) => {
2412
- return typeof x.match !== "undefined";
2413
- });
2414
- if (matches.length !== collections.length) {
2415
- throw new Error("path must be unique when no `match` is provided");
2415
+ if (collectionsArr.some((x) => typeof x.match === "undefined")) {
2416
+ throw new Error(
2417
+ "Can not have two or more collections with the same path and format if one doesn't have a match property"
2418
+ );
2416
2419
  }
2420
+ const matches = collectionsArr.map(
2421
+ (x) => typeof x?.match === "object" ? JSON.stringify(x.match) : ""
2422
+ );
2423
+ if (matches.length === new Set(matches).size) {
2424
+ return;
2425
+ }
2426
+ throw new Error(
2427
+ "Can not have two or more collections with the same path format and match. Please update either the path or the match to be unique."
2428
+ );
2417
2429
  });
2418
2430
  };
2419
2431
  var validateCollection = async (collection) => {
@@ -2479,7 +2491,7 @@ var validateField = async (field) => {
2479
2491
  // package.json
2480
2492
  var package_default = {
2481
2493
  name: "@tinacms/graphql",
2482
- version: "1.3.5",
2494
+ version: "1.4.0",
2483
2495
  main: "dist/index.js",
2484
2496
  module: "dist/index.es.js",
2485
2497
  typings: "dist/index.d.ts",
@@ -2542,6 +2554,7 @@ var package_default = {
2542
2554
  "mdast-util-mdx-expression": "^1.1.0",
2543
2555
  "mdast-util-to-markdown": "^1.2.1",
2544
2556
  "micromark-extension-mdxjs": "^1.0.0",
2557
+ micromatch: "4.0.5",
2545
2558
  "normalize-path": "^3.0.0",
2546
2559
  prettier: "^2.2.1",
2547
2560
  "readable-stream": "^4.3.0",
@@ -2582,6 +2595,7 @@ var package_default = {
2582
2595
  "@types/lodash.upperfirst": "^4.3.6",
2583
2596
  "@types/lru-cache": "^5.1.0",
2584
2597
  "@types/mdast": "^3.0.10",
2598
+ "@types/micromatch": "^4.0.2",
2585
2599
  "@types/node": "^14.17.34",
2586
2600
  "@types/normalize-path": "^3.0.0",
2587
2601
  "@types/ws": "^7.2.6",
@@ -2620,7 +2634,6 @@ var createSchema = async ({
2620
2634
  };
2621
2635
 
2622
2636
  // src/build.ts
2623
- import path from "path";
2624
2637
  var buildDotTinaFiles = async ({
2625
2638
  database,
2626
2639
  config,
@@ -2630,7 +2643,11 @@ var buildDotTinaFiles = async ({
2630
2643
  if (flags.indexOf("experimentalData") === -1) {
2631
2644
  flags.push("experimentalData");
2632
2645
  }
2633
- const tinaSchema = await createSchema({ schema: config, flags });
2646
+ const { schema } = config;
2647
+ const tinaSchema = await createSchema({
2648
+ schema: { ...schema, config },
2649
+ flags
2650
+ });
2634
2651
  const builder = await createBuilder({
2635
2652
  database,
2636
2653
  tinaSchema
@@ -2644,11 +2661,21 @@ var buildDotTinaFiles = async ({
2644
2661
  await database.bridge.get(".tina/__generated__/_graphql.json")
2645
2662
  );
2646
2663
  }
2664
+ let fragDoc = "";
2665
+ let queryDoc = "";
2647
2666
  if (buildSDK) {
2648
- await _buildFragments(builder, tinaSchema, database.bridge.rootPath);
2649
- await _buildQueries(builder, tinaSchema, database.bridge.rootPath);
2667
+ fragDoc = await _buildFragments(
2668
+ builder,
2669
+ tinaSchema,
2670
+ database.bridge.rootPath
2671
+ );
2672
+ queryDoc = await _buildQueries(
2673
+ builder,
2674
+ tinaSchema,
2675
+ database.bridge.rootPath
2676
+ );
2650
2677
  }
2651
- return { graphQLSchema, tinaSchema };
2678
+ return { graphQLSchema, tinaSchema, fragDoc, queryDoc };
2652
2679
  };
2653
2680
  var _buildFragments = async (builder, tinaSchema, rootPath) => {
2654
2681
  const fragmentDefinitionsFields = [];
@@ -2666,23 +2693,7 @@ var _buildFragments = async (builder, tinaSchema, rootPath) => {
2666
2693
  (node) => node.name.value
2667
2694
  )
2668
2695
  };
2669
- const fragPath = path.join(rootPath, ".tina", "__generated__");
2670
- await fs.outputFile(path.join(fragPath, "frags.gql"), print(fragDoc));
2671
- if (await (await fs.stat(path.join(fragPath, "frags.gql"))).size > 100 * 1024) {
2672
- console.warn(
2673
- "Warning: frags.gql is very large (>100kb). Consider setting the reference depth to 1 or 0. See code snippet below."
2674
- );
2675
- console.log(
2676
- `const schema = defineSchema({
2677
- config: {
2678
- client: {
2679
- referenceDepth: 1,
2680
- },
2681
- }
2682
- // ...
2683
- })`
2684
- );
2685
- }
2696
+ return print(fragDoc);
2686
2697
  };
2687
2698
  var _buildQueries = async (builder, tinaSchema, rootPath) => {
2688
2699
  const operationsDefinitions = [];
@@ -2713,8 +2724,7 @@ var _buildQueries = async (builder, tinaSchema, rootPath) => {
2713
2724
  (node) => node.name.value
2714
2725
  )
2715
2726
  };
2716
- const fragPath = path.join(rootPath, ".tina", "__generated__");
2717
- await fs.outputFile(path.join(fragPath, "queries.gql"), print(queryDoc));
2727
+ return print(queryDoc);
2718
2728
  };
2719
2729
  var _buildSchema = async (builder, tinaSchema) => {
2720
2730
  const definitions = [];
@@ -2802,7 +2812,7 @@ import {
2802
2812
  } from "graphql";
2803
2813
 
2804
2814
  // src/resolver/index.ts
2805
- import path2 from "path";
2815
+ import path from "path";
2806
2816
  import isValid from "date-fns/isValid";
2807
2817
 
2808
2818
  // src/mdx/index.ts
@@ -3012,9 +3022,9 @@ var resolveMediaRelativeToCloud = (value, config = { useRelativeMedia: true }, s
3012
3022
  return value;
3013
3023
  }
3014
3024
  };
3015
- var cleanUpSlashes = (path6) => {
3016
- if (path6) {
3017
- return `/${path6.replace(/^\/+|\/+$/gm, "")}`;
3025
+ var cleanUpSlashes = (path4) => {
3026
+ if (path4) {
3027
+ return `/${path4.replace(/^\/+|\/+$/gm, "")}`;
3018
3028
  }
3019
3029
  return "";
3020
3030
  };
@@ -3478,7 +3488,11 @@ var makeStringEscaper = (regex, replacement) => {
3478
3488
  (val) => val.replace(regex, replacement)
3479
3489
  );
3480
3490
  } else {
3481
- return input.replace(regex, replacement);
3491
+ if (typeof input === "string") {
3492
+ return input.replace(regex, replacement);
3493
+ } else {
3494
+ return input;
3495
+ }
3482
3496
  }
3483
3497
  };
3484
3498
  };
@@ -3518,7 +3532,7 @@ var Resolver = class {
3518
3532
  base: basename,
3519
3533
  ext: extension,
3520
3534
  name: filename
3521
- } = path2.parse(fullPath);
3535
+ } = path.parse(fullPath);
3522
3536
  const relativePath = fullPath.replace(/\\/g, "/").replace(collection.path, "").replace(/^\/|\/$/g, "");
3523
3537
  const breadcrumbs = relativePath.replace(extension, "").split("/");
3524
3538
  const data = {
@@ -3761,7 +3775,7 @@ var Resolver = class {
3761
3775
  (yup3) => yup3.object({ relativePath: yup3.string().required() })
3762
3776
  );
3763
3777
  const collection = await this.tinaSchema.getCollection(collectionLookup);
3764
- const realPath = path2.join(collection?.path, args.relativePath);
3778
+ const realPath = path.join(collection?.path, args.relativePath);
3765
3779
  const alreadyExists = await this.database.documentExists(realPath);
3766
3780
  if (isMutation) {
3767
3781
  if (isCreation) {
@@ -3802,7 +3816,7 @@ var Resolver = class {
3802
3816
  (yup3) => yup3.object({ relativePath: yup3.string().required() })
3803
3817
  );
3804
3818
  const doc = await this.getDocument(realPath);
3805
- const newRealPath = path2.join(
3819
+ const newRealPath = path.join(
3806
3820
  collection?.path,
3807
3821
  args.params.relativePath
3808
3822
  );
@@ -3857,7 +3871,7 @@ var Resolver = class {
3857
3871
  first: -1
3858
3872
  },
3859
3873
  collection: referencedCollection,
3860
- hydrator: (path6) => path6
3874
+ hydrator: (path4) => path4
3861
3875
  }
3862
3876
  );
3863
3877
  const { edges } = resolvedCollectionConnection;
@@ -4386,13 +4400,15 @@ var resolve = async ({
4386
4400
  };
4387
4401
 
4388
4402
  // src/database/index.ts
4389
- import path3 from "path";
4403
+ import path2 from "path";
4390
4404
  import { GraphQLError as GraphQLError4 } from "graphql";
4405
+ import micromatch from "micromatch";
4391
4406
 
4392
4407
  // src/database/util.ts
4393
4408
  import toml from "@iarna/toml";
4394
4409
  import yaml from "js-yaml";
4395
4410
  import matter from "gray-matter";
4411
+ import { normalizePath } from "@tinacms/schema-tools";
4396
4412
  var matterEngines = {
4397
4413
  toml: {
4398
4414
  parse: (val) => toml.parse(val),
@@ -4476,7 +4492,6 @@ var parseFile = (content, format, yupSchema, markdownParseConfig) => {
4476
4492
  throw new Error(`Must specify a valid format, got ${format}`);
4477
4493
  }
4478
4494
  };
4479
- var normalizePath = (filepath) => filepath.replace(/\\/g, "/");
4480
4495
 
4481
4496
  // src/database/alias-utils.ts
4482
4497
  var replaceNameOverrides = (template, obj) => {
@@ -4565,14 +4580,14 @@ var Database = class {
4565
4580
  const tinaSchema = await this.getSchema(this.level);
4566
4581
  return tinaSchema.getCollectionByFullPath(filepath);
4567
4582
  };
4568
- this.getGeneratedFolder = () => path3.join(this.tinaDirectory, "__generated__");
4583
+ this.getGeneratedFolder = () => path2.join(this.tinaDirectory, "__generated__");
4569
4584
  this.get = async (filepath) => {
4570
4585
  await this.initLevel();
4571
4586
  if (SYSTEM_FILES.includes(filepath)) {
4572
4587
  throw new Error(`Unexpected get for config file ${filepath}`);
4573
4588
  } else {
4574
4589
  const tinaSchema = await this.getSchema(this.level);
4575
- const extension = path3.extname(filepath);
4590
+ const extension = path2.extname(filepath);
4576
4591
  const contentObject = await this.level.sublevel(
4577
4592
  CONTENT_ROOT_PREFIX,
4578
4593
  SUBLEVEL_OPTIONS
@@ -4676,6 +4691,17 @@ var Database = class {
4676
4691
  const normalizedPath = normalizePath(filepath);
4677
4692
  const dataFields = await this.formatBodyOnPayload(filepath, data);
4678
4693
  const collection = await this.collectionForPath(filepath);
4694
+ if (collection.match?.exclude || collection.match?.include) {
4695
+ const matches = this.tinaSchema.getMatches({ collection });
4696
+ const match = micromatch.isMatch(filepath, matches);
4697
+ if (!match) {
4698
+ throw new GraphQLError4(
4699
+ `File ${filepath} does not match collection ${collection.name} glob ${matches.join(
4700
+ ","
4701
+ )}. Please change the filename or update matches for ${collection.name} in your config file.`
4702
+ );
4703
+ }
4704
+ }
4679
4705
  const stringifiedFile = await this.stringifyFile(
4680
4706
  filepath,
4681
4707
  dataFields,
@@ -4762,7 +4788,7 @@ var Database = class {
4762
4788
  );
4763
4789
  const writeTemplateKey = templateDetails.info.type === "union";
4764
4790
  const aliasedData = applyNameOverrides(templateDetails.template, payload);
4765
- const extension = path3.extname(filepath);
4791
+ const extension = path2.extname(filepath);
4766
4792
  const stringifiedFile = stringifyFile(
4767
4793
  aliasedData,
4768
4794
  extension,
@@ -4788,7 +4814,7 @@ var Database = class {
4788
4814
  this.getLookup = async (returnType) => {
4789
4815
  await this.initLevel();
4790
4816
  const lookupPath = normalizePath(
4791
- path3.join(this.getGeneratedFolder(), `_lookup.json`)
4817
+ path2.join(this.getGeneratedFolder(), `_lookup.json`)
4792
4818
  );
4793
4819
  if (!this._lookup) {
4794
4820
  const _lookup = await this.level.sublevel(
@@ -4802,7 +4828,7 @@ var Database = class {
4802
4828
  this.getGraphQLSchema = async () => {
4803
4829
  await this.initLevel();
4804
4830
  const graphqlPath = normalizePath(
4805
- path3.join(this.getGeneratedFolder(), `_graphql.json`)
4831
+ path2.join(this.getGeneratedFolder(), `_graphql.json`)
4806
4832
  );
4807
4833
  return await this.level.sublevel(
4808
4834
  CONTENT_ROOT_PREFIX,
@@ -4814,7 +4840,7 @@ var Database = class {
4814
4840
  throw new Error(`No bridge configured`);
4815
4841
  }
4816
4842
  const graphqlPath = normalizePath(
4817
- path3.join(this.getGeneratedFolder(), `_graphql.json`)
4843
+ path2.join(this.getGeneratedFolder(), `_graphql.json`)
4818
4844
  );
4819
4845
  const _graphql = await this.bridge.get(graphqlPath);
4820
4846
  return JSON.parse(_graphql);
@@ -4822,7 +4848,7 @@ var Database = class {
4822
4848
  this.getTinaSchema = async (level) => {
4823
4849
  await this.initLevel();
4824
4850
  const schemaPath = normalizePath(
4825
- path3.join(this.getGeneratedFolder(), `_schema.json`)
4851
+ path2.join(this.getGeneratedFolder(), `_schema.json`)
4826
4852
  );
4827
4853
  return await (level || this.level).sublevel(
4828
4854
  CONTENT_ROOT_PREFIX,
@@ -5007,11 +5033,11 @@ var Database = class {
5007
5033
  }) => {
5008
5034
  if (this.bridge && this.bridge.supportsBuilding()) {
5009
5035
  await this.bridge.putConfig(
5010
- normalizePath(path3.join(this.getGeneratedFolder(), `_graphql.json`)),
5036
+ normalizePath(path2.join(this.getGeneratedFolder(), `_graphql.json`)),
5011
5037
  JSON.stringify(graphQLSchema)
5012
5038
  );
5013
5039
  await this.bridge.putConfig(
5014
- normalizePath(path3.join(this.getGeneratedFolder(), `_schema.json`)),
5040
+ normalizePath(path2.join(this.getGeneratedFolder(), `_schema.json`)),
5015
5041
  JSON.stringify(tinaSchema.schema)
5016
5042
  );
5017
5043
  }
@@ -5025,10 +5051,10 @@ var Database = class {
5025
5051
  throw new Error("No bridge configured");
5026
5052
  }
5027
5053
  await this.initLevel();
5028
- await this.indexStatusCallbackWrapper(async () => {
5054
+ const result = await this.indexStatusCallbackWrapper(async () => {
5029
5055
  const lookup = lookupFromLockFile || JSON.parse(
5030
5056
  await this.bridge.get(
5031
- normalizePath(path3.join(this.getGeneratedFolder(), "_lookup.json"))
5057
+ normalizePath(path2.join(this.getGeneratedFolder(), "_lookup.json"))
5032
5058
  )
5033
5059
  );
5034
5060
  let nextLevel;
@@ -5046,18 +5072,18 @@ var Database = class {
5046
5072
  SUBLEVEL_OPTIONS
5047
5073
  );
5048
5074
  await contentRootLevel.put(
5049
- normalizePath(path3.join(this.getGeneratedFolder(), "_graphql.json")),
5075
+ normalizePath(path2.join(this.getGeneratedFolder(), "_graphql.json")),
5050
5076
  graphQLSchema
5051
5077
  );
5052
5078
  await contentRootLevel.put(
5053
- normalizePath(path3.join(this.getGeneratedFolder(), "_schema.json")),
5079
+ normalizePath(path2.join(this.getGeneratedFolder(), "_schema.json")),
5054
5080
  tinaSchema.schema
5055
5081
  );
5056
5082
  await contentRootLevel.put(
5057
- normalizePath(path3.join(this.getGeneratedFolder(), "_lookup.json")),
5083
+ normalizePath(path2.join(this.getGeneratedFolder(), "_lookup.json")),
5058
5084
  lookup
5059
5085
  );
5060
- await this._indexAllContent(nextLevel);
5086
+ const result2 = await this._indexAllContent(nextLevel);
5061
5087
  if (this.config.version) {
5062
5088
  await this.updateDatabaseVersion(nextVersion);
5063
5089
  if (this.level) {
@@ -5065,7 +5091,9 @@ var Database = class {
5065
5091
  }
5066
5092
  this.level = nextLevel;
5067
5093
  }
5094
+ return result2;
5068
5095
  });
5096
+ return result;
5069
5097
  };
5070
5098
  this.deleteContentByPaths = async (documentPaths) => {
5071
5099
  await this.initLevel();
@@ -5159,6 +5187,7 @@ var Database = class {
5159
5187
  await this.onDelete(normalizePath(filepath));
5160
5188
  };
5161
5189
  this._indexAllContent = async (level) => {
5190
+ const warnings = [];
5162
5191
  const tinaSchema = await this.getSchema(level);
5163
5192
  const operations = [];
5164
5193
  const enqueueOps = async (ops) => {
@@ -5168,22 +5197,43 @@ var Database = class {
5168
5197
  await level.batch(batchOps);
5169
5198
  }
5170
5199
  };
5200
+ const filesSeen = /* @__PURE__ */ new Map();
5201
+ const duplicateFiles = /* @__PURE__ */ new Set();
5171
5202
  await sequential(tinaSchema.getCollections(), async (collection) => {
5172
- const documentPaths = await this.bridge.glob(
5173
- normalizePath(collection.path),
5174
- collection.format || "md"
5175
- );
5176
- await _indexContent(this, level, documentPaths, enqueueOps, collection);
5203
+ const normalPath = normalizePath(collection.path);
5204
+ const format = collection.format || "md";
5205
+ const documentPaths = await this.bridge.glob(normalPath, format);
5206
+ const matches = this.tinaSchema.getMatches({ collection });
5207
+ const filteredPaths = matches.length > 0 ? micromatch(documentPaths, matches) : documentPaths;
5208
+ filteredPaths.forEach((path4) => {
5209
+ if (filesSeen.has(path4)) {
5210
+ filesSeen.get(path4).push(collection.name);
5211
+ duplicateFiles.add(path4);
5212
+ } else {
5213
+ filesSeen.set(path4, [collection.name]);
5214
+ }
5215
+ });
5216
+ duplicateFiles.forEach((path4) => {
5217
+ warnings.push(
5218
+ `"${path4}" Found in multiple collections: ${filesSeen.get(path4).map((collection2) => `"${collection2}"`).join(
5219
+ ", "
5220
+ )}. This can cause unexpected behavior. We recommend updating the \`match\` property of those collections so that each file is in only one collection.
5221
+ This will be an error in the future.
5222
+ `
5223
+ );
5224
+ });
5225
+ await _indexContent(this, level, filteredPaths, enqueueOps, collection);
5177
5226
  });
5178
5227
  while (operations.length) {
5179
5228
  await level.batch(operations.splice(0, 25));
5180
5229
  }
5230
+ return { warnings };
5181
5231
  };
5182
5232
  this.addToLookupMap = async (lookup) => {
5183
5233
  if (!this.bridge) {
5184
5234
  throw new Error("No bridge configured");
5185
5235
  }
5186
- const lookupPath = path3.join(this.getGeneratedFolder(), `_lookup.json`);
5236
+ const lookupPath = path2.join(this.getGeneratedFolder(), `_lookup.json`);
5187
5237
  let lookupMap;
5188
5238
  try {
5189
5239
  lookupMap = JSON.parse(await this.bridge.get(normalizePath(lookupPath)));
@@ -5284,8 +5334,9 @@ var Database = class {
5284
5334
  async indexStatusCallbackWrapper(fn) {
5285
5335
  await this.indexStatusCallback({ status: "inprogress" });
5286
5336
  try {
5287
- await fn();
5337
+ const result = await fn();
5288
5338
  await this.indexStatusCallback({ status: "complete" });
5339
+ return result;
5289
5340
  } catch (error) {
5290
5341
  await this.indexStatusCallback({ status: "failed", error });
5291
5342
  throw error;
@@ -5314,7 +5365,7 @@ var _indexContent = async (database, level, documentPaths, enqueueOps, collectio
5314
5365
  const dataString = await database.bridge.get(normalizePath(filepath));
5315
5366
  const data = parseFile(
5316
5367
  dataString,
5317
- path3.extname(filepath),
5368
+ path2.extname(filepath),
5318
5369
  (yup3) => yup3.object({}),
5319
5370
  {
5320
5371
  frontmatterDelimiters: collection?.frontmatterDelimiters,
@@ -5425,22 +5476,19 @@ var TinaLevelClient = class extends ManyLevelGuest {
5425
5476
  };
5426
5477
 
5427
5478
  // src/database/bridge/filesystem.ts
5428
- import fs2 from "fs-extra";
5479
+ import fs from "fs-extra";
5429
5480
  import fg from "fast-glob";
5430
- import path4 from "path";
5481
+ import path3 from "path";
5431
5482
  import normalize from "normalize-path";
5432
5483
  var FilesystemBridge = class {
5433
- constructor(rootPath) {
5484
+ constructor(rootPath, outputPath) {
5434
5485
  this.rootPath = rootPath || "";
5435
- this.outputPath = rootPath || "";
5436
- }
5437
- addOutputPath(outputPath) {
5438
- this.outputPath = outputPath;
5486
+ this.outputPath = outputPath || rootPath;
5439
5487
  }
5440
5488
  async glob(pattern, extension) {
5441
- const basePath = path4.join(this.outputPath, ...pattern.split("/"));
5489
+ const basePath = path3.join(this.outputPath, ...pattern.split("/"));
5442
5490
  const items = await fg(
5443
- path4.join(basePath, "**", `/*${extension}`).replace(/\\/g, "/"),
5491
+ path3.join(basePath, "**", `/*${extension}`).replace(/\\/g, "/"),
5444
5492
  {
5445
5493
  dot: true
5446
5494
  }
@@ -5454,10 +5502,10 @@ var FilesystemBridge = class {
5454
5502
  return true;
5455
5503
  }
5456
5504
  async delete(filepath) {
5457
- await fs2.remove(path4.join(this.outputPath, filepath));
5505
+ await fs.remove(path3.join(this.outputPath, filepath));
5458
5506
  }
5459
5507
  async get(filepath) {
5460
- return fs2.readFileSync(path4.join(this.outputPath, filepath)).toString();
5508
+ return fs.readFileSync(path3.join(this.outputPath, filepath)).toString();
5461
5509
  }
5462
5510
  async putConfig(filepath, data) {
5463
5511
  if (this.rootPath !== this.outputPath) {
@@ -5469,7 +5517,7 @@ var FilesystemBridge = class {
5469
5517
  }
5470
5518
  async put(filepath, data, basePathOverride) {
5471
5519
  const basePath = basePathOverride || this.outputPath;
5472
- await fs2.outputFileSync(path4.join(basePath, filepath), data);
5520
+ await fs.outputFileSync(path3.join(basePath, filepath), data);
5473
5521
  }
5474
5522
  };
5475
5523
  var AuditFileSystemBridge = class extends FilesystemBridge {
@@ -5487,7 +5535,7 @@ var AuditFileSystemBridge = class extends FilesystemBridge {
5487
5535
 
5488
5536
  // src/database/bridge/isomorphic.ts
5489
5537
  import git from "isomorphic-git";
5490
- import fs3 from "fs-extra";
5538
+ import fs2 from "fs-extra";
5491
5539
  import globParent from "glob-parent";
5492
5540
  import normalize2 from "normalize-path";
5493
5541
  import { GraphQLError as GraphQLError5 } from "graphql";
@@ -5506,7 +5554,7 @@ var IsomorphicBridge = class {
5506
5554
  gitRoot,
5507
5555
  author,
5508
5556
  committer,
5509
- fsModule = fs3,
5557
+ fsModule = fs2,
5510
5558
  commitMessage = "Update from GraphQL client",
5511
5559
  ref,
5512
5560
  onPut,
@@ -5550,7 +5598,7 @@ var IsomorphicBridge = class {
5550
5598
  async listEntries({
5551
5599
  pattern,
5552
5600
  entry,
5553
- path: path6,
5601
+ path: path4,
5554
5602
  results
5555
5603
  }) {
5556
5604
  const treeResult = await git.readTree({
@@ -5560,7 +5608,7 @@ var IsomorphicBridge = class {
5560
5608
  });
5561
5609
  const children = [];
5562
5610
  for (const childEntry of treeResult.tree) {
5563
- const childPath = path6 ? `${path6}/${childEntry.path}` : childEntry.path;
5611
+ const childPath = path4 ? `${path4}/${childEntry.path}` : childEntry.path;
5564
5612
  if (childEntry.type === "tree") {
5565
5613
  children.push(childEntry);
5566
5614
  } else {
@@ -5570,7 +5618,7 @@ var IsomorphicBridge = class {
5570
5618
  }
5571
5619
  }
5572
5620
  for (const childEntry of children) {
5573
- const childPath = path6 ? `${path6}/${childEntry.path}` : childEntry.path;
5621
+ const childPath = path4 ? `${path4}/${childEntry.path}` : childEntry.path;
5574
5622
  await this.listEntries({
5575
5623
  pattern,
5576
5624
  entry: childEntry,
@@ -5579,17 +5627,17 @@ var IsomorphicBridge = class {
5579
5627
  });
5580
5628
  }
5581
5629
  }
5582
- async resolvePathEntries(path6, ref) {
5583
- let pathParts = path6.split("/");
5630
+ async resolvePathEntries(path4, ref) {
5631
+ let pathParts = path4.split("/");
5584
5632
  const result = await git.walk({
5585
5633
  ...this.isomorphicConfig,
5586
5634
  map: async (filepath, [head]) => {
5587
5635
  if (head._fullpath === ".") {
5588
5636
  return head;
5589
5637
  }
5590
- if (path6.startsWith(filepath)) {
5591
- if (dirname(path6) === dirname(filepath)) {
5592
- if (path6 === filepath) {
5638
+ if (path4.startsWith(filepath)) {
5639
+ if (dirname(path4) === dirname(filepath)) {
5640
+ if (path4 === filepath) {
5593
5641
  return head;
5594
5642
  }
5595
5643
  } else {
@@ -5609,7 +5657,7 @@ var IsomorphicBridge = class {
5609
5657
  }
5610
5658
  return { pathParts, pathEntries };
5611
5659
  }
5612
- async updateTreeHierarchy(existingOid, updatedOid, path6, type, pathEntries, pathParts) {
5660
+ async updateTreeHierarchy(existingOid, updatedOid, path4, type, pathEntries, pathParts) {
5613
5661
  const lastIdx = pathEntries.length - 1;
5614
5662
  const parentEntry = pathEntries[lastIdx];
5615
5663
  const parentPath = pathParts[lastIdx];
@@ -5624,7 +5672,7 @@ var IsomorphicBridge = class {
5624
5672
  cache: this.cache
5625
5673
  });
5626
5674
  tree = existingOid ? treeResult.tree.map((entry) => {
5627
- if (entry.path === path6) {
5675
+ if (entry.path === path4) {
5628
5676
  entry.oid = updatedOid;
5629
5677
  }
5630
5678
  return entry;
@@ -5633,7 +5681,7 @@ var IsomorphicBridge = class {
5633
5681
  {
5634
5682
  oid: updatedOid,
5635
5683
  type,
5636
- path: path6,
5684
+ path: path4,
5637
5685
  mode
5638
5686
  }
5639
5687
  ];
@@ -5642,7 +5690,7 @@ var IsomorphicBridge = class {
5642
5690
  {
5643
5691
  oid: updatedOid,
5644
5692
  type,
5645
- path: path6,
5693
+ path: path4,
5646
5694
  mode
5647
5695
  }
5648
5696
  ];
@@ -5743,7 +5791,7 @@ var IsomorphicBridge = class {
5743
5791
  path: parentPath,
5744
5792
  results
5745
5793
  });
5746
- return results.map((path6) => this.unqualifyPath(path6)).filter((path6) => path6.endsWith(extension));
5794
+ return results.map((path4) => this.unqualifyPath(path4)).filter((path4) => path4.endsWith(extension));
5747
5795
  }
5748
5796
  supportsBuilding() {
5749
5797
  return true;
@@ -5879,16 +5927,12 @@ var IsomorphicBridge = class {
5879
5927
  };
5880
5928
 
5881
5929
  // src/index.ts
5882
- var buildSchema = async (rootPath, database, flags) => {
5883
- const tempConfig = path5.join(rootPath, ".tina", "__generated__", "config");
5884
- const config = await fs4.readFileSync(path5.join(tempConfig, "schema.json")).toString();
5885
- await fs4.remove(tempConfig);
5886
- const { graphQLSchema, tinaSchema } = await buildDotTinaFiles({
5930
+ var buildSchema = async (database, config, flags) => {
5931
+ return buildDotTinaFiles({
5887
5932
  database,
5888
- config: JSON.parse(config),
5933
+ config,
5889
5934
  flags
5890
5935
  });
5891
- return { graphQLSchema, tinaSchema };
5892
5936
  };
5893
5937
  var getASTSchema = async (database) => {
5894
5938
  const gqlAst = await database.getGraphQLSchemaFromBridge();