@tinacms/graphql 0.0.0-bdc07c1-20250506013835 → 0.0.0-be4681c-20250619070932
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/README.md +144 -0
- package/dist/database/bridge/filesystem.d.ts +1 -1
- package/dist/database/util.d.ts +2 -5
- package/dist/index.d.ts +32 -1
- package/dist/index.js +368 -401
- package/dist/index.mjs +249 -256
- package/dist/resolver/index.d.ts +5 -5
- package/dist/schema/createSchema.d.ts +0 -3
- package/dist/schema/validate.d.ts +0 -3
- package/package.json +5 -10
- package/readme.md +0 -194
package/dist/index.js
CHANGED
|
@@ -1435,13 +1435,12 @@ var checkPasswordHash = async ({
|
|
|
1435
1435
|
return true;
|
|
1436
1436
|
};
|
|
1437
1437
|
var mapUserFields = (collectable, prefix = []) => {
|
|
1438
|
-
var _a, _b, _c, _d, _e;
|
|
1439
1438
|
const results = [];
|
|
1440
|
-
const passwordFields =
|
|
1439
|
+
const passwordFields = collectable.fields?.filter((field) => field.type === "password") || [];
|
|
1441
1440
|
if (passwordFields.length > 1) {
|
|
1442
1441
|
throw new Error("Only one password field is allowed");
|
|
1443
1442
|
}
|
|
1444
|
-
const idFields =
|
|
1443
|
+
const idFields = collectable.fields?.filter((field) => field.uid) || [];
|
|
1445
1444
|
if (idFields.length > 1) {
|
|
1446
1445
|
throw new Error("Only one uid field is allowed");
|
|
1447
1446
|
}
|
|
@@ -1449,11 +1448,11 @@ var mapUserFields = (collectable, prefix = []) => {
|
|
|
1449
1448
|
results.push({
|
|
1450
1449
|
path: prefix,
|
|
1451
1450
|
collectable,
|
|
1452
|
-
idFieldName:
|
|
1453
|
-
passwordFieldName:
|
|
1451
|
+
idFieldName: idFields[0]?.name,
|
|
1452
|
+
passwordFieldName: passwordFields[0]?.name
|
|
1454
1453
|
});
|
|
1455
1454
|
}
|
|
1456
|
-
|
|
1455
|
+
collectable.fields?.forEach((field) => {
|
|
1457
1456
|
if (field.type === "object" && field.fields) {
|
|
1458
1457
|
results.push(...mapUserFields(field, [...prefix, field.name]));
|
|
1459
1458
|
}
|
|
@@ -1944,13 +1943,12 @@ var Builder = class {
|
|
|
1944
1943
|
*
|
|
1945
1944
|
* */
|
|
1946
1945
|
this._getCollectionFragmentSelections = async (collection, depth) => {
|
|
1947
|
-
var _a;
|
|
1948
1946
|
const selections = [];
|
|
1949
1947
|
selections.push({
|
|
1950
1948
|
name: { kind: "Name", value: "__typename" },
|
|
1951
1949
|
kind: "Field"
|
|
1952
1950
|
});
|
|
1953
|
-
if (
|
|
1951
|
+
if (collection.fields?.length > 0) {
|
|
1954
1952
|
await sequential(collection.fields, async (x) => {
|
|
1955
1953
|
const field = await this._buildFieldNodeForFragments(x, depth);
|
|
1956
1954
|
selections.push(field);
|
|
@@ -1965,7 +1963,6 @@ var Builder = class {
|
|
|
1965
1963
|
return selections;
|
|
1966
1964
|
};
|
|
1967
1965
|
this._buildFieldNodeForFragments = async (field, depth) => {
|
|
1968
|
-
var _a, _b;
|
|
1969
1966
|
switch (field.type) {
|
|
1970
1967
|
case "string":
|
|
1971
1968
|
case "image":
|
|
@@ -1998,7 +1995,7 @@ var Builder = class {
|
|
|
1998
1995
|
selections: filterSelections([passwordValue, passwordChangeRequired])
|
|
1999
1996
|
});
|
|
2000
1997
|
case "object":
|
|
2001
|
-
if (
|
|
1998
|
+
if (field.fields?.length > 0) {
|
|
2002
1999
|
const selections2 = [];
|
|
2003
2000
|
await sequential(field.fields, async (item) => {
|
|
2004
2001
|
const field2 = await this._buildFieldNodeForFragments(item, depth);
|
|
@@ -2011,7 +2008,7 @@ var Builder = class {
|
|
|
2011
2008
|
...filterSelections(selections2)
|
|
2012
2009
|
]
|
|
2013
2010
|
});
|
|
2014
|
-
} else if (
|
|
2011
|
+
} else if (field.templates?.length > 0) {
|
|
2015
2012
|
const selections2 = [];
|
|
2016
2013
|
await sequential(field.templates, async (tem) => {
|
|
2017
2014
|
if (typeof tem === "object") {
|
|
@@ -2673,7 +2670,7 @@ var Builder = class {
|
|
|
2673
2670
|
this.addToLookupMap({
|
|
2674
2671
|
type: name,
|
|
2675
2672
|
resolveType: "unionData",
|
|
2676
|
-
collection: collection
|
|
2673
|
+
collection: collection?.name,
|
|
2677
2674
|
typeMap
|
|
2678
2675
|
});
|
|
2679
2676
|
return astBuilder.UnionTypeDefinition({ name, types });
|
|
@@ -2883,9 +2880,8 @@ Visit https://tina.io/docs/errors/ui-not-supported/ for more information
|
|
|
2883
2880
|
]
|
|
2884
2881
|
});
|
|
2885
2882
|
};
|
|
2886
|
-
var _a, _b, _c, _d;
|
|
2887
2883
|
this.maxDepth = // @ts-ignore
|
|
2888
|
-
|
|
2884
|
+
config?.tinaSchema.schema?.config?.client?.referenceDepth ?? 2;
|
|
2889
2885
|
this.tinaSchema = config.tinaSchema;
|
|
2890
2886
|
this.lookupMap = {};
|
|
2891
2887
|
}
|
|
@@ -2974,7 +2970,7 @@ var validationCollectionsPathAndMatch = (collections) => {
|
|
|
2974
2970
|
return;
|
|
2975
2971
|
}
|
|
2976
2972
|
const noMatchCollections = collections.filter((x) => {
|
|
2977
|
-
return typeof
|
|
2973
|
+
return typeof x?.match === "undefined";
|
|
2978
2974
|
}).map((x) => `${x.path}${x.format || "md"}`);
|
|
2979
2975
|
if (noMatchCollections.length !== new Set(noMatchCollections).size) {
|
|
2980
2976
|
throw new Error(
|
|
@@ -2985,10 +2981,7 @@ var validationCollectionsPathAndMatch = (collections) => {
|
|
|
2985
2981
|
const hasMatchAndPath = collections.filter((x) => {
|
|
2986
2982
|
return typeof x.path !== "undefined" && typeof x.match !== "undefined";
|
|
2987
2983
|
}).map(
|
|
2988
|
-
(x) => {
|
|
2989
|
-
var _a, _b;
|
|
2990
|
-
return `${x.path}|${((_a = x == null ? void 0 : x.match) == null ? void 0 : _a.exclude) || ""}|${((_b = x == null ? void 0 : x.match) == null ? void 0 : _b.include) || ""}|${x.format || "md"}`;
|
|
2991
|
-
}
|
|
2984
|
+
(x) => `${x.path}|${x?.match?.exclude || ""}|${x?.match?.include || ""}|${x.format || "md"}`
|
|
2992
2985
|
);
|
|
2993
2986
|
if (hasMatchAndPath.length !== new Set(hasMatchAndPath).size) {
|
|
2994
2987
|
throw new Error(
|
|
@@ -3012,7 +3005,7 @@ var validationCollectionsPathAndMatch = (collections) => {
|
|
|
3012
3005
|
);
|
|
3013
3006
|
}
|
|
3014
3007
|
const matches = collectionsArr.map(
|
|
3015
|
-
(x) => typeof
|
|
3008
|
+
(x) => typeof x?.match === "object" ? JSON.stringify(x.match) : ""
|
|
3016
3009
|
);
|
|
3017
3010
|
if (matches.length === new Set(matches).size) {
|
|
3018
3011
|
return;
|
|
@@ -3090,7 +3083,7 @@ var validateField = async (field) => {
|
|
|
3090
3083
|
// package.json
|
|
3091
3084
|
var package_default = {
|
|
3092
3085
|
name: "@tinacms/graphql",
|
|
3093
|
-
version: "1.5.
|
|
3086
|
+
version: "1.5.18",
|
|
3094
3087
|
main: "dist/index.js",
|
|
3095
3088
|
module: "dist/index.mjs",
|
|
3096
3089
|
typings: "dist/index.d.ts",
|
|
@@ -3116,7 +3109,6 @@ var package_default = {
|
|
|
3116
3109
|
types: "pnpm tsc",
|
|
3117
3110
|
build: "tinacms-scripts build",
|
|
3118
3111
|
docs: "pnpm typedoc",
|
|
3119
|
-
serve: "pnpm nodemon dist/server.js",
|
|
3120
3112
|
test: "vitest run",
|
|
3121
3113
|
"test-watch": "vitest"
|
|
3122
3114
|
},
|
|
@@ -3145,9 +3137,6 @@ var package_default = {
|
|
|
3145
3137
|
scmp: "^2.1.0",
|
|
3146
3138
|
yup: "^0.32.11"
|
|
3147
3139
|
},
|
|
3148
|
-
peerDependencies: {
|
|
3149
|
-
"@tinacms/common": "workspace:*"
|
|
3150
|
-
},
|
|
3151
3140
|
publishConfig: {
|
|
3152
3141
|
registry: "https://registry.npmjs.org"
|
|
3153
3142
|
},
|
|
@@ -3174,7 +3163,6 @@ var package_default = {
|
|
|
3174
3163
|
"@types/yup": "^0.29.14",
|
|
3175
3164
|
"jest-file-snapshot": "^0.5.0",
|
|
3176
3165
|
"memory-level": "^1.0.0",
|
|
3177
|
-
nodemon: "3.1.4",
|
|
3178
3166
|
typescript: "^5.7.3",
|
|
3179
3167
|
vite: "^4.5.9",
|
|
3180
3168
|
vitest: "^0.32.4",
|
|
@@ -3260,7 +3248,6 @@ var _buildQueries = async (builder, tinaSchema) => {
|
|
|
3260
3248
|
const operationsDefinitions = [];
|
|
3261
3249
|
const collections = tinaSchema.getCollections();
|
|
3262
3250
|
await sequential(collections, async (collection) => {
|
|
3263
|
-
var _a, _b, _c;
|
|
3264
3251
|
const queryName = NAMER.queryName(collection.namespace);
|
|
3265
3252
|
const queryListName = NAMER.generateQueryListName(collection.namespace);
|
|
3266
3253
|
const queryFilterTypeName = NAMER.dataFilterTypeName(collection.namespace);
|
|
@@ -3275,7 +3262,7 @@ var _buildQueries = async (builder, tinaSchema) => {
|
|
|
3275
3262
|
filterType: queryFilterTypeName,
|
|
3276
3263
|
// look for flag to see if the data layer is enabled
|
|
3277
3264
|
dataLayer: Boolean(
|
|
3278
|
-
|
|
3265
|
+
tinaSchema.config?.meta?.flags?.find((x) => x === "experimentalData")
|
|
3279
3266
|
)
|
|
3280
3267
|
})
|
|
3281
3268
|
);
|
|
@@ -3387,251 +3374,11 @@ var import_graphql5 = require("graphql");
|
|
|
3387
3374
|
// src/resolver/index.ts
|
|
3388
3375
|
var import_path3 = __toESM(require("path"));
|
|
3389
3376
|
var import_isValid = __toESM(require("date-fns/isValid/index.js"));
|
|
3377
|
+
var import_jsonpath_plus2 = require("jsonpath-plus");
|
|
3390
3378
|
|
|
3391
3379
|
// src/mdx/index.ts
|
|
3392
3380
|
var import_mdx = require("@tinacms/mdx");
|
|
3393
3381
|
|
|
3394
|
-
// src/resolver/index.ts
|
|
3395
|
-
var import_jsonpath_plus2 = require("jsonpath-plus");
|
|
3396
|
-
|
|
3397
|
-
// src/resolver/error.ts
|
|
3398
|
-
var TinaGraphQLError = class extends Error {
|
|
3399
|
-
constructor(message, extensions) {
|
|
3400
|
-
super(message);
|
|
3401
|
-
if (!this.name) {
|
|
3402
|
-
Object.defineProperty(this, "name", { value: "TinaGraphQLError" });
|
|
3403
|
-
}
|
|
3404
|
-
this.extensions = { ...extensions };
|
|
3405
|
-
}
|
|
3406
|
-
};
|
|
3407
|
-
var TinaFetchError = class extends Error {
|
|
3408
|
-
constructor(message, args) {
|
|
3409
|
-
super(message);
|
|
3410
|
-
this.name = "TinaFetchError";
|
|
3411
|
-
this.collection = args.collection;
|
|
3412
|
-
this.stack = args.stack;
|
|
3413
|
-
this.file = args.file;
|
|
3414
|
-
this.originalError = args.originalError;
|
|
3415
|
-
}
|
|
3416
|
-
};
|
|
3417
|
-
var TinaQueryError = class extends TinaFetchError {
|
|
3418
|
-
constructor(args) {
|
|
3419
|
-
super(
|
|
3420
|
-
`Error querying file ${args.file} from collection ${args.collection}. ${auditMessage(args.includeAuditMessage)}`,
|
|
3421
|
-
args
|
|
3422
|
-
);
|
|
3423
|
-
}
|
|
3424
|
-
};
|
|
3425
|
-
var TinaParseDocumentError = class extends TinaFetchError {
|
|
3426
|
-
constructor(args) {
|
|
3427
|
-
super(
|
|
3428
|
-
`Error parsing file ${args.file} from collection ${args.collection}. ${auditMessage(args.includeAuditMessage)}`,
|
|
3429
|
-
args
|
|
3430
|
-
);
|
|
3431
|
-
}
|
|
3432
|
-
toString() {
|
|
3433
|
-
return super.toString() + "\n OriginalError: \n" + this.originalError.toString();
|
|
3434
|
-
}
|
|
3435
|
-
};
|
|
3436
|
-
var auditMessage = (includeAuditMessage = true) => includeAuditMessage ? `Please run "tinacms audit" or add the --verbose option for more info` : "";
|
|
3437
|
-
var handleFetchErrorError = (e, verbose) => {
|
|
3438
|
-
if (e instanceof Error) {
|
|
3439
|
-
if (e instanceof TinaFetchError) {
|
|
3440
|
-
if (verbose) {
|
|
3441
|
-
console.log(e.toString());
|
|
3442
|
-
console.log(e);
|
|
3443
|
-
console.log(e.stack);
|
|
3444
|
-
}
|
|
3445
|
-
}
|
|
3446
|
-
} else {
|
|
3447
|
-
console.error(e);
|
|
3448
|
-
}
|
|
3449
|
-
throw e;
|
|
3450
|
-
};
|
|
3451
|
-
|
|
3452
|
-
// src/resolver/filter-utils.ts
|
|
3453
|
-
var resolveReferences = async (filter, fields, resolver) => {
|
|
3454
|
-
for (const fieldKey of Object.keys(filter)) {
|
|
3455
|
-
const fieldDefinition = fields.find(
|
|
3456
|
-
(f) => f.name === fieldKey
|
|
3457
|
-
);
|
|
3458
|
-
if (fieldDefinition) {
|
|
3459
|
-
if (fieldDefinition.type === "reference") {
|
|
3460
|
-
const { edges, values } = await resolver(filter, fieldDefinition);
|
|
3461
|
-
if (edges.length === 1) {
|
|
3462
|
-
filter[fieldKey] = {
|
|
3463
|
-
eq: values[0]
|
|
3464
|
-
};
|
|
3465
|
-
} else if (edges.length > 1) {
|
|
3466
|
-
filter[fieldKey] = {
|
|
3467
|
-
in: values
|
|
3468
|
-
};
|
|
3469
|
-
} else {
|
|
3470
|
-
filter[fieldKey] = {
|
|
3471
|
-
eq: "___null___"
|
|
3472
|
-
};
|
|
3473
|
-
}
|
|
3474
|
-
} else if (fieldDefinition.type === "object") {
|
|
3475
|
-
if (fieldDefinition.templates) {
|
|
3476
|
-
for (const templateName of Object.keys(filter[fieldKey])) {
|
|
3477
|
-
const template = fieldDefinition.templates.find(
|
|
3478
|
-
(template2) => !(typeof template2 === "string") && template2.name === templateName
|
|
3479
|
-
);
|
|
3480
|
-
if (template) {
|
|
3481
|
-
await resolveReferences(
|
|
3482
|
-
filter[fieldKey][templateName],
|
|
3483
|
-
template.fields,
|
|
3484
|
-
resolver
|
|
3485
|
-
);
|
|
3486
|
-
} else {
|
|
3487
|
-
throw new Error(`Template ${templateName} not found`);
|
|
3488
|
-
}
|
|
3489
|
-
}
|
|
3490
|
-
} else {
|
|
3491
|
-
await resolveReferences(
|
|
3492
|
-
filter[fieldKey],
|
|
3493
|
-
fieldDefinition.fields,
|
|
3494
|
-
resolver
|
|
3495
|
-
);
|
|
3496
|
-
}
|
|
3497
|
-
}
|
|
3498
|
-
} else {
|
|
3499
|
-
throw new Error(`Unable to find field ${fieldKey}`);
|
|
3500
|
-
}
|
|
3501
|
-
}
|
|
3502
|
-
};
|
|
3503
|
-
var collectConditionsForChildFields = (filterNode, fields, pathExpression, collectCondition) => {
|
|
3504
|
-
for (const childFieldName of Object.keys(filterNode)) {
|
|
3505
|
-
const childField = fields.find((field) => field.name === childFieldName);
|
|
3506
|
-
if (!childField) {
|
|
3507
|
-
throw new Error(`Unable to find type for field ${childFieldName}`);
|
|
3508
|
-
}
|
|
3509
|
-
collectConditionsForField(
|
|
3510
|
-
childFieldName,
|
|
3511
|
-
childField,
|
|
3512
|
-
filterNode[childFieldName],
|
|
3513
|
-
pathExpression,
|
|
3514
|
-
collectCondition
|
|
3515
|
-
);
|
|
3516
|
-
}
|
|
3517
|
-
};
|
|
3518
|
-
var collectConditionsForObjectField = (fieldName, field, filterNode, pathExpression, collectCondition) => {
|
|
3519
|
-
if (field.list && field.templates) {
|
|
3520
|
-
for (const [filterKey, childFilterNode] of Object.entries(filterNode)) {
|
|
3521
|
-
const template = field.templates.find(
|
|
3522
|
-
(template2) => !(typeof template2 === "string") && template2.name === filterKey
|
|
3523
|
-
);
|
|
3524
|
-
const jsonPath = `${fieldName}[?(@._template=="${filterKey}")]`;
|
|
3525
|
-
const filterPath = pathExpression ? `${pathExpression}.${jsonPath}` : jsonPath;
|
|
3526
|
-
collectConditionsForChildFields(
|
|
3527
|
-
childFilterNode,
|
|
3528
|
-
template.fields,
|
|
3529
|
-
filterPath,
|
|
3530
|
-
collectCondition
|
|
3531
|
-
);
|
|
3532
|
-
}
|
|
3533
|
-
} else {
|
|
3534
|
-
const jsonPath = `${fieldName}${field.list ? "[*]" : ""}`;
|
|
3535
|
-
const filterPath = pathExpression ? `${pathExpression}.${jsonPath}` : `${jsonPath}`;
|
|
3536
|
-
collectConditionsForChildFields(
|
|
3537
|
-
filterNode,
|
|
3538
|
-
field.fields,
|
|
3539
|
-
filterPath,
|
|
3540
|
-
collectCondition
|
|
3541
|
-
);
|
|
3542
|
-
}
|
|
3543
|
-
};
|
|
3544
|
-
var collectConditionsForField = (fieldName, field, filterNode, pathExpression, collectCondition) => {
|
|
3545
|
-
if (field.type === "object") {
|
|
3546
|
-
collectConditionsForObjectField(
|
|
3547
|
-
fieldName,
|
|
3548
|
-
field,
|
|
3549
|
-
filterNode,
|
|
3550
|
-
pathExpression,
|
|
3551
|
-
collectCondition
|
|
3552
|
-
);
|
|
3553
|
-
} else {
|
|
3554
|
-
collectCondition({
|
|
3555
|
-
filterPath: pathExpression ? `${pathExpression}.${fieldName}` : fieldName,
|
|
3556
|
-
filterExpression: {
|
|
3557
|
-
_type: field.type,
|
|
3558
|
-
_list: !!field.list,
|
|
3559
|
-
...filterNode
|
|
3560
|
-
}
|
|
3561
|
-
});
|
|
3562
|
-
}
|
|
3563
|
-
};
|
|
3564
|
-
|
|
3565
|
-
// src/resolver/media-utils.ts
|
|
3566
|
-
var resolveMediaCloudToRelative = (value, config = { useRelativeMedia: true }, schema) => {
|
|
3567
|
-
if (config && value) {
|
|
3568
|
-
if (config.useRelativeMedia === true) {
|
|
3569
|
-
return value;
|
|
3570
|
-
}
|
|
3571
|
-
if (hasTinaMediaConfig(schema) === true) {
|
|
3572
|
-
const assetsURL = `https://${config.assetsHost}/${config.clientId}`;
|
|
3573
|
-
if (typeof value === "string" && value.includes(assetsURL)) {
|
|
3574
|
-
const cleanMediaRoot = cleanUpSlashes(
|
|
3575
|
-
schema.config.media.tina.mediaRoot
|
|
3576
|
-
);
|
|
3577
|
-
const strippedURL = value.replace(assetsURL, "");
|
|
3578
|
-
return `${cleanMediaRoot}${strippedURL}`;
|
|
3579
|
-
}
|
|
3580
|
-
if (Array.isArray(value)) {
|
|
3581
|
-
return value.map((v) => {
|
|
3582
|
-
if (!v || typeof v !== "string") return v;
|
|
3583
|
-
const cleanMediaRoot = cleanUpSlashes(
|
|
3584
|
-
schema.config.media.tina.mediaRoot
|
|
3585
|
-
);
|
|
3586
|
-
const strippedURL = v.replace(assetsURL, "");
|
|
3587
|
-
return `${cleanMediaRoot}${strippedURL}`;
|
|
3588
|
-
});
|
|
3589
|
-
}
|
|
3590
|
-
return value;
|
|
3591
|
-
}
|
|
3592
|
-
return value;
|
|
3593
|
-
} else {
|
|
3594
|
-
return value;
|
|
3595
|
-
}
|
|
3596
|
-
};
|
|
3597
|
-
var resolveMediaRelativeToCloud = (value, config = { useRelativeMedia: true }, schema) => {
|
|
3598
|
-
if (config && value) {
|
|
3599
|
-
if (config.useRelativeMedia === true) {
|
|
3600
|
-
return value;
|
|
3601
|
-
}
|
|
3602
|
-
if (hasTinaMediaConfig(schema) === true) {
|
|
3603
|
-
const cleanMediaRoot = cleanUpSlashes(schema.config.media.tina.mediaRoot);
|
|
3604
|
-
if (typeof value === "string") {
|
|
3605
|
-
const strippedValue = value.replace(cleanMediaRoot, "");
|
|
3606
|
-
return `https://${config.assetsHost}/${config.clientId}${strippedValue}`;
|
|
3607
|
-
}
|
|
3608
|
-
if (Array.isArray(value)) {
|
|
3609
|
-
return value.map((v) => {
|
|
3610
|
-
if (!v || typeof v !== "string") return v;
|
|
3611
|
-
const strippedValue = v.replace(cleanMediaRoot, "");
|
|
3612
|
-
return `https://${config.assetsHost}/${config.clientId}${strippedValue}`;
|
|
3613
|
-
});
|
|
3614
|
-
}
|
|
3615
|
-
}
|
|
3616
|
-
return value;
|
|
3617
|
-
} else {
|
|
3618
|
-
return value;
|
|
3619
|
-
}
|
|
3620
|
-
};
|
|
3621
|
-
var cleanUpSlashes = (path7) => {
|
|
3622
|
-
if (path7) {
|
|
3623
|
-
return `/${path7.replace(/^\/+|\/+$/gm, "")}`;
|
|
3624
|
-
}
|
|
3625
|
-
return "";
|
|
3626
|
-
};
|
|
3627
|
-
var hasTinaMediaConfig = (schema) => {
|
|
3628
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
3629
|
-
if (!((_b = (_a = schema.config) == null ? void 0 : _a.media) == null ? void 0 : _b.tina)) return false;
|
|
3630
|
-
if (typeof ((_e = (_d = (_c = schema.config) == null ? void 0 : _c.media) == null ? void 0 : _d.tina) == null ? void 0 : _e.publicFolder) !== "string" && typeof ((_h = (_g = (_f = schema.config) == null ? void 0 : _f.media) == null ? void 0 : _g.tina) == null ? void 0 : _h.mediaRoot) !== "string")
|
|
3631
|
-
return false;
|
|
3632
|
-
return true;
|
|
3633
|
-
};
|
|
3634
|
-
|
|
3635
3382
|
// src/resolver/index.ts
|
|
3636
3383
|
var import_graphql3 = require("graphql");
|
|
3637
3384
|
|
|
@@ -3693,11 +3440,11 @@ var import_path2 = __toESM(require("path"));
|
|
|
3693
3440
|
|
|
3694
3441
|
// src/database/util.ts
|
|
3695
3442
|
var import_toml = __toESM(require("@iarna/toml"));
|
|
3696
|
-
var import_js_yaml = __toESM(require("js-yaml"));
|
|
3697
|
-
var import_gray_matter = __toESM(require("gray-matter"));
|
|
3698
3443
|
var import_schema_tools4 = require("@tinacms/schema-tools");
|
|
3699
|
-
var
|
|
3444
|
+
var import_gray_matter = __toESM(require("gray-matter"));
|
|
3445
|
+
var import_js_yaml = __toESM(require("js-yaml"));
|
|
3700
3446
|
var import_path = __toESM(require("path"));
|
|
3447
|
+
var import_micromatch = __toESM(require("micromatch"));
|
|
3701
3448
|
|
|
3702
3449
|
// src/database/alias-utils.ts
|
|
3703
3450
|
var replaceBlockAliases = (template, item) => {
|
|
@@ -3734,22 +3481,20 @@ var replaceNameOverrides = (template, obj) => {
|
|
|
3734
3481
|
}
|
|
3735
3482
|
};
|
|
3736
3483
|
function isBlockField(field) {
|
|
3737
|
-
|
|
3738
|
-
return field && field.type === "object" && ((_a = field.templates) == null ? void 0 : _a.length) > 0;
|
|
3484
|
+
return field && field.type === "object" && field.templates?.length > 0;
|
|
3739
3485
|
}
|
|
3740
3486
|
var _replaceNameOverrides = (fields, obj) => {
|
|
3741
3487
|
const output = {};
|
|
3742
3488
|
Object.keys(obj).forEach((key) => {
|
|
3743
3489
|
const field = fields.find(
|
|
3744
|
-
(fieldWithMatchingAlias) => (
|
|
3490
|
+
(fieldWithMatchingAlias) => (fieldWithMatchingAlias?.nameOverride || fieldWithMatchingAlias?.name) === key
|
|
3745
3491
|
);
|
|
3746
|
-
output[
|
|
3492
|
+
output[field?.name || key] = field?.type == "object" ? replaceNameOverrides(field, obj[key]) : obj[key];
|
|
3747
3493
|
});
|
|
3748
3494
|
return output;
|
|
3749
3495
|
};
|
|
3750
3496
|
var getTemplateForData = (field, data) => {
|
|
3751
|
-
|
|
3752
|
-
if ((_a = field.templates) == null ? void 0 : _a.length) {
|
|
3497
|
+
if (field.templates?.length) {
|
|
3753
3498
|
const templateKey = "_template";
|
|
3754
3499
|
if (data[templateKey]) {
|
|
3755
3500
|
const result = field.templates.find(
|
|
@@ -3807,8 +3552,8 @@ var _applyNameOverrides = (fields, obj) => {
|
|
|
3807
3552
|
const output = {};
|
|
3808
3553
|
Object.keys(obj).forEach((key) => {
|
|
3809
3554
|
const field = fields.find((field2) => field2.name === key);
|
|
3810
|
-
const outputKey =
|
|
3811
|
-
output[outputKey] =
|
|
3555
|
+
const outputKey = field?.nameOverride || key;
|
|
3556
|
+
output[outputKey] = field?.type === "object" ? applyNameOverrides(field, obj[key]) : obj[key];
|
|
3812
3557
|
});
|
|
3813
3558
|
return output;
|
|
3814
3559
|
};
|
|
@@ -3821,7 +3566,6 @@ var matterEngines = {
|
|
|
3821
3566
|
}
|
|
3822
3567
|
};
|
|
3823
3568
|
var stringifyFile = (content, format, keepTemplateKey, markdownParseConfig) => {
|
|
3824
|
-
var _a, _b;
|
|
3825
3569
|
const {
|
|
3826
3570
|
_relativePath,
|
|
3827
3571
|
_keepTemplateKey,
|
|
@@ -3845,9 +3589,9 @@ var stringifyFile = (content, format, keepTemplateKey, markdownParseConfig) => {
|
|
|
3845
3589
|
${$_body}`,
|
|
3846
3590
|
strippedContent,
|
|
3847
3591
|
{
|
|
3848
|
-
language:
|
|
3592
|
+
language: markdownParseConfig?.frontmatterFormat ?? "yaml",
|
|
3849
3593
|
engines: matterEngines,
|
|
3850
|
-
delimiters:
|
|
3594
|
+
delimiters: markdownParseConfig?.frontmatterDelimiters ?? "---"
|
|
3851
3595
|
}
|
|
3852
3596
|
);
|
|
3853
3597
|
return ok;
|
|
@@ -3863,15 +3607,14 @@ ${$_body}`,
|
|
|
3863
3607
|
}
|
|
3864
3608
|
};
|
|
3865
3609
|
var parseFile = (content, format, yupSchema, markdownParseConfig) => {
|
|
3866
|
-
var _a, _b;
|
|
3867
3610
|
try {
|
|
3868
3611
|
switch (format) {
|
|
3869
3612
|
case ".markdown":
|
|
3870
3613
|
case ".mdx":
|
|
3871
3614
|
case ".md":
|
|
3872
3615
|
const contentJSON = (0, import_gray_matter.default)(content || "", {
|
|
3873
|
-
language:
|
|
3874
|
-
delimiters:
|
|
3616
|
+
language: markdownParseConfig?.frontmatterFormat ?? "yaml",
|
|
3617
|
+
delimiters: markdownParseConfig?.frontmatterDelimiters ?? "---",
|
|
3875
3618
|
engines: matterEngines
|
|
3876
3619
|
});
|
|
3877
3620
|
const markdownData = {
|
|
@@ -3970,7 +3713,7 @@ var transformDocument = (filepath, contentObject, tinaSchema) => {
|
|
|
3970
3713
|
),
|
|
3971
3714
|
template: void 0
|
|
3972
3715
|
} : tinaSchema.getCollectionAndTemplateByFullPath(filepath, templateName);
|
|
3973
|
-
const field = template
|
|
3716
|
+
const field = template?.fields.find((field2) => {
|
|
3974
3717
|
if (field2.type === "string" || field2.type === "rich-text") {
|
|
3975
3718
|
if (field2.isBody) {
|
|
3976
3719
|
return true;
|
|
@@ -3990,7 +3733,7 @@ var transformDocument = (filepath, contentObject, tinaSchema) => {
|
|
|
3990
3733
|
...data,
|
|
3991
3734
|
_collection: collection.name,
|
|
3992
3735
|
_keepTemplateKey: !!collection.templates,
|
|
3993
|
-
_template:
|
|
3736
|
+
_template: template?.namespace ? lastItem(template?.namespace) : void 0,
|
|
3994
3737
|
_relativePath: filepath.replace(collection.path, "").replace(/^\/|\/$/g, ""),
|
|
3995
3738
|
_id: filepath
|
|
3996
3739
|
};
|
|
@@ -3999,10 +3742,10 @@ function hasOwnProperty(obj, prop) {
|
|
|
3999
3742
|
return obj.hasOwnProperty(prop);
|
|
4000
3743
|
}
|
|
4001
3744
|
var getTemplateForFile = (templateInfo, data) => {
|
|
4002
|
-
if (
|
|
3745
|
+
if (templateInfo?.type === "object") {
|
|
4003
3746
|
return templateInfo.template;
|
|
4004
3747
|
}
|
|
4005
|
-
if (
|
|
3748
|
+
if (templateInfo?.type === "union") {
|
|
4006
3749
|
if (hasOwnProperty(data, "_template")) {
|
|
4007
3750
|
const template = templateInfo.templates.find(
|
|
4008
3751
|
(t) => lastItem(t.namespace) === data._template
|
|
@@ -4026,8 +3769,8 @@ var loadAndParseWithAliases = async (bridge, filepath, collection, templateInfo)
|
|
|
4026
3769
|
import_path.default.extname(filepath),
|
|
4027
3770
|
(yup3) => yup3.object({}),
|
|
4028
3771
|
{
|
|
4029
|
-
frontmatterDelimiters: collection
|
|
4030
|
-
frontmatterFormat: collection
|
|
3772
|
+
frontmatterDelimiters: collection?.frontmatterDelimiters,
|
|
3773
|
+
frontmatterFormat: collection?.frontmatterFormat
|
|
4031
3774
|
}
|
|
4032
3775
|
);
|
|
4033
3776
|
const template = getTemplateForFile(templateInfo, data);
|
|
@@ -4689,12 +4432,248 @@ var stringEscaper = makeStringEscaper(
|
|
|
4689
4432
|
encodeURIComponent(INDEX_KEY_FIELD_SEPARATOR)
|
|
4690
4433
|
);
|
|
4691
4434
|
|
|
4435
|
+
// src/resolver/error.ts
|
|
4436
|
+
var TinaGraphQLError = class extends Error {
|
|
4437
|
+
constructor(message, extensions) {
|
|
4438
|
+
super(message);
|
|
4439
|
+
if (!this.name) {
|
|
4440
|
+
Object.defineProperty(this, "name", { value: "TinaGraphQLError" });
|
|
4441
|
+
}
|
|
4442
|
+
this.extensions = { ...extensions };
|
|
4443
|
+
}
|
|
4444
|
+
};
|
|
4445
|
+
var TinaFetchError = class extends Error {
|
|
4446
|
+
constructor(message, args) {
|
|
4447
|
+
super(message);
|
|
4448
|
+
this.name = "TinaFetchError";
|
|
4449
|
+
this.collection = args.collection;
|
|
4450
|
+
this.stack = args.stack;
|
|
4451
|
+
this.file = args.file;
|
|
4452
|
+
this.originalError = args.originalError;
|
|
4453
|
+
}
|
|
4454
|
+
};
|
|
4455
|
+
var TinaQueryError = class extends TinaFetchError {
|
|
4456
|
+
constructor(args) {
|
|
4457
|
+
super(
|
|
4458
|
+
`Error querying file ${args.file} from collection ${args.collection}. ${auditMessage(args.includeAuditMessage)}`,
|
|
4459
|
+
args
|
|
4460
|
+
);
|
|
4461
|
+
}
|
|
4462
|
+
};
|
|
4463
|
+
var TinaParseDocumentError = class extends TinaFetchError {
|
|
4464
|
+
constructor(args) {
|
|
4465
|
+
super(
|
|
4466
|
+
`Error parsing file ${args.file} from collection ${args.collection}. ${auditMessage(args.includeAuditMessage)}`,
|
|
4467
|
+
args
|
|
4468
|
+
);
|
|
4469
|
+
}
|
|
4470
|
+
toString() {
|
|
4471
|
+
return super.toString() + "\n OriginalError: \n" + this.originalError.toString();
|
|
4472
|
+
}
|
|
4473
|
+
};
|
|
4474
|
+
var auditMessage = (includeAuditMessage = true) => includeAuditMessage ? `Please run "tinacms audit" or add the --verbose option for more info` : "";
|
|
4475
|
+
var handleFetchErrorError = (e, verbose) => {
|
|
4476
|
+
if (e instanceof Error) {
|
|
4477
|
+
if (e instanceof TinaFetchError) {
|
|
4478
|
+
if (verbose) {
|
|
4479
|
+
console.log(e.toString());
|
|
4480
|
+
console.log(e);
|
|
4481
|
+
console.log(e.stack);
|
|
4482
|
+
}
|
|
4483
|
+
}
|
|
4484
|
+
} else {
|
|
4485
|
+
console.error(e);
|
|
4486
|
+
}
|
|
4487
|
+
throw e;
|
|
4488
|
+
};
|
|
4489
|
+
|
|
4490
|
+
// src/resolver/filter-utils.ts
|
|
4491
|
+
var resolveReferences = async (filter, fields, resolver) => {
|
|
4492
|
+
for (const fieldKey of Object.keys(filter)) {
|
|
4493
|
+
const fieldDefinition = fields.find(
|
|
4494
|
+
(f) => f.name === fieldKey
|
|
4495
|
+
);
|
|
4496
|
+
if (fieldDefinition) {
|
|
4497
|
+
if (fieldDefinition.type === "reference") {
|
|
4498
|
+
const { edges, values } = await resolver(filter, fieldDefinition);
|
|
4499
|
+
if (edges.length === 1) {
|
|
4500
|
+
filter[fieldKey] = {
|
|
4501
|
+
eq: values[0]
|
|
4502
|
+
};
|
|
4503
|
+
} else if (edges.length > 1) {
|
|
4504
|
+
filter[fieldKey] = {
|
|
4505
|
+
in: values
|
|
4506
|
+
};
|
|
4507
|
+
} else {
|
|
4508
|
+
filter[fieldKey] = {
|
|
4509
|
+
eq: "___null___"
|
|
4510
|
+
};
|
|
4511
|
+
}
|
|
4512
|
+
} else if (fieldDefinition.type === "object") {
|
|
4513
|
+
if (fieldDefinition.templates) {
|
|
4514
|
+
for (const templateName of Object.keys(filter[fieldKey])) {
|
|
4515
|
+
const template = fieldDefinition.templates.find(
|
|
4516
|
+
(template2) => !(typeof template2 === "string") && template2.name === templateName
|
|
4517
|
+
);
|
|
4518
|
+
if (template) {
|
|
4519
|
+
await resolveReferences(
|
|
4520
|
+
filter[fieldKey][templateName],
|
|
4521
|
+
template.fields,
|
|
4522
|
+
resolver
|
|
4523
|
+
);
|
|
4524
|
+
} else {
|
|
4525
|
+
throw new Error(`Template ${templateName} not found`);
|
|
4526
|
+
}
|
|
4527
|
+
}
|
|
4528
|
+
} else {
|
|
4529
|
+
await resolveReferences(
|
|
4530
|
+
filter[fieldKey],
|
|
4531
|
+
fieldDefinition.fields,
|
|
4532
|
+
resolver
|
|
4533
|
+
);
|
|
4534
|
+
}
|
|
4535
|
+
}
|
|
4536
|
+
} else {
|
|
4537
|
+
throw new Error(`Unable to find field ${fieldKey}`);
|
|
4538
|
+
}
|
|
4539
|
+
}
|
|
4540
|
+
};
|
|
4541
|
+
var collectConditionsForChildFields = (filterNode, fields, pathExpression, collectCondition) => {
|
|
4542
|
+
for (const childFieldName of Object.keys(filterNode)) {
|
|
4543
|
+
const childField = fields.find((field) => field.name === childFieldName);
|
|
4544
|
+
if (!childField) {
|
|
4545
|
+
throw new Error(`Unable to find type for field ${childFieldName}`);
|
|
4546
|
+
}
|
|
4547
|
+
collectConditionsForField(
|
|
4548
|
+
childFieldName,
|
|
4549
|
+
childField,
|
|
4550
|
+
filterNode[childFieldName],
|
|
4551
|
+
pathExpression,
|
|
4552
|
+
collectCondition
|
|
4553
|
+
);
|
|
4554
|
+
}
|
|
4555
|
+
};
|
|
4556
|
+
var collectConditionsForObjectField = (fieldName, field, filterNode, pathExpression, collectCondition) => {
|
|
4557
|
+
if (field.list && field.templates) {
|
|
4558
|
+
for (const [filterKey, childFilterNode] of Object.entries(filterNode)) {
|
|
4559
|
+
const template = field.templates.find(
|
|
4560
|
+
(template2) => !(typeof template2 === "string") && template2.name === filterKey
|
|
4561
|
+
);
|
|
4562
|
+
const jsonPath = `${fieldName}[?(@._template=="${filterKey}")]`;
|
|
4563
|
+
const filterPath = pathExpression ? `${pathExpression}.${jsonPath}` : jsonPath;
|
|
4564
|
+
collectConditionsForChildFields(
|
|
4565
|
+
childFilterNode,
|
|
4566
|
+
template.fields,
|
|
4567
|
+
filterPath,
|
|
4568
|
+
collectCondition
|
|
4569
|
+
);
|
|
4570
|
+
}
|
|
4571
|
+
} else {
|
|
4572
|
+
const jsonPath = `${fieldName}${field.list ? "[*]" : ""}`;
|
|
4573
|
+
const filterPath = pathExpression ? `${pathExpression}.${jsonPath}` : `${jsonPath}`;
|
|
4574
|
+
collectConditionsForChildFields(
|
|
4575
|
+
filterNode,
|
|
4576
|
+
field.fields,
|
|
4577
|
+
filterPath,
|
|
4578
|
+
collectCondition
|
|
4579
|
+
);
|
|
4580
|
+
}
|
|
4581
|
+
};
|
|
4582
|
+
var collectConditionsForField = (fieldName, field, filterNode, pathExpression, collectCondition) => {
|
|
4583
|
+
if (field.type === "object") {
|
|
4584
|
+
collectConditionsForObjectField(
|
|
4585
|
+
fieldName,
|
|
4586
|
+
field,
|
|
4587
|
+
filterNode,
|
|
4588
|
+
pathExpression,
|
|
4589
|
+
collectCondition
|
|
4590
|
+
);
|
|
4591
|
+
} else {
|
|
4592
|
+
collectCondition({
|
|
4593
|
+
filterPath: pathExpression ? `${pathExpression}.${fieldName}` : fieldName,
|
|
4594
|
+
filterExpression: {
|
|
4595
|
+
_type: field.type,
|
|
4596
|
+
_list: !!field.list,
|
|
4597
|
+
...filterNode
|
|
4598
|
+
}
|
|
4599
|
+
});
|
|
4600
|
+
}
|
|
4601
|
+
};
|
|
4602
|
+
|
|
4603
|
+
// src/resolver/media-utils.ts
|
|
4604
|
+
var resolveMediaCloudToRelative = (value, config = { useRelativeMedia: true }, schema) => {
|
|
4605
|
+
if (config && value) {
|
|
4606
|
+
if (config.useRelativeMedia === true) {
|
|
4607
|
+
return value;
|
|
4608
|
+
}
|
|
4609
|
+
if (hasTinaMediaConfig(schema) === true) {
|
|
4610
|
+
const assetsURL = `https://${config.assetsHost}/${config.clientId}`;
|
|
4611
|
+
if (typeof value === "string" && value.includes(assetsURL)) {
|
|
4612
|
+
const cleanMediaRoot = cleanUpSlashes(
|
|
4613
|
+
schema.config.media.tina.mediaRoot
|
|
4614
|
+
);
|
|
4615
|
+
const strippedURL = value.replace(assetsURL, "");
|
|
4616
|
+
return `${cleanMediaRoot}${strippedURL}`;
|
|
4617
|
+
}
|
|
4618
|
+
if (Array.isArray(value)) {
|
|
4619
|
+
return value.map((v) => {
|
|
4620
|
+
if (!v || typeof v !== "string") return v;
|
|
4621
|
+
const cleanMediaRoot = cleanUpSlashes(
|
|
4622
|
+
schema.config.media.tina.mediaRoot
|
|
4623
|
+
);
|
|
4624
|
+
const strippedURL = v.replace(assetsURL, "");
|
|
4625
|
+
return `${cleanMediaRoot}${strippedURL}`;
|
|
4626
|
+
});
|
|
4627
|
+
}
|
|
4628
|
+
return value;
|
|
4629
|
+
}
|
|
4630
|
+
return value;
|
|
4631
|
+
} else {
|
|
4632
|
+
return value;
|
|
4633
|
+
}
|
|
4634
|
+
};
|
|
4635
|
+
var resolveMediaRelativeToCloud = (value, config = { useRelativeMedia: true }, schema) => {
|
|
4636
|
+
if (config && value) {
|
|
4637
|
+
if (config.useRelativeMedia === true) {
|
|
4638
|
+
return value;
|
|
4639
|
+
}
|
|
4640
|
+
if (hasTinaMediaConfig(schema) === true) {
|
|
4641
|
+
const cleanMediaRoot = cleanUpSlashes(schema.config.media.tina.mediaRoot);
|
|
4642
|
+
if (typeof value === "string") {
|
|
4643
|
+
const strippedValue = value.replace(cleanMediaRoot, "");
|
|
4644
|
+
return `https://${config.assetsHost}/${config.clientId}${strippedValue}`;
|
|
4645
|
+
}
|
|
4646
|
+
if (Array.isArray(value)) {
|
|
4647
|
+
return value.map((v) => {
|
|
4648
|
+
if (!v || typeof v !== "string") return v;
|
|
4649
|
+
const strippedValue = v.replace(cleanMediaRoot, "");
|
|
4650
|
+
return `https://${config.assetsHost}/${config.clientId}${strippedValue}`;
|
|
4651
|
+
});
|
|
4652
|
+
}
|
|
4653
|
+
}
|
|
4654
|
+
return value;
|
|
4655
|
+
} else {
|
|
4656
|
+
return value;
|
|
4657
|
+
}
|
|
4658
|
+
};
|
|
4659
|
+
var cleanUpSlashes = (path7) => {
|
|
4660
|
+
if (path7) {
|
|
4661
|
+
return `/${path7.replace(/^\/+|\/+$/gm, "")}`;
|
|
4662
|
+
}
|
|
4663
|
+
return "";
|
|
4664
|
+
};
|
|
4665
|
+
var hasTinaMediaConfig = (schema) => {
|
|
4666
|
+
if (!schema.config?.media?.tina) return false;
|
|
4667
|
+
if (typeof schema.config?.media?.tina?.publicFolder !== "string" && typeof schema.config?.media?.tina?.mediaRoot !== "string")
|
|
4668
|
+
return false;
|
|
4669
|
+
return true;
|
|
4670
|
+
};
|
|
4671
|
+
|
|
4692
4672
|
// src/resolver/index.ts
|
|
4693
4673
|
var createResolver = (args) => {
|
|
4694
4674
|
return new Resolver(args);
|
|
4695
4675
|
};
|
|
4696
4676
|
var resolveFieldData = async ({ namespace, ...field }, rawData, accumulator, tinaSchema, config, isAudit) => {
|
|
4697
|
-
var _a, _b;
|
|
4698
4677
|
if (!rawData) {
|
|
4699
4678
|
return void 0;
|
|
4700
4679
|
}
|
|
@@ -4722,7 +4701,7 @@ var resolveFieldData = async ({ namespace, ...field }, rawData, accumulator, tin
|
|
|
4722
4701
|
accumulator[field.name] = {
|
|
4723
4702
|
value: void 0,
|
|
4724
4703
|
// never resolve the password hash
|
|
4725
|
-
passwordChangeRequired:
|
|
4704
|
+
passwordChangeRequired: value["passwordChangeRequired"] ?? false
|
|
4726
4705
|
};
|
|
4727
4706
|
break;
|
|
4728
4707
|
case "image":
|
|
@@ -4738,11 +4717,11 @@ var resolveFieldData = async ({ namespace, ...field }, rawData, accumulator, tin
|
|
|
4738
4717
|
field,
|
|
4739
4718
|
(value2) => resolveMediaRelativeToCloud(value2, config, tinaSchema.schema)
|
|
4740
4719
|
);
|
|
4741
|
-
if (
|
|
4720
|
+
if (tree?.children[0]?.type === "invalid_markdown") {
|
|
4742
4721
|
if (isAudit) {
|
|
4743
|
-
const invalidNode = tree
|
|
4722
|
+
const invalidNode = tree?.children[0];
|
|
4744
4723
|
throw new import_graphql3.GraphQLError(
|
|
4745
|
-
`${invalidNode
|
|
4724
|
+
`${invalidNode?.message}${invalidNode.position ? ` at line ${invalidNode.position.start.line}, column ${invalidNode.position.start.column}` : ""}`
|
|
4746
4725
|
);
|
|
4747
4726
|
}
|
|
4748
4727
|
}
|
|
@@ -4855,11 +4834,11 @@ var transformDocumentIntoPayload = async (fullPath, rawData, tinaSchema, config,
|
|
|
4855
4834
|
});
|
|
4856
4835
|
}
|
|
4857
4836
|
const titleField = template.fields.find((x) => {
|
|
4858
|
-
if (x.type === "string" &&
|
|
4837
|
+
if (x.type === "string" && x?.isTitle) {
|
|
4859
4838
|
return true;
|
|
4860
4839
|
}
|
|
4861
4840
|
});
|
|
4862
|
-
const titleFieldName = titleField
|
|
4841
|
+
const titleFieldName = titleField?.name;
|
|
4863
4842
|
const title = data[titleFieldName || " "] || null;
|
|
4864
4843
|
return {
|
|
4865
4844
|
__typename: collection.fields ? NAMER.documentTypeName(collection.namespace) : NAMER.documentTypeName(template.namespace),
|
|
@@ -4969,7 +4948,7 @@ var Resolver = class {
|
|
|
4969
4948
|
);
|
|
4970
4949
|
}
|
|
4971
4950
|
const rawData = await this.getRaw(fullPath);
|
|
4972
|
-
const hasReferences =
|
|
4951
|
+
const hasReferences = opts?.checkReferences ? await this.hasReferences(fullPath, opts.collection) : void 0;
|
|
4973
4952
|
return transformDocumentIntoPayload(
|
|
4974
4953
|
fullPath,
|
|
4975
4954
|
rawData,
|
|
@@ -5009,9 +4988,9 @@ var Resolver = class {
|
|
|
5009
4988
|
return this.buildFieldMutations(
|
|
5010
4989
|
item,
|
|
5011
4990
|
objectTemplate,
|
|
5012
|
-
idField && existingData &&
|
|
4991
|
+
idField && existingData && existingData?.find(
|
|
5013
4992
|
(d) => d[idField.name] === item[idField.name]
|
|
5014
|
-
)
|
|
4993
|
+
)
|
|
5015
4994
|
);
|
|
5016
4995
|
}
|
|
5017
4996
|
)
|
|
@@ -5137,7 +5116,7 @@ var Resolver = class {
|
|
|
5137
5116
|
isCollectionSpecific
|
|
5138
5117
|
}) => {
|
|
5139
5118
|
const doc = await this.getDocument(realPath);
|
|
5140
|
-
const oldDoc = this.resolveLegacyValues(
|
|
5119
|
+
const oldDoc = this.resolveLegacyValues(doc?._rawData || {}, collection);
|
|
5141
5120
|
if (isAddPendingDocument === true) {
|
|
5142
5121
|
const templateInfo = this.tinaSchema.getTemplatesForCollectable(collection);
|
|
5143
5122
|
const params2 = this.buildParams(args);
|
|
@@ -5147,7 +5126,7 @@ var Resolver = class {
|
|
|
5147
5126
|
const values = await this.buildFieldMutations(
|
|
5148
5127
|
params2,
|
|
5149
5128
|
templateInfo.template,
|
|
5150
|
-
doc
|
|
5129
|
+
doc?._rawData
|
|
5151
5130
|
);
|
|
5152
5131
|
await this.database.put(
|
|
5153
5132
|
realPath,
|
|
@@ -5171,7 +5150,7 @@ var Resolver = class {
|
|
|
5171
5150
|
// @ts-ignore FIXME: failing on unknown, which we don't need to know because it's recursive
|
|
5172
5151
|
templateParams,
|
|
5173
5152
|
template,
|
|
5174
|
-
doc
|
|
5153
|
+
doc?._rawData
|
|
5175
5154
|
),
|
|
5176
5155
|
_template: lastItem(template.namespace)
|
|
5177
5156
|
};
|
|
@@ -5185,7 +5164,7 @@ var Resolver = class {
|
|
|
5185
5164
|
//@ts-ignore
|
|
5186
5165
|
isCollectionSpecific ? args.params : args.params[collection.name],
|
|
5187
5166
|
collection,
|
|
5188
|
-
doc
|
|
5167
|
+
doc?._rawData
|
|
5189
5168
|
);
|
|
5190
5169
|
await this.database.put(
|
|
5191
5170
|
realPath,
|
|
@@ -5201,7 +5180,6 @@ var Resolver = class {
|
|
|
5201
5180
|
this.resolveLegacyValues = (oldDoc, collection) => {
|
|
5202
5181
|
const legacyValues = {};
|
|
5203
5182
|
Object.entries(oldDoc).forEach(([key, value]) => {
|
|
5204
|
-
var _a;
|
|
5205
5183
|
const reservedKeys = [
|
|
5206
5184
|
"$_body",
|
|
5207
5185
|
"_collection",
|
|
@@ -5214,7 +5192,7 @@ var Resolver = class {
|
|
|
5214
5192
|
return;
|
|
5215
5193
|
}
|
|
5216
5194
|
if (oldDoc._template && collection.templates) {
|
|
5217
|
-
const template =
|
|
5195
|
+
const template = collection.templates?.find(
|
|
5218
5196
|
({ name }) => name === oldDoc._template
|
|
5219
5197
|
);
|
|
5220
5198
|
if (template) {
|
|
@@ -5261,7 +5239,7 @@ var Resolver = class {
|
|
|
5261
5239
|
(yup3) => yup3.object({ relativePath: yup3.string().required() })
|
|
5262
5240
|
);
|
|
5263
5241
|
const collection = await this.tinaSchema.getCollection(collectionLookup);
|
|
5264
|
-
let realPath = import_path3.default.join(collection
|
|
5242
|
+
let realPath = import_path3.default.join(collection?.path, args.relativePath);
|
|
5265
5243
|
if (isFolderCreation) {
|
|
5266
5244
|
realPath = `${realPath}/.gitkeep.${collection.format || "md"}`;
|
|
5267
5245
|
}
|
|
@@ -5345,12 +5323,12 @@ var Resolver = class {
|
|
|
5345
5323
|
(yup3) => yup3.object({ params: yup3.object().required() })
|
|
5346
5324
|
);
|
|
5347
5325
|
assertShape(
|
|
5348
|
-
args
|
|
5326
|
+
args?.params,
|
|
5349
5327
|
(yup3) => yup3.object({ relativePath: yup3.string().required() })
|
|
5350
5328
|
);
|
|
5351
5329
|
const doc = await this.getDocument(realPath);
|
|
5352
5330
|
const newRealPath = import_path3.default.join(
|
|
5353
|
-
collection
|
|
5331
|
+
collection?.path,
|
|
5354
5332
|
args.params.relativePath
|
|
5355
5333
|
);
|
|
5356
5334
|
if (newRealPath === realPath) {
|
|
@@ -5580,7 +5558,7 @@ var Resolver = class {
|
|
|
5580
5558
|
if (!references[c.name][refId]) {
|
|
5581
5559
|
references[c.name][refId] = [];
|
|
5582
5560
|
}
|
|
5583
|
-
const referencePath = rawItem
|
|
5561
|
+
const referencePath = rawItem?.[REFS_PATH_FIELD];
|
|
5584
5562
|
if (referencePath) {
|
|
5585
5563
|
references[c.name][refId].push(referencePath);
|
|
5586
5564
|
}
|
|
@@ -5590,7 +5568,6 @@ var Resolver = class {
|
|
|
5590
5568
|
return references;
|
|
5591
5569
|
};
|
|
5592
5570
|
this.buildFieldMutations = async (fieldParams, template, existingData) => {
|
|
5593
|
-
var _a;
|
|
5594
5571
|
const accum = {};
|
|
5595
5572
|
for (const passwordField of template.fields.filter(
|
|
5596
5573
|
(f) => f.type === "password"
|
|
@@ -5633,7 +5610,7 @@ var Resolver = class {
|
|
|
5633
5610
|
accum[fieldName] = await this.buildObjectMutations(
|
|
5634
5611
|
fieldValue,
|
|
5635
5612
|
field,
|
|
5636
|
-
existingData
|
|
5613
|
+
existingData?.[fieldName]
|
|
5637
5614
|
);
|
|
5638
5615
|
break;
|
|
5639
5616
|
case "password":
|
|
@@ -5652,7 +5629,7 @@ var Resolver = class {
|
|
|
5652
5629
|
} else {
|
|
5653
5630
|
accum[fieldName] = {
|
|
5654
5631
|
...fieldValue,
|
|
5655
|
-
value:
|
|
5632
|
+
value: existingData?.[fieldName]?.["value"]
|
|
5656
5633
|
};
|
|
5657
5634
|
}
|
|
5658
5635
|
break;
|
|
@@ -5787,9 +5764,8 @@ var resolve = async ({
|
|
|
5787
5764
|
isAudit,
|
|
5788
5765
|
ctxUser
|
|
5789
5766
|
}) => {
|
|
5790
|
-
var _a;
|
|
5791
5767
|
try {
|
|
5792
|
-
const verboseValue = verbose
|
|
5768
|
+
const verboseValue = verbose ?? true;
|
|
5793
5769
|
const graphQLSchemaAst = await database.getGraphQLSchema();
|
|
5794
5770
|
if (!graphQLSchemaAst) {
|
|
5795
5771
|
throw new import_graphql5.GraphQLError("GraphQL schema not found");
|
|
@@ -5801,7 +5777,7 @@ var resolve = async ({
|
|
|
5801
5777
|
// @ts-ignore
|
|
5802
5778
|
schema: tinaConfig,
|
|
5803
5779
|
// @ts-ignore
|
|
5804
|
-
flags:
|
|
5780
|
+
flags: tinaConfig?.meta?.flags
|
|
5805
5781
|
});
|
|
5806
5782
|
const resolver = createResolver({
|
|
5807
5783
|
config,
|
|
@@ -5826,7 +5802,6 @@ var resolve = async ({
|
|
|
5826
5802
|
throw new Error(`Unable to find lookup key for ${namedType}`);
|
|
5827
5803
|
},
|
|
5828
5804
|
fieldResolver: async (source = {}, _args = {}, _context, info) => {
|
|
5829
|
-
var _a2, _b, _c, _d;
|
|
5830
5805
|
try {
|
|
5831
5806
|
const args = JSON.parse(JSON.stringify(_args));
|
|
5832
5807
|
const returnType = (0, import_graphql5.getNamedType)(info.returnType).toString();
|
|
@@ -5843,8 +5818,7 @@ var resolve = async ({
|
|
|
5843
5818
|
);
|
|
5844
5819
|
const hasDocuments2 = collectionNode2.selectionSet.selections.find(
|
|
5845
5820
|
(x) => {
|
|
5846
|
-
|
|
5847
|
-
return ((_a3 = x == null ? void 0 : x.name) == null ? void 0 : _a3.value) === "documents";
|
|
5821
|
+
return x?.name?.value === "documents";
|
|
5848
5822
|
}
|
|
5849
5823
|
);
|
|
5850
5824
|
return tinaSchema.getCollections().map((collection) => {
|
|
@@ -5860,8 +5834,7 @@ var resolve = async ({
|
|
|
5860
5834
|
);
|
|
5861
5835
|
const hasDocuments = collectionNode.selectionSet.selections.find(
|
|
5862
5836
|
(x) => {
|
|
5863
|
-
|
|
5864
|
-
return ((_a3 = x == null ? void 0 : x.name) == null ? void 0 : _a3.value) === "documents";
|
|
5837
|
+
return x?.name?.value === "documents";
|
|
5865
5838
|
}
|
|
5866
5839
|
);
|
|
5867
5840
|
return resolver.resolveCollection(
|
|
@@ -5880,7 +5853,7 @@ var resolve = async ({
|
|
|
5880
5853
|
}
|
|
5881
5854
|
}
|
|
5882
5855
|
if (info.fieldName === "authenticate" || info.fieldName === "authorize") {
|
|
5883
|
-
const sub = args.sub ||
|
|
5856
|
+
const sub = args.sub || ctxUser?.sub;
|
|
5884
5857
|
const collection = tinaSchema.getCollections().find((c) => c.isAuthCollection);
|
|
5885
5858
|
if (!collection) {
|
|
5886
5859
|
throw new Error("Auth collection not found");
|
|
@@ -5928,7 +5901,7 @@ var resolve = async ({
|
|
|
5928
5901
|
return user;
|
|
5929
5902
|
}
|
|
5930
5903
|
if (info.fieldName === "updatePassword") {
|
|
5931
|
-
if (!
|
|
5904
|
+
if (!ctxUser?.sub) {
|
|
5932
5905
|
throw new Error("Not authorized");
|
|
5933
5906
|
}
|
|
5934
5907
|
if (!args.password) {
|
|
@@ -6011,7 +5984,7 @@ var resolve = async ({
|
|
|
6011
5984
|
if (typeof value === "string" && value !== "") {
|
|
6012
5985
|
return resolver.getDocument(value);
|
|
6013
5986
|
}
|
|
6014
|
-
if (
|
|
5987
|
+
if (args?.collection && info.fieldName === "addPendingDocument") {
|
|
6015
5988
|
return resolver.resolveDocument({
|
|
6016
5989
|
args: { ...args, params: {} },
|
|
6017
5990
|
collection: args.collection,
|
|
@@ -6035,7 +6008,7 @@ var resolve = async ({
|
|
|
6035
6008
|
// Right now this is the only case for deletion
|
|
6036
6009
|
isDeletion: info.fieldName === "deleteDocument",
|
|
6037
6010
|
isFolderCreation: info.fieldName === "createFolder",
|
|
6038
|
-
isUpdateName: Boolean(
|
|
6011
|
+
isUpdateName: Boolean(args?.params?.relativePath),
|
|
6039
6012
|
isAddPendingDocument: false,
|
|
6040
6013
|
isCollectionSpecific: false
|
|
6041
6014
|
});
|
|
@@ -6054,16 +6027,16 @@ var resolve = async ({
|
|
|
6054
6027
|
})
|
|
6055
6028
|
};
|
|
6056
6029
|
}
|
|
6057
|
-
if (info.fieldName === "documents" &&
|
|
6030
|
+
if (info.fieldName === "documents" && value?.collection && value?.hasDocuments) {
|
|
6058
6031
|
let filter = args.filter;
|
|
6059
6032
|
if (
|
|
6060
6033
|
// 1. Make sure that the filter exists
|
|
6061
|
-
typeof
|
|
6034
|
+
typeof args?.filter !== "undefined" && args?.filter !== null && // 2. Make sure that the collection name exists
|
|
6062
6035
|
// @ts-ignore
|
|
6063
|
-
typeof
|
|
6036
|
+
typeof value?.collection?.name === "string" && // 3. Make sure that the collection name is in the filter and is not undefined
|
|
6064
6037
|
// @ts-ignore
|
|
6065
|
-
Object.keys(args.filter).includes(
|
|
6066
|
-
typeof args.filter[
|
|
6038
|
+
Object.keys(args.filter).includes(value?.collection?.name) && // @ts-ignore
|
|
6039
|
+
typeof args.filter[value?.collection?.name] !== "undefined"
|
|
6067
6040
|
) {
|
|
6068
6041
|
filter = args.filter[value.collection.name];
|
|
6069
6042
|
}
|
|
@@ -6200,15 +6173,15 @@ var TinaLevelClient = class extends import_many_level.ManyLevelGuest {
|
|
|
6200
6173
|
};
|
|
6201
6174
|
|
|
6202
6175
|
// src/database/index.ts
|
|
6203
|
-
var import_node_path = __toESM(require("path"));
|
|
6176
|
+
var import_node_path = __toESM(require("node:path"));
|
|
6204
6177
|
var import_graphql6 = require("graphql");
|
|
6205
6178
|
var import_micromatch2 = __toESM(require("micromatch"));
|
|
6206
6179
|
var import_js_sha12 = __toESM(require("js-sha1"));
|
|
6207
6180
|
var import_lodash5 = __toESM(require("lodash.set"));
|
|
6208
6181
|
var createLocalDatabase = (config) => {
|
|
6209
|
-
const level = new TinaLevelClient(config
|
|
6182
|
+
const level = new TinaLevelClient(config?.port);
|
|
6210
6183
|
level.openConnection();
|
|
6211
|
-
const fsBridge = new FilesystemBridge(
|
|
6184
|
+
const fsBridge = new FilesystemBridge(config?.rootPath || process.cwd());
|
|
6212
6185
|
return new Database({
|
|
6213
6186
|
bridge: fsBridge,
|
|
6214
6187
|
...config || {},
|
|
@@ -6281,7 +6254,7 @@ var Database = class {
|
|
|
6281
6254
|
);
|
|
6282
6255
|
}
|
|
6283
6256
|
const metadata = await metadataLevel.get(`metadata_${key}`);
|
|
6284
|
-
return metadata
|
|
6257
|
+
return metadata?.value;
|
|
6285
6258
|
};
|
|
6286
6259
|
this.setMetadata = async (key, value) => {
|
|
6287
6260
|
await this.initLevel();
|
|
@@ -6303,7 +6276,7 @@ var Database = class {
|
|
|
6303
6276
|
let level = this.contentLevel;
|
|
6304
6277
|
if (this.appLevel) {
|
|
6305
6278
|
collection = await this.collectionForPath(filepath);
|
|
6306
|
-
if (collection
|
|
6279
|
+
if (collection?.isDetached) {
|
|
6307
6280
|
level = this.appLevel.sublevel(collection.name, SUBLEVEL_OPTIONS);
|
|
6308
6281
|
}
|
|
6309
6282
|
}
|
|
@@ -6322,7 +6295,6 @@ var Database = class {
|
|
|
6322
6295
|
}
|
|
6323
6296
|
};
|
|
6324
6297
|
this.addPendingDocument = async (filepath, data) => {
|
|
6325
|
-
var _a;
|
|
6326
6298
|
await this.initLevel();
|
|
6327
6299
|
const dataFields = await this.formatBodyOnPayload(filepath, data);
|
|
6328
6300
|
const collection = await this.collectionForPath(filepath);
|
|
@@ -6335,10 +6307,10 @@ var Database = class {
|
|
|
6335
6307
|
collection
|
|
6336
6308
|
);
|
|
6337
6309
|
const indexDefinitions = await this.getIndexDefinitions(this.contentLevel);
|
|
6338
|
-
const collectionIndexDefinitions = indexDefinitions
|
|
6339
|
-
const collectionReferences = (
|
|
6310
|
+
const collectionIndexDefinitions = indexDefinitions?.[collection.name];
|
|
6311
|
+
const collectionReferences = (await this.getCollectionReferences())?.[collection.name];
|
|
6340
6312
|
const normalizedPath = (0, import_schema_tools4.normalizePath)(filepath);
|
|
6341
|
-
if (!
|
|
6313
|
+
if (!collection?.isDetached) {
|
|
6342
6314
|
if (this.bridge) {
|
|
6343
6315
|
await this.bridge.put(normalizedPath, stringifiedFile);
|
|
6344
6316
|
}
|
|
@@ -6356,7 +6328,7 @@ var Database = class {
|
|
|
6356
6328
|
}
|
|
6357
6329
|
}
|
|
6358
6330
|
let level = this.contentLevel;
|
|
6359
|
-
if (collection
|
|
6331
|
+
if (collection?.isDetached) {
|
|
6360
6332
|
level = this.appLevel.sublevel(collection.name, SUBLEVEL_OPTIONS);
|
|
6361
6333
|
}
|
|
6362
6334
|
const folderTreeBuilder = new FolderTreeBuilder();
|
|
@@ -6367,7 +6339,7 @@ var Database = class {
|
|
|
6367
6339
|
putOps = [
|
|
6368
6340
|
...makeRefOpsForDocument(
|
|
6369
6341
|
normalizedPath,
|
|
6370
|
-
collection
|
|
6342
|
+
collection?.name,
|
|
6371
6343
|
collectionReferences,
|
|
6372
6344
|
dataFields,
|
|
6373
6345
|
"put",
|
|
@@ -6375,7 +6347,7 @@ var Database = class {
|
|
|
6375
6347
|
),
|
|
6376
6348
|
...makeIndexOpsForDocument(
|
|
6377
6349
|
normalizedPath,
|
|
6378
|
-
collection
|
|
6350
|
+
collection?.name,
|
|
6379
6351
|
collectionIndexDefinitions,
|
|
6380
6352
|
dataFields,
|
|
6381
6353
|
"put",
|
|
@@ -6384,7 +6356,7 @@ var Database = class {
|
|
|
6384
6356
|
// folder indices
|
|
6385
6357
|
...makeIndexOpsForDocument(
|
|
6386
6358
|
normalizedPath,
|
|
6387
|
-
`${collection
|
|
6359
|
+
`${collection?.name}_${folderKey}`,
|
|
6388
6360
|
collectionIndexDefinitions,
|
|
6389
6361
|
dataFields,
|
|
6390
6362
|
"put",
|
|
@@ -6398,7 +6370,7 @@ var Database = class {
|
|
|
6398
6370
|
delOps = existingItem ? [
|
|
6399
6371
|
...makeRefOpsForDocument(
|
|
6400
6372
|
normalizedPath,
|
|
6401
|
-
collection
|
|
6373
|
+
collection?.name,
|
|
6402
6374
|
collectionReferences,
|
|
6403
6375
|
existingItem,
|
|
6404
6376
|
"del",
|
|
@@ -6406,7 +6378,7 @@ var Database = class {
|
|
|
6406
6378
|
),
|
|
6407
6379
|
...makeIndexOpsForDocument(
|
|
6408
6380
|
normalizedPath,
|
|
6409
|
-
collection
|
|
6381
|
+
collection?.name,
|
|
6410
6382
|
collectionIndexDefinitions,
|
|
6411
6383
|
existingItem,
|
|
6412
6384
|
"del",
|
|
@@ -6415,7 +6387,7 @@ var Database = class {
|
|
|
6415
6387
|
// folder indices
|
|
6416
6388
|
...makeIndexOpsForDocument(
|
|
6417
6389
|
normalizedPath,
|
|
6418
|
-
`${collection
|
|
6390
|
+
`${collection?.name}_${folderKey}`,
|
|
6419
6391
|
collectionIndexDefinitions,
|
|
6420
6392
|
existingItem,
|
|
6421
6393
|
"del",
|
|
@@ -6439,7 +6411,6 @@ var Database = class {
|
|
|
6439
6411
|
await level.batch(ops);
|
|
6440
6412
|
};
|
|
6441
6413
|
this.put = async (filepath, data, collectionName) => {
|
|
6442
|
-
var _a, _b, _c;
|
|
6443
6414
|
await this.initLevel();
|
|
6444
6415
|
try {
|
|
6445
6416
|
if (SYSTEM_FILES.includes(filepath)) {
|
|
@@ -6450,16 +6421,16 @@ var Database = class {
|
|
|
6450
6421
|
const indexDefinitions = await this.getIndexDefinitions(
|
|
6451
6422
|
this.contentLevel
|
|
6452
6423
|
);
|
|
6453
|
-
collectionIndexDefinitions = indexDefinitions
|
|
6424
|
+
collectionIndexDefinitions = indexDefinitions?.[collectionName];
|
|
6454
6425
|
}
|
|
6455
|
-
const collectionReferences = (
|
|
6426
|
+
const collectionReferences = (await this.getCollectionReferences())?.[collectionName];
|
|
6456
6427
|
const normalizedPath = (0, import_schema_tools4.normalizePath)(filepath);
|
|
6457
6428
|
const dataFields = await this.formatBodyOnPayload(filepath, data);
|
|
6458
6429
|
const collection = await this.collectionForPath(filepath);
|
|
6459
6430
|
if (!collection) {
|
|
6460
6431
|
throw new import_graphql6.GraphQLError(`Unable to find collection for ${filepath}.`);
|
|
6461
6432
|
}
|
|
6462
|
-
if (
|
|
6433
|
+
if (collection.match?.exclude || collection.match?.include) {
|
|
6463
6434
|
const matches = this.tinaSchema.getMatches({ collection });
|
|
6464
6435
|
const match = import_micromatch2.default.isMatch(filepath, matches);
|
|
6465
6436
|
if (!match) {
|
|
@@ -6473,7 +6444,7 @@ var Database = class {
|
|
|
6473
6444
|
const stringifiedFile = filepath.endsWith(
|
|
6474
6445
|
`.gitkeep.${collection.format || "md"}`
|
|
6475
6446
|
) ? "" : await this.stringifyFile(filepath, dataFields, collection);
|
|
6476
|
-
if (!
|
|
6447
|
+
if (!collection?.isDetached) {
|
|
6477
6448
|
if (this.bridge) {
|
|
6478
6449
|
await this.bridge.put(normalizedPath, stringifiedFile);
|
|
6479
6450
|
}
|
|
@@ -6495,7 +6466,7 @@ var Database = class {
|
|
|
6495
6466
|
filepath,
|
|
6496
6467
|
collection.path || ""
|
|
6497
6468
|
);
|
|
6498
|
-
const level =
|
|
6469
|
+
const level = collection?.isDetached ? this.appLevel.sublevel(collection?.name, SUBLEVEL_OPTIONS) : this.contentLevel;
|
|
6499
6470
|
let putOps = [];
|
|
6500
6471
|
let delOps = [];
|
|
6501
6472
|
if (!isGitKeep(normalizedPath, collection)) {
|
|
@@ -6519,7 +6490,7 @@ var Database = class {
|
|
|
6519
6490
|
// folder indices
|
|
6520
6491
|
...makeIndexOpsForDocument(
|
|
6521
6492
|
normalizedPath,
|
|
6522
|
-
`${collection
|
|
6493
|
+
`${collection?.name}_${folderKey}`,
|
|
6523
6494
|
collectionIndexDefinitions,
|
|
6524
6495
|
dataFields,
|
|
6525
6496
|
"put",
|
|
@@ -6550,7 +6521,7 @@ var Database = class {
|
|
|
6550
6521
|
// folder indices
|
|
6551
6522
|
...makeIndexOpsForDocument(
|
|
6552
6523
|
normalizedPath,
|
|
6553
|
-
`${collection
|
|
6524
|
+
`${collection?.name}_${folderKey}`,
|
|
6554
6525
|
collectionIndexDefinitions,
|
|
6555
6526
|
existingItem,
|
|
6556
6527
|
"del",
|
|
@@ -6627,8 +6598,8 @@ var Database = class {
|
|
|
6627
6598
|
writeTemplateKey,
|
|
6628
6599
|
//templateInfo.type === 'union',
|
|
6629
6600
|
{
|
|
6630
|
-
frontmatterFormat: collection
|
|
6631
|
-
frontmatterDelimiters: collection
|
|
6601
|
+
frontmatterFormat: collection?.frontmatterFormat,
|
|
6602
|
+
frontmatterDelimiters: collection?.frontmatterDelimiters
|
|
6632
6603
|
}
|
|
6633
6604
|
);
|
|
6634
6605
|
};
|
|
@@ -6797,8 +6768,8 @@ var Database = class {
|
|
|
6797
6768
|
);
|
|
6798
6769
|
return {
|
|
6799
6770
|
name: indexField.name,
|
|
6800
|
-
type: field
|
|
6801
|
-
list: !!
|
|
6771
|
+
type: field?.type,
|
|
6772
|
+
list: !!field?.list
|
|
6802
6773
|
};
|
|
6803
6774
|
})
|
|
6804
6775
|
};
|
|
@@ -6824,7 +6795,6 @@ var Database = class {
|
|
|
6824
6795
|
return true;
|
|
6825
6796
|
};
|
|
6826
6797
|
this.query = async (queryOptions, hydrator) => {
|
|
6827
|
-
var _a;
|
|
6828
6798
|
await this.initLevel();
|
|
6829
6799
|
const {
|
|
6830
6800
|
first,
|
|
@@ -6852,14 +6822,14 @@ var Database = class {
|
|
|
6852
6822
|
const allIndexDefinitions = await this.getIndexDefinitions(
|
|
6853
6823
|
this.contentLevel
|
|
6854
6824
|
);
|
|
6855
|
-
const indexDefinitions = allIndexDefinitions
|
|
6825
|
+
const indexDefinitions = allIndexDefinitions?.[collection.name];
|
|
6856
6826
|
if (!indexDefinitions) {
|
|
6857
6827
|
throw new Error(`No indexDefinitions for collection ${collection.name}`);
|
|
6858
6828
|
}
|
|
6859
6829
|
const filterChain = coerceFilterChainOperands(rawFilterChain);
|
|
6860
|
-
const indexDefinition = sort &&
|
|
6830
|
+
const indexDefinition = sort && indexDefinitions?.[sort];
|
|
6861
6831
|
const filterSuffixes = indexDefinition && makeFilterSuffixes(filterChain, indexDefinition);
|
|
6862
|
-
const level =
|
|
6832
|
+
const level = collection?.isDetached ? this.appLevel.sublevel(collection?.name, SUBLEVEL_OPTIONS) : this.contentLevel;
|
|
6863
6833
|
const rootLevel = level.sublevel(
|
|
6864
6834
|
CONTENT_ROOT_PREFIX,
|
|
6865
6835
|
SUBLEVEL_OPTIONS
|
|
@@ -6869,17 +6839,17 @@ var Database = class {
|
|
|
6869
6839
|
SUBLEVEL_OPTIONS
|
|
6870
6840
|
).sublevel(sort, SUBLEVEL_OPTIONS) : rootLevel;
|
|
6871
6841
|
if (!query.gt && !query.gte) {
|
|
6872
|
-
query.gte =
|
|
6842
|
+
query.gte = filterSuffixes?.left ? filterSuffixes.left : "";
|
|
6873
6843
|
}
|
|
6874
6844
|
if (!query.lt && !query.lte) {
|
|
6875
|
-
query.lte =
|
|
6845
|
+
query.lte = filterSuffixes?.right ? `${filterSuffixes.right}\uFFFF` : "\uFFFF";
|
|
6876
6846
|
}
|
|
6877
6847
|
let edges = [];
|
|
6878
6848
|
let startKey = "";
|
|
6879
6849
|
let endKey = "";
|
|
6880
6850
|
let hasPreviousPage = false;
|
|
6881
6851
|
let hasNextPage = false;
|
|
6882
|
-
const fieldsPattern =
|
|
6852
|
+
const fieldsPattern = indexDefinition?.fields?.length ? `${indexDefinition.fields.map((p) => `(?<${p.name}>.+)${INDEX_KEY_FIELD_SEPARATOR}`).join("")}` : "";
|
|
6883
6853
|
const valuesRegex = indexDefinition ? new RegExp(`^${fieldsPattern}(?<_filepath_>.+)`) : new RegExp(`^(?<_filepath_>.+)`);
|
|
6884
6854
|
const itemFilter = makeFilter({ filterChain });
|
|
6885
6855
|
const iterator = sublevel.iterator(query);
|
|
@@ -7091,18 +7061,17 @@ var Database = class {
|
|
|
7091
7061
|
}
|
|
7092
7062
|
};
|
|
7093
7063
|
this.delete = async (filepath) => {
|
|
7094
|
-
var _a;
|
|
7095
7064
|
await this.initLevel();
|
|
7096
7065
|
const collection = await this.collectionForPath(filepath);
|
|
7097
7066
|
if (!collection) {
|
|
7098
7067
|
throw new Error(`No collection found for path: ${filepath}`);
|
|
7099
7068
|
}
|
|
7100
7069
|
const indexDefinitions = await this.getIndexDefinitions(this.contentLevel);
|
|
7101
|
-
const collectionReferences = (
|
|
7102
|
-
const collectionIndexDefinitions = indexDefinitions
|
|
7070
|
+
const collectionReferences = (await this.getCollectionReferences())?.[collection.name];
|
|
7071
|
+
const collectionIndexDefinitions = indexDefinitions?.[collection.name];
|
|
7103
7072
|
let level = this.contentLevel;
|
|
7104
|
-
if (collection
|
|
7105
|
-
level = this.appLevel.sublevel(collection
|
|
7073
|
+
if (collection?.isDetached) {
|
|
7074
|
+
level = this.appLevel.sublevel(collection?.name, SUBLEVEL_OPTIONS);
|
|
7106
7075
|
}
|
|
7107
7076
|
const normalizedPath = (0, import_schema_tools4.normalizePath)(filepath);
|
|
7108
7077
|
const rootSublevel = level.sublevel(
|
|
@@ -7149,7 +7118,7 @@ var Database = class {
|
|
|
7149
7118
|
}
|
|
7150
7119
|
]);
|
|
7151
7120
|
}
|
|
7152
|
-
if (!
|
|
7121
|
+
if (!collection?.isDetached) {
|
|
7153
7122
|
if (this.bridge) {
|
|
7154
7123
|
await this.bridge.delete(normalizedPath);
|
|
7155
7124
|
}
|
|
@@ -7244,7 +7213,7 @@ var Database = class {
|
|
|
7244
7213
|
);
|
|
7245
7214
|
}
|
|
7246
7215
|
const metadata = await metadataLevel.get("metadata");
|
|
7247
|
-
return metadata
|
|
7216
|
+
return metadata?.version;
|
|
7248
7217
|
}
|
|
7249
7218
|
async initLevel() {
|
|
7250
7219
|
if (this.contentLevel) {
|
|
@@ -7330,7 +7299,7 @@ var hashPasswordVisitor = async (node, path7) => {
|
|
|
7330
7299
|
};
|
|
7331
7300
|
var visitNodes = async (node, path7, callback) => {
|
|
7332
7301
|
const [currentLevel, ...remainingLevels] = path7;
|
|
7333
|
-
if (!
|
|
7302
|
+
if (!remainingLevels?.length) {
|
|
7334
7303
|
return callback(node, path7);
|
|
7335
7304
|
}
|
|
7336
7305
|
if (Array.isArray(node[currentLevel])) {
|
|
@@ -7346,7 +7315,7 @@ var hashPasswordValues = async (data, passwordFields) => Promise.all(
|
|
|
7346
7315
|
async (passwordField) => visitNodes(data, passwordField, hashPasswordVisitor)
|
|
7347
7316
|
)
|
|
7348
7317
|
);
|
|
7349
|
-
var isGitKeep = (filepath, collection) => filepath.endsWith(`.gitkeep.${
|
|
7318
|
+
var isGitKeep = (filepath, collection) => filepath.endsWith(`.gitkeep.${collection?.format || "md"}`);
|
|
7350
7319
|
var _indexContent = async ({
|
|
7351
7320
|
database,
|
|
7352
7321
|
level,
|
|
@@ -7356,18 +7325,17 @@ var _indexContent = async ({
|
|
|
7356
7325
|
passwordFields,
|
|
7357
7326
|
isPartialReindex
|
|
7358
7327
|
}) => {
|
|
7359
|
-
var _a;
|
|
7360
7328
|
let collectionIndexDefinitions;
|
|
7361
7329
|
let collectionPath;
|
|
7362
7330
|
if (collection) {
|
|
7363
7331
|
const indexDefinitions = await database.getIndexDefinitions(level);
|
|
7364
|
-
collectionIndexDefinitions = indexDefinitions
|
|
7332
|
+
collectionIndexDefinitions = indexDefinitions?.[collection.name];
|
|
7365
7333
|
if (!collectionIndexDefinitions) {
|
|
7366
7334
|
throw new Error(`No indexDefinitions for collection ${collection.name}`);
|
|
7367
7335
|
}
|
|
7368
7336
|
collectionPath = collection.path;
|
|
7369
7337
|
}
|
|
7370
|
-
const collectionReferences = (
|
|
7338
|
+
const collectionReferences = (await database.getCollectionReferences())?.[collection?.name];
|
|
7371
7339
|
const tinaSchema = await database.getSchema();
|
|
7372
7340
|
let templateInfo = null;
|
|
7373
7341
|
if (collection) {
|
|
@@ -7385,7 +7353,7 @@ var _indexContent = async ({
|
|
|
7385
7353
|
if (!aliasedData) {
|
|
7386
7354
|
return;
|
|
7387
7355
|
}
|
|
7388
|
-
if (passwordFields
|
|
7356
|
+
if (passwordFields?.length) {
|
|
7389
7357
|
await hashPasswordValues(aliasedData, passwordFields);
|
|
7390
7358
|
}
|
|
7391
7359
|
const normalizedPath = (0, import_schema_tools4.normalizePath)(filepath);
|
|
@@ -7403,7 +7371,7 @@ var _indexContent = async ({
|
|
|
7403
7371
|
await database.contentLevel.batch([
|
|
7404
7372
|
...makeRefOpsForDocument(
|
|
7405
7373
|
normalizedPath,
|
|
7406
|
-
collection
|
|
7374
|
+
collection?.name,
|
|
7407
7375
|
collectionReferences,
|
|
7408
7376
|
item,
|
|
7409
7377
|
"del",
|
|
@@ -7438,7 +7406,7 @@ var _indexContent = async ({
|
|
|
7438
7406
|
await enqueueOps([
|
|
7439
7407
|
...makeRefOpsForDocument(
|
|
7440
7408
|
normalizedPath,
|
|
7441
|
-
collection
|
|
7409
|
+
collection?.name,
|
|
7442
7410
|
collectionReferences,
|
|
7443
7411
|
aliasedData,
|
|
7444
7412
|
"put",
|
|
@@ -7446,7 +7414,7 @@ var _indexContent = async ({
|
|
|
7446
7414
|
),
|
|
7447
7415
|
...makeIndexOpsForDocument(
|
|
7448
7416
|
normalizedPath,
|
|
7449
|
-
collection
|
|
7417
|
+
collection?.name,
|
|
7450
7418
|
collectionIndexDefinitions,
|
|
7451
7419
|
aliasedData,
|
|
7452
7420
|
"put",
|
|
@@ -7455,7 +7423,7 @@ var _indexContent = async ({
|
|
|
7455
7423
|
// folder indexes
|
|
7456
7424
|
...makeIndexOpsForDocument(
|
|
7457
7425
|
normalizedPath,
|
|
7458
|
-
`${collection
|
|
7426
|
+
`${collection?.name}_${folderKey}`,
|
|
7459
7427
|
collectionIndexDefinitions,
|
|
7460
7428
|
aliasedData,
|
|
7461
7429
|
"put",
|
|
@@ -7476,7 +7444,7 @@ var _indexContent = async ({
|
|
|
7476
7444
|
throw new TinaFetchError(`Unable to seed ${filepath}`, {
|
|
7477
7445
|
originalError: error,
|
|
7478
7446
|
file: filepath,
|
|
7479
|
-
collection: collection
|
|
7447
|
+
collection: collection?.name,
|
|
7480
7448
|
stack: error.stack
|
|
7481
7449
|
});
|
|
7482
7450
|
}
|
|
@@ -7494,7 +7462,6 @@ var _indexContent = async ({
|
|
|
7494
7462
|
}
|
|
7495
7463
|
};
|
|
7496
7464
|
var _deleteIndexContent = async (database, documentPaths, enqueueOps, collection) => {
|
|
7497
|
-
var _a;
|
|
7498
7465
|
if (!documentPaths.length) {
|
|
7499
7466
|
return;
|
|
7500
7467
|
}
|
|
@@ -7503,12 +7470,12 @@ var _deleteIndexContent = async (database, documentPaths, enqueueOps, collection
|
|
|
7503
7470
|
const indexDefinitions = await database.getIndexDefinitions(
|
|
7504
7471
|
database.contentLevel
|
|
7505
7472
|
);
|
|
7506
|
-
collectionIndexDefinitions = indexDefinitions
|
|
7473
|
+
collectionIndexDefinitions = indexDefinitions?.[collection.name];
|
|
7507
7474
|
if (!collectionIndexDefinitions) {
|
|
7508
7475
|
throw new Error(`No indexDefinitions for collection ${collection.name}`);
|
|
7509
7476
|
}
|
|
7510
7477
|
}
|
|
7511
|
-
const collectionReferences = (
|
|
7478
|
+
const collectionReferences = (await database.getCollectionReferences())?.[collection?.name];
|
|
7512
7479
|
const tinaSchema = await database.getSchema();
|
|
7513
7480
|
let templateInfo = null;
|
|
7514
7481
|
if (collection) {
|
|
@@ -7525,7 +7492,7 @@ var _deleteIndexContent = async (database, documentPaths, enqueueOps, collection
|
|
|
7525
7492
|
if (item) {
|
|
7526
7493
|
const folderKey = folderTreeBuilder.update(
|
|
7527
7494
|
itemKey,
|
|
7528
|
-
|
|
7495
|
+
collection?.path || ""
|
|
7529
7496
|
);
|
|
7530
7497
|
const aliasedData = templateInfo ? replaceNameOverrides(
|
|
7531
7498
|
getTemplateForFile(templateInfo, item),
|
|
@@ -7534,7 +7501,7 @@ var _deleteIndexContent = async (database, documentPaths, enqueueOps, collection
|
|
|
7534
7501
|
await enqueueOps([
|
|
7535
7502
|
...makeRefOpsForDocument(
|
|
7536
7503
|
itemKey,
|
|
7537
|
-
collection
|
|
7504
|
+
collection?.name,
|
|
7538
7505
|
collectionReferences,
|
|
7539
7506
|
aliasedData,
|
|
7540
7507
|
"del",
|
|
@@ -7551,7 +7518,7 @@ var _deleteIndexContent = async (database, documentPaths, enqueueOps, collection
|
|
|
7551
7518
|
// folder indexes
|
|
7552
7519
|
...makeIndexOpsForDocument(
|
|
7553
7520
|
itemKey,
|
|
7554
|
-
`${collection
|
|
7521
|
+
`${collection?.name}_${folderKey}`,
|
|
7555
7522
|
collectionIndexDefinitions,
|
|
7556
7523
|
aliasedData,
|
|
7557
7524
|
"del",
|
|
@@ -7636,12 +7603,12 @@ var getChangedFiles = async ({
|
|
|
7636
7603
|
}
|
|
7637
7604
|
}
|
|
7638
7605
|
}
|
|
7639
|
-
if (await
|
|
7606
|
+
if (await B?.type() === "tree") {
|
|
7640
7607
|
return;
|
|
7641
7608
|
}
|
|
7642
7609
|
if (matches) {
|
|
7643
|
-
const oidA = await
|
|
7644
|
-
const oidB = await
|
|
7610
|
+
const oidA = await A?.oid();
|
|
7611
|
+
const oidB = await B?.oid();
|
|
7645
7612
|
if (oidA !== oidB) {
|
|
7646
7613
|
if (oidA === void 0) {
|
|
7647
7614
|
results.added.push(relativePath);
|
|
@@ -7669,8 +7636,8 @@ var import_path5 = __toESM(require("path"));
|
|
|
7669
7636
|
var import_normalize_path = __toESM(require("normalize-path"));
|
|
7670
7637
|
var FilesystemBridge = class {
|
|
7671
7638
|
constructor(rootPath, outputPath) {
|
|
7672
|
-
this.rootPath = rootPath
|
|
7673
|
-
this.outputPath = outputPath
|
|
7639
|
+
this.rootPath = import_path5.default.resolve(rootPath);
|
|
7640
|
+
this.outputPath = outputPath ? import_path5.default.resolve(outputPath) : this.rootPath;
|
|
7674
7641
|
}
|
|
7675
7642
|
async glob(pattern, extension) {
|
|
7676
7643
|
const basePath = import_path5.default.join(this.outputPath, ...pattern.split("/"));
|
|
@@ -7682,19 +7649,19 @@ var FilesystemBridge = class {
|
|
|
7682
7649
|
}
|
|
7683
7650
|
);
|
|
7684
7651
|
const posixRootPath = (0, import_normalize_path.default)(this.outputPath);
|
|
7685
|
-
return items.map(
|
|
7686
|
-
|
|
7687
|
-
|
|
7652
|
+
return items.map(
|
|
7653
|
+
(item) => item.substring(posixRootPath.length).replace(/^\/|\/$/g, "")
|
|
7654
|
+
);
|
|
7688
7655
|
}
|
|
7689
7656
|
async delete(filepath) {
|
|
7690
7657
|
await import_fs_extra2.default.remove(import_path5.default.join(this.outputPath, filepath));
|
|
7691
7658
|
}
|
|
7692
7659
|
async get(filepath) {
|
|
7693
|
-
return import_fs_extra2.default.
|
|
7660
|
+
return (await import_fs_extra2.default.readFile(import_path5.default.join(this.outputPath, filepath))).toString();
|
|
7694
7661
|
}
|
|
7695
7662
|
async put(filepath, data, basePathOverride) {
|
|
7696
7663
|
const basePath = basePathOverride || this.outputPath;
|
|
7697
|
-
await import_fs_extra2.default.
|
|
7664
|
+
await import_fs_extra2.default.outputFile(import_path5.default.join(basePath, filepath), data);
|
|
7698
7665
|
}
|
|
7699
7666
|
};
|
|
7700
7667
|
var AuditFileSystemBridge = class extends FilesystemBridge {
|