@tinacms/graphql 1.3.5 → 1.4.1
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/build.d.ts +4 -2
- package/dist/database/bridge/filesystem.d.ts +1 -2
- package/dist/database/index.d.ts +6 -5
- package/dist/database/util.d.ts +2 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.es.js +159 -109
- package/dist/index.js +179 -125
- package/dist/resolver/index.d.ts +8 -2
- package/package.json +7 -5
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
|
|
@@ -2223,11 +2220,11 @@ Visit https://tina.io/docs/errors/ui-not-supported/ for more information
|
|
|
2223
2220
|
switch (field.type) {
|
|
2224
2221
|
case "boolean":
|
|
2225
2222
|
case "datetime":
|
|
2226
|
-
case "image":
|
|
2227
2223
|
case "number":
|
|
2228
2224
|
if (field.list) {
|
|
2229
2225
|
console.warn(listWarningMsg);
|
|
2230
2226
|
}
|
|
2227
|
+
case "image":
|
|
2231
2228
|
case "string":
|
|
2232
2229
|
return astBuilder.FieldDefinition({
|
|
2233
2230
|
name: field.name,
|
|
@@ -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(
|
|
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(
|
|
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(
|
|
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
|
-
|
|
2403
|
-
r[
|
|
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
|
-
|
|
2412
|
-
|
|
2413
|
-
|
|
2414
|
-
|
|
2415
|
-
|
|
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
|
+
);
|
|
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;
|
|
2416
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.
|
|
2494
|
+
version: "1.4.1",
|
|
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
|
|
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(
|
|
2649
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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 = (
|
|
3016
|
-
if (
|
|
3017
|
-
return `/${
|
|
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
|
-
|
|
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
|
-
} =
|
|
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 =
|
|
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 =
|
|
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: (
|
|
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
|
|
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 = () =>
|
|
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 =
|
|
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 =
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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(
|
|
5036
|
+
normalizePath(path2.join(this.getGeneratedFolder(), `_graphql.json`)),
|
|
5011
5037
|
JSON.stringify(graphQLSchema)
|
|
5012
5038
|
);
|
|
5013
5039
|
await this.bridge.putConfig(
|
|
5014
|
-
normalizePath(
|
|
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(
|
|
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(
|
|
5075
|
+
normalizePath(path2.join(this.getGeneratedFolder(), "_graphql.json")),
|
|
5050
5076
|
graphQLSchema
|
|
5051
5077
|
);
|
|
5052
5078
|
await contentRootLevel.put(
|
|
5053
|
-
normalizePath(
|
|
5079
|
+
normalizePath(path2.join(this.getGeneratedFolder(), "_schema.json")),
|
|
5054
5080
|
tinaSchema.schema
|
|
5055
5081
|
);
|
|
5056
5082
|
await contentRootLevel.put(
|
|
5057
|
-
normalizePath(
|
|
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
|
|
5173
|
-
|
|
5174
|
-
|
|
5175
|
-
);
|
|
5176
|
-
|
|
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 =
|
|
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
|
-
|
|
5368
|
+
path2.extname(filepath),
|
|
5318
5369
|
(yup3) => yup3.object({}),
|
|
5319
5370
|
{
|
|
5320
5371
|
frontmatterDelimiters: collection?.frontmatterDelimiters,
|
|
@@ -5392,9 +5443,15 @@ var getTemplateForFile = (templateInfo, data) => {
|
|
|
5392
5443
|
}
|
|
5393
5444
|
if (templateInfo.type === "union") {
|
|
5394
5445
|
if (hasOwnProperty(data, "_template")) {
|
|
5395
|
-
|
|
5446
|
+
const template = templateInfo.templates.find(
|
|
5396
5447
|
(t) => lastItem(t.namespace) === data._template
|
|
5397
5448
|
);
|
|
5449
|
+
if (!template) {
|
|
5450
|
+
throw new Error(
|
|
5451
|
+
`Unable to find template "${data._template}". Possible templates are: ${templateInfo.templates.map((template2) => `"${template2.name}"`).join(", ")}.`
|
|
5452
|
+
);
|
|
5453
|
+
}
|
|
5454
|
+
return template;
|
|
5398
5455
|
} else {
|
|
5399
5456
|
throw new Error(
|
|
5400
5457
|
`Expected _template to be provided for document in an ambiguous collection`
|
|
@@ -5425,22 +5482,19 @@ var TinaLevelClient = class extends ManyLevelGuest {
|
|
|
5425
5482
|
};
|
|
5426
5483
|
|
|
5427
5484
|
// src/database/bridge/filesystem.ts
|
|
5428
|
-
import
|
|
5485
|
+
import fs from "fs-extra";
|
|
5429
5486
|
import fg from "fast-glob";
|
|
5430
|
-
import
|
|
5487
|
+
import path3 from "path";
|
|
5431
5488
|
import normalize from "normalize-path";
|
|
5432
5489
|
var FilesystemBridge = class {
|
|
5433
|
-
constructor(rootPath) {
|
|
5490
|
+
constructor(rootPath, outputPath) {
|
|
5434
5491
|
this.rootPath = rootPath || "";
|
|
5435
|
-
this.outputPath =
|
|
5436
|
-
}
|
|
5437
|
-
addOutputPath(outputPath) {
|
|
5438
|
-
this.outputPath = outputPath;
|
|
5492
|
+
this.outputPath = outputPath || rootPath;
|
|
5439
5493
|
}
|
|
5440
5494
|
async glob(pattern, extension) {
|
|
5441
|
-
const basePath =
|
|
5495
|
+
const basePath = path3.join(this.outputPath, ...pattern.split("/"));
|
|
5442
5496
|
const items = await fg(
|
|
5443
|
-
|
|
5497
|
+
path3.join(basePath, "**", `/*${extension}`).replace(/\\/g, "/"),
|
|
5444
5498
|
{
|
|
5445
5499
|
dot: true
|
|
5446
5500
|
}
|
|
@@ -5454,10 +5508,10 @@ var FilesystemBridge = class {
|
|
|
5454
5508
|
return true;
|
|
5455
5509
|
}
|
|
5456
5510
|
async delete(filepath) {
|
|
5457
|
-
await
|
|
5511
|
+
await fs.remove(path3.join(this.outputPath, filepath));
|
|
5458
5512
|
}
|
|
5459
5513
|
async get(filepath) {
|
|
5460
|
-
return
|
|
5514
|
+
return fs.readFileSync(path3.join(this.outputPath, filepath)).toString();
|
|
5461
5515
|
}
|
|
5462
5516
|
async putConfig(filepath, data) {
|
|
5463
5517
|
if (this.rootPath !== this.outputPath) {
|
|
@@ -5469,7 +5523,7 @@ var FilesystemBridge = class {
|
|
|
5469
5523
|
}
|
|
5470
5524
|
async put(filepath, data, basePathOverride) {
|
|
5471
5525
|
const basePath = basePathOverride || this.outputPath;
|
|
5472
|
-
await
|
|
5526
|
+
await fs.outputFileSync(path3.join(basePath, filepath), data);
|
|
5473
5527
|
}
|
|
5474
5528
|
};
|
|
5475
5529
|
var AuditFileSystemBridge = class extends FilesystemBridge {
|
|
@@ -5487,7 +5541,7 @@ var AuditFileSystemBridge = class extends FilesystemBridge {
|
|
|
5487
5541
|
|
|
5488
5542
|
// src/database/bridge/isomorphic.ts
|
|
5489
5543
|
import git from "isomorphic-git";
|
|
5490
|
-
import
|
|
5544
|
+
import fs2 from "fs-extra";
|
|
5491
5545
|
import globParent from "glob-parent";
|
|
5492
5546
|
import normalize2 from "normalize-path";
|
|
5493
5547
|
import { GraphQLError as GraphQLError5 } from "graphql";
|
|
@@ -5506,7 +5560,7 @@ var IsomorphicBridge = class {
|
|
|
5506
5560
|
gitRoot,
|
|
5507
5561
|
author,
|
|
5508
5562
|
committer,
|
|
5509
|
-
fsModule =
|
|
5563
|
+
fsModule = fs2,
|
|
5510
5564
|
commitMessage = "Update from GraphQL client",
|
|
5511
5565
|
ref,
|
|
5512
5566
|
onPut,
|
|
@@ -5550,7 +5604,7 @@ var IsomorphicBridge = class {
|
|
|
5550
5604
|
async listEntries({
|
|
5551
5605
|
pattern,
|
|
5552
5606
|
entry,
|
|
5553
|
-
path:
|
|
5607
|
+
path: path4,
|
|
5554
5608
|
results
|
|
5555
5609
|
}) {
|
|
5556
5610
|
const treeResult = await git.readTree({
|
|
@@ -5560,7 +5614,7 @@ var IsomorphicBridge = class {
|
|
|
5560
5614
|
});
|
|
5561
5615
|
const children = [];
|
|
5562
5616
|
for (const childEntry of treeResult.tree) {
|
|
5563
|
-
const childPath =
|
|
5617
|
+
const childPath = path4 ? `${path4}/${childEntry.path}` : childEntry.path;
|
|
5564
5618
|
if (childEntry.type === "tree") {
|
|
5565
5619
|
children.push(childEntry);
|
|
5566
5620
|
} else {
|
|
@@ -5570,7 +5624,7 @@ var IsomorphicBridge = class {
|
|
|
5570
5624
|
}
|
|
5571
5625
|
}
|
|
5572
5626
|
for (const childEntry of children) {
|
|
5573
|
-
const childPath =
|
|
5627
|
+
const childPath = path4 ? `${path4}/${childEntry.path}` : childEntry.path;
|
|
5574
5628
|
await this.listEntries({
|
|
5575
5629
|
pattern,
|
|
5576
5630
|
entry: childEntry,
|
|
@@ -5579,17 +5633,17 @@ var IsomorphicBridge = class {
|
|
|
5579
5633
|
});
|
|
5580
5634
|
}
|
|
5581
5635
|
}
|
|
5582
|
-
async resolvePathEntries(
|
|
5583
|
-
let pathParts =
|
|
5636
|
+
async resolvePathEntries(path4, ref) {
|
|
5637
|
+
let pathParts = path4.split("/");
|
|
5584
5638
|
const result = await git.walk({
|
|
5585
5639
|
...this.isomorphicConfig,
|
|
5586
5640
|
map: async (filepath, [head]) => {
|
|
5587
5641
|
if (head._fullpath === ".") {
|
|
5588
5642
|
return head;
|
|
5589
5643
|
}
|
|
5590
|
-
if (
|
|
5591
|
-
if (dirname(
|
|
5592
|
-
if (
|
|
5644
|
+
if (path4.startsWith(filepath)) {
|
|
5645
|
+
if (dirname(path4) === dirname(filepath)) {
|
|
5646
|
+
if (path4 === filepath) {
|
|
5593
5647
|
return head;
|
|
5594
5648
|
}
|
|
5595
5649
|
} else {
|
|
@@ -5609,7 +5663,7 @@ var IsomorphicBridge = class {
|
|
|
5609
5663
|
}
|
|
5610
5664
|
return { pathParts, pathEntries };
|
|
5611
5665
|
}
|
|
5612
|
-
async updateTreeHierarchy(existingOid, updatedOid,
|
|
5666
|
+
async updateTreeHierarchy(existingOid, updatedOid, path4, type, pathEntries, pathParts) {
|
|
5613
5667
|
const lastIdx = pathEntries.length - 1;
|
|
5614
5668
|
const parentEntry = pathEntries[lastIdx];
|
|
5615
5669
|
const parentPath = pathParts[lastIdx];
|
|
@@ -5624,7 +5678,7 @@ var IsomorphicBridge = class {
|
|
|
5624
5678
|
cache: this.cache
|
|
5625
5679
|
});
|
|
5626
5680
|
tree = existingOid ? treeResult.tree.map((entry) => {
|
|
5627
|
-
if (entry.path ===
|
|
5681
|
+
if (entry.path === path4) {
|
|
5628
5682
|
entry.oid = updatedOid;
|
|
5629
5683
|
}
|
|
5630
5684
|
return entry;
|
|
@@ -5633,7 +5687,7 @@ var IsomorphicBridge = class {
|
|
|
5633
5687
|
{
|
|
5634
5688
|
oid: updatedOid,
|
|
5635
5689
|
type,
|
|
5636
|
-
path:
|
|
5690
|
+
path: path4,
|
|
5637
5691
|
mode
|
|
5638
5692
|
}
|
|
5639
5693
|
];
|
|
@@ -5642,7 +5696,7 @@ var IsomorphicBridge = class {
|
|
|
5642
5696
|
{
|
|
5643
5697
|
oid: updatedOid,
|
|
5644
5698
|
type,
|
|
5645
|
-
path:
|
|
5699
|
+
path: path4,
|
|
5646
5700
|
mode
|
|
5647
5701
|
}
|
|
5648
5702
|
];
|
|
@@ -5743,7 +5797,7 @@ var IsomorphicBridge = class {
|
|
|
5743
5797
|
path: parentPath,
|
|
5744
5798
|
results
|
|
5745
5799
|
});
|
|
5746
|
-
return results.map((
|
|
5800
|
+
return results.map((path4) => this.unqualifyPath(path4)).filter((path4) => path4.endsWith(extension));
|
|
5747
5801
|
}
|
|
5748
5802
|
supportsBuilding() {
|
|
5749
5803
|
return true;
|
|
@@ -5879,16 +5933,12 @@ var IsomorphicBridge = class {
|
|
|
5879
5933
|
};
|
|
5880
5934
|
|
|
5881
5935
|
// src/index.ts
|
|
5882
|
-
var buildSchema = async (
|
|
5883
|
-
|
|
5884
|
-
const config = await fs4.readFileSync(path5.join(tempConfig, "schema.json")).toString();
|
|
5885
|
-
await fs4.remove(tempConfig);
|
|
5886
|
-
const { graphQLSchema, tinaSchema } = await buildDotTinaFiles({
|
|
5936
|
+
var buildSchema = async (database, config, flags) => {
|
|
5937
|
+
return buildDotTinaFiles({
|
|
5887
5938
|
database,
|
|
5888
|
-
config
|
|
5939
|
+
config,
|
|
5889
5940
|
flags
|
|
5890
5941
|
});
|
|
5891
|
-
return { graphQLSchema, tinaSchema };
|
|
5892
5942
|
};
|
|
5893
5943
|
var getASTSchema = async (database) => {
|
|
5894
5944
|
const gqlAst = await database.getGraphQLSchemaFromBridge();
|