@tinacms/graphql 1.3.2 → 1.3.3
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/builder/index.d.ts +12 -12
- package/dist/database/alias-utils.d.ts +3 -0
- package/dist/database/index.d.ts +26 -9
- package/dist/index.d.ts +3 -7
- package/dist/index.es.js +153 -93
- package/dist/index.js +157 -93
- package/dist/resolver/filter-utils.d.ts +4 -4
- package/dist/resolver/index.d.ts +31 -29
- package/dist/resolver/media-utils.d.ts +3 -3
- package/dist/schema/createSchema.d.ts +2 -2
- package/dist/schema/validate.d.ts +8 -2
- package/dist/spec/setup.d.ts +4 -4
- package/package.json +5 -5
- package/dist/mdx/parse.d.ts +0 -220
- package/dist/mdx/stringify.d.ts +0 -13
package/dist/index.js
CHANGED
|
@@ -1580,8 +1580,9 @@ var Builder = class {
|
|
|
1580
1580
|
});
|
|
1581
1581
|
};
|
|
1582
1582
|
this._getCollectionFragmentSelections = async (collection, depth) => {
|
|
1583
|
+
var _a;
|
|
1583
1584
|
const selections = [];
|
|
1584
|
-
if (
|
|
1585
|
+
if (((_a = collection.fields) == null ? void 0 : _a.length) > 0) {
|
|
1585
1586
|
await sequential(collection.fields, async (x) => {
|
|
1586
1587
|
const field = await this._buildFieldNodeForFragments(x, depth);
|
|
1587
1588
|
selections.push(field);
|
|
@@ -1596,6 +1597,7 @@ var Builder = class {
|
|
|
1596
1597
|
return selections;
|
|
1597
1598
|
};
|
|
1598
1599
|
this._buildFieldNodeForFragments = async (field, depth) => {
|
|
1600
|
+
var _a, _b;
|
|
1599
1601
|
switch (field.type) {
|
|
1600
1602
|
case "string":
|
|
1601
1603
|
case "image":
|
|
@@ -1605,7 +1607,7 @@ var Builder = class {
|
|
|
1605
1607
|
case "rich-text":
|
|
1606
1608
|
return astBuilder.FieldNodeDefinition(field);
|
|
1607
1609
|
case "object":
|
|
1608
|
-
if (
|
|
1610
|
+
if (((_a = field.fields) == null ? void 0 : _a.length) > 0) {
|
|
1609
1611
|
const selections2 = [];
|
|
1610
1612
|
await sequential(field.fields, async (item) => {
|
|
1611
1613
|
const field2 = await this._buildFieldNodeForFragments(item, depth);
|
|
@@ -1618,7 +1620,7 @@ var Builder = class {
|
|
|
1618
1620
|
...filterSelections(selections2)
|
|
1619
1621
|
]
|
|
1620
1622
|
});
|
|
1621
|
-
} else if (
|
|
1623
|
+
} else if (((_b = field.templates) == null ? void 0 : _b.length) > 0) {
|
|
1622
1624
|
const selections2 = [];
|
|
1623
1625
|
await sequential(field.templates, async (tem) => {
|
|
1624
1626
|
if (typeof tem === "object") {
|
|
@@ -2447,9 +2449,6 @@ var validateCollection = async (collection) => {
|
|
|
2447
2449
|
const validCollection = await collectionSchema.cast(collection);
|
|
2448
2450
|
if (validCollection.templates) {
|
|
2449
2451
|
templates = await sequential(validCollection.templates, async (template) => {
|
|
2450
|
-
if (typeof template === "string") {
|
|
2451
|
-
throw new Error(`Global templates are not yet supported`);
|
|
2452
|
-
}
|
|
2453
2452
|
const fields2 = await sequential(template.fields, async (field) => {
|
|
2454
2453
|
return validateField(field);
|
|
2455
2454
|
});
|
|
@@ -2478,12 +2477,13 @@ var validateField = async (field) => {
|
|
|
2478
2477
|
type: yup2.string().oneOf(FIELD_TYPES, (obj) => `'type' must be one of: ${obj.values}, but got '${obj.value}' at ${messageName}`)
|
|
2479
2478
|
});
|
|
2480
2479
|
await schema.validate(field);
|
|
2481
|
-
|
|
2480
|
+
const validField = await schema.cast(field);
|
|
2481
|
+
return validField;
|
|
2482
2482
|
};
|
|
2483
2483
|
|
|
2484
2484
|
// package.json
|
|
2485
2485
|
var name = "@tinacms/graphql";
|
|
2486
|
-
var version = "1.3.
|
|
2486
|
+
var version = "1.3.3";
|
|
2487
2487
|
var main = "dist/index.js";
|
|
2488
2488
|
var module2 = "dist/index.es.js";
|
|
2489
2489
|
var typings = "dist/index.d.ts";
|
|
@@ -2842,16 +2842,7 @@ var resolveReferences = async (filter, fields, resolver) => {
|
|
|
2842
2842
|
}
|
|
2843
2843
|
} else if (fieldDefinition.type === "object") {
|
|
2844
2844
|
if (fieldDefinition.templates) {
|
|
2845
|
-
const globalTemplates = {};
|
|
2846
|
-
for (const template of fieldDefinition.templates) {
|
|
2847
|
-
if (typeof template === "string") {
|
|
2848
|
-
globalTemplates[template] = 1;
|
|
2849
|
-
}
|
|
2850
|
-
}
|
|
2851
2845
|
for (const templateName of Object.keys(filter[fieldKey])) {
|
|
2852
|
-
if (templateName in globalTemplates) {
|
|
2853
|
-
throw new Error("Global templates not yet supported for queries");
|
|
2854
|
-
}
|
|
2855
2846
|
const template = fieldDefinition.templates.find((template2) => !(typeof template2 === "string") && template2.name === templateName);
|
|
2856
2847
|
if (template) {
|
|
2857
2848
|
await resolveReferences(filter[fieldKey][templateName], template.fields, resolver);
|
|
@@ -2879,16 +2870,7 @@ var collectConditionsForChildFields = (filterNode, fields, pathExpression, colle
|
|
|
2879
2870
|
};
|
|
2880
2871
|
var collectConditionsForObjectField = (fieldName, field, filterNode, pathExpression, collectCondition) => {
|
|
2881
2872
|
if (field.list && field.templates) {
|
|
2882
|
-
const globalTemplates = {};
|
|
2883
|
-
for (const template of field.templates) {
|
|
2884
|
-
if (typeof template === "string") {
|
|
2885
|
-
globalTemplates[template] = 1;
|
|
2886
|
-
}
|
|
2887
|
-
}
|
|
2888
2873
|
for (const [filterKey, childFilterNode] of Object.entries(filterNode)) {
|
|
2889
|
-
if (filterKey in globalTemplates) {
|
|
2890
|
-
throw new Error("Global templates not yet supported for queries");
|
|
2891
|
-
}
|
|
2892
2874
|
const template = field.templates.find((template2) => !(typeof template2 === "string") && template2.name === filterKey);
|
|
2893
2875
|
const jsonPath = `${fieldName}[?(@._template=="${filterKey}")]`;
|
|
2894
2876
|
const filterPath = pathExpression ? `${pathExpression}.${jsonPath}` : jsonPath;
|
|
@@ -3471,7 +3453,7 @@ var Resolver = class {
|
|
|
3471
3453
|
};
|
|
3472
3454
|
this.buildObjectMutations = (fieldValue, field) => {
|
|
3473
3455
|
if (field.fields) {
|
|
3474
|
-
const objectTemplate =
|
|
3456
|
+
const objectTemplate = field;
|
|
3475
3457
|
if (Array.isArray(fieldValue)) {
|
|
3476
3458
|
return fieldValue.map((item) => this.buildFieldMutations(item, objectTemplate));
|
|
3477
3459
|
} else {
|
|
@@ -3485,9 +3467,6 @@ var Resolver = class {
|
|
|
3485
3467
|
throw new Error(`Expected object for template value for field ${field.name}`);
|
|
3486
3468
|
}
|
|
3487
3469
|
const templates = field.templates.map((templateOrTemplateName) => {
|
|
3488
|
-
if (typeof templateOrTemplateName === "string") {
|
|
3489
|
-
return this.tinaSchema.getGlobalTemplate(templateOrTemplateName);
|
|
3490
|
-
}
|
|
3491
3470
|
return templateOrTemplateName;
|
|
3492
3471
|
});
|
|
3493
3472
|
const [templateName] = Object.entries(item)[0];
|
|
@@ -3504,9 +3483,6 @@ var Resolver = class {
|
|
|
3504
3483
|
throw new Error(`Expected object for template value for field ${field.name}`);
|
|
3505
3484
|
}
|
|
3506
3485
|
const templates = field.templates.map((templateOrTemplateName) => {
|
|
3507
|
-
if (typeof templateOrTemplateName === "string") {
|
|
3508
|
-
return this.tinaSchema.getGlobalTemplate(templateOrTemplateName);
|
|
3509
|
-
}
|
|
3510
3486
|
return templateOrTemplateName;
|
|
3511
3487
|
});
|
|
3512
3488
|
const [templateName] = Object.entries(fieldValue)[0];
|
|
@@ -4217,6 +4193,64 @@ var parseFile = (content, format, yupSchema, markdownParseConfig) => {
|
|
|
4217
4193
|
};
|
|
4218
4194
|
var normalizePath = (filepath) => filepath.replace(/\\/g, "/");
|
|
4219
4195
|
|
|
4196
|
+
// src/database/alias-utils.ts
|
|
4197
|
+
var replaceNameOverrides = (template, obj) => {
|
|
4198
|
+
if (template.list) {
|
|
4199
|
+
return obj.map((item) => {
|
|
4200
|
+
return _replaceNameOverrides(getTemplateForData(template, item).fields, item);
|
|
4201
|
+
});
|
|
4202
|
+
} else {
|
|
4203
|
+
return _replaceNameOverrides(getTemplateForData(template, obj).fields, obj);
|
|
4204
|
+
}
|
|
4205
|
+
};
|
|
4206
|
+
var _replaceNameOverrides = (fields, obj) => {
|
|
4207
|
+
const output = {};
|
|
4208
|
+
Object.keys(obj).forEach((key) => {
|
|
4209
|
+
const field = fields.find((fieldWithMatchingAlias) => ((fieldWithMatchingAlias == null ? void 0 : fieldWithMatchingAlias.nameOverride) || (fieldWithMatchingAlias == null ? void 0 : fieldWithMatchingAlias.name)) === key);
|
|
4210
|
+
output[(field == null ? void 0 : field.name) || key] = (field == null ? void 0 : field.type) == "object" ? replaceNameOverrides(field, obj[key]) : obj[key];
|
|
4211
|
+
});
|
|
4212
|
+
return output;
|
|
4213
|
+
};
|
|
4214
|
+
var getTemplateKey = (field) => {
|
|
4215
|
+
var _a, _b, _c;
|
|
4216
|
+
const DEFAULT_TEMPLATE_KEY = "_template";
|
|
4217
|
+
if ((_a = field.templates) == null ? void 0 : _a.length) {
|
|
4218
|
+
const templateField = (_c = (_b = field.templates[0]) == null ? void 0 : _b.fields) == null ? void 0 : _c.find((field2) => field2.name === DEFAULT_TEMPLATE_KEY);
|
|
4219
|
+
return (templateField == null ? void 0 : templateField.alias) || DEFAULT_TEMPLATE_KEY;
|
|
4220
|
+
}
|
|
4221
|
+
return DEFAULT_TEMPLATE_KEY;
|
|
4222
|
+
};
|
|
4223
|
+
var getTemplateForData = (field, data) => {
|
|
4224
|
+
var _a;
|
|
4225
|
+
if ((_a = field.templates) == null ? void 0 : _a.length) {
|
|
4226
|
+
const templateKey = getTemplateKey(field);
|
|
4227
|
+
if (data[templateKey]) {
|
|
4228
|
+
return field.templates.find((template) => template.name === data[templateKey]);
|
|
4229
|
+
}
|
|
4230
|
+
} else {
|
|
4231
|
+
return field;
|
|
4232
|
+
}
|
|
4233
|
+
throw new Error("No template found for field " + field.name);
|
|
4234
|
+
};
|
|
4235
|
+
var applyNameOverrides = (template, obj) => {
|
|
4236
|
+
if (template.list) {
|
|
4237
|
+
return obj.map((item) => {
|
|
4238
|
+
return _applyNameOverrides(getTemplateForData(template, item).fields, item);
|
|
4239
|
+
});
|
|
4240
|
+
} else {
|
|
4241
|
+
return _applyNameOverrides(getTemplateForData(template, obj).fields, obj);
|
|
4242
|
+
}
|
|
4243
|
+
};
|
|
4244
|
+
var _applyNameOverrides = (fields, obj) => {
|
|
4245
|
+
const output = {};
|
|
4246
|
+
Object.keys(obj).forEach((key) => {
|
|
4247
|
+
const field = fields.find((field2) => field2.name === key);
|
|
4248
|
+
const outputKey = (field == null ? void 0 : field.nameOverride) || key;
|
|
4249
|
+
output[outputKey] = (field == null ? void 0 : field.type) === "object" ? applyNameOverrides(field, obj[key]) : obj[key];
|
|
4250
|
+
});
|
|
4251
|
+
return output;
|
|
4252
|
+
};
|
|
4253
|
+
|
|
4220
4254
|
// src/database/index.ts
|
|
4221
4255
|
var createDatabase = (config) => {
|
|
4222
4256
|
return new Database(__spreadProps(__spreadValues({}, config), {
|
|
@@ -4276,8 +4310,9 @@ var Database = class {
|
|
|
4276
4310
|
};
|
|
4277
4311
|
this.addPendingDocument = async (filepath, data) => {
|
|
4278
4312
|
await this.initLevel();
|
|
4279
|
-
const
|
|
4313
|
+
const dataFields = await this.formatBodyOnPayload(filepath, data);
|
|
4280
4314
|
const collection = await this.collectionForPath(filepath);
|
|
4315
|
+
const stringifiedFile = await this.stringifyFile(filepath, dataFields, collection);
|
|
4281
4316
|
let collectionIndexDefinitions;
|
|
4282
4317
|
if (collection) {
|
|
4283
4318
|
const indexDefinitions = await this.getIndexDefinitions(this.level);
|
|
@@ -4288,7 +4323,7 @@ var Database = class {
|
|
|
4288
4323
|
await this.bridge.put(normalizedPath, stringifiedFile);
|
|
4289
4324
|
}
|
|
4290
4325
|
await this.onPut(normalizedPath, stringifiedFile);
|
|
4291
|
-
const putOps = makeIndexOpsForDocument(normalizedPath, collection == null ? void 0 : collection.name, collectionIndexDefinitions,
|
|
4326
|
+
const putOps = makeIndexOpsForDocument(normalizedPath, collection == null ? void 0 : collection.name, collectionIndexDefinitions, dataFields, "put", this.level);
|
|
4292
4327
|
const existingItem = await this.level.sublevel(CONTENT_ROOT_PREFIX, SUBLEVEL_OPTIONS).get(normalizedPath);
|
|
4293
4328
|
const delOps = existingItem ? makeIndexOpsForDocument(normalizedPath, collection == null ? void 0 : collection.name, collectionIndexDefinitions, existingItem, "del", this.level) : [];
|
|
4294
4329
|
const ops = [
|
|
@@ -4297,39 +4332,41 @@ var Database = class {
|
|
|
4297
4332
|
{
|
|
4298
4333
|
type: "put",
|
|
4299
4334
|
key: normalizedPath,
|
|
4300
|
-
value:
|
|
4335
|
+
value: dataFields,
|
|
4301
4336
|
sublevel: this.level.sublevel(CONTENT_ROOT_PREFIX, SUBLEVEL_OPTIONS)
|
|
4302
4337
|
}
|
|
4303
4338
|
];
|
|
4304
4339
|
await this.level.batch(ops);
|
|
4305
4340
|
};
|
|
4306
|
-
this.put = async (filepath, data,
|
|
4341
|
+
this.put = async (filepath, data, collectionName) => {
|
|
4307
4342
|
await this.initLevel();
|
|
4308
4343
|
try {
|
|
4309
4344
|
if (SYSTEM_FILES.includes(filepath)) {
|
|
4310
4345
|
throw new Error(`Unexpected put for config file ${filepath}`);
|
|
4311
4346
|
} else {
|
|
4312
4347
|
let collectionIndexDefinitions;
|
|
4313
|
-
if (
|
|
4348
|
+
if (collectionName) {
|
|
4314
4349
|
const indexDefinitions = await this.getIndexDefinitions(this.level);
|
|
4315
|
-
collectionIndexDefinitions = indexDefinitions == null ? void 0 : indexDefinitions[
|
|
4350
|
+
collectionIndexDefinitions = indexDefinitions == null ? void 0 : indexDefinitions[collectionName];
|
|
4316
4351
|
}
|
|
4317
4352
|
const normalizedPath = normalizePath(filepath);
|
|
4318
|
-
const
|
|
4353
|
+
const dataFields = await this.formatBodyOnPayload(filepath, data);
|
|
4354
|
+
const collection = await this.collectionForPath(filepath);
|
|
4355
|
+
const stringifiedFile = await this.stringifyFile(filepath, dataFields, collection);
|
|
4319
4356
|
if (this.bridge) {
|
|
4320
4357
|
await this.bridge.put(normalizedPath, stringifiedFile);
|
|
4321
4358
|
}
|
|
4322
4359
|
await this.onPut(normalizedPath, stringifiedFile);
|
|
4323
|
-
const putOps = makeIndexOpsForDocument(normalizedPath,
|
|
4360
|
+
const putOps = makeIndexOpsForDocument(normalizedPath, collectionName, collectionIndexDefinitions, dataFields, "put", this.level);
|
|
4324
4361
|
const existingItem = await this.level.sublevel(CONTENT_ROOT_PREFIX, SUBLEVEL_OPTIONS).get(normalizedPath);
|
|
4325
|
-
const delOps = existingItem ? makeIndexOpsForDocument(normalizedPath,
|
|
4362
|
+
const delOps = existingItem ? makeIndexOpsForDocument(normalizedPath, collectionName, collectionIndexDefinitions, existingItem, "del", this.level) : [];
|
|
4326
4363
|
const ops = [
|
|
4327
4364
|
...delOps,
|
|
4328
4365
|
...putOps,
|
|
4329
4366
|
{
|
|
4330
4367
|
type: "put",
|
|
4331
4368
|
key: normalizedPath,
|
|
4332
|
-
value:
|
|
4369
|
+
value: dataFields,
|
|
4333
4370
|
sublevel: this.level.sublevel(CONTENT_ROOT_PREFIX, SUBLEVEL_OPTIONS)
|
|
4334
4371
|
}
|
|
4335
4372
|
];
|
|
@@ -4340,66 +4377,52 @@ var Database = class {
|
|
|
4340
4377
|
throw new TinaFetchError(`Error in PUT for ${filepath}`, {
|
|
4341
4378
|
originalError: error,
|
|
4342
4379
|
file: filepath,
|
|
4343
|
-
collection,
|
|
4380
|
+
collection: collectionName,
|
|
4344
4381
|
stack: error.stack
|
|
4345
4382
|
});
|
|
4346
4383
|
}
|
|
4347
4384
|
};
|
|
4348
|
-
this.
|
|
4349
|
-
|
|
4350
|
-
|
|
4351
|
-
}
|
|
4352
|
-
|
|
4353
|
-
|
|
4354
|
-
|
|
4355
|
-
|
|
4356
|
-
if (templateInfo.type === "object") {
|
|
4357
|
-
template = templateInfo.template;
|
|
4358
|
-
}
|
|
4359
|
-
if (templateInfo.type === "union") {
|
|
4360
|
-
if (hasOwnProperty(data, "_template")) {
|
|
4361
|
-
template = templateInfo.templates.find((t) => lastItem(t.namespace) === data._template);
|
|
4362
|
-
} else {
|
|
4363
|
-
throw new Error(`Expected _template to be provided for document in an ambiguous collection`);
|
|
4385
|
+
this.formatBodyOnPayload = async (filepath, data) => {
|
|
4386
|
+
const tinaSchema = await this.getSchema(this.level);
|
|
4387
|
+
const collection = tinaSchema.getCollectionByFullPath(filepath);
|
|
4388
|
+
const { template } = await this.getTemplateDetailsForFile(collection, data);
|
|
4389
|
+
const bodyField = template.fields.find((field) => {
|
|
4390
|
+
if (field.type === "string" || field.type === "rich-text") {
|
|
4391
|
+
if (field.isBody) {
|
|
4392
|
+
return true;
|
|
4364
4393
|
}
|
|
4365
4394
|
}
|
|
4366
|
-
|
|
4367
|
-
|
|
4368
|
-
|
|
4369
|
-
|
|
4370
|
-
|
|
4371
|
-
|
|
4372
|
-
|
|
4373
|
-
}
|
|
4395
|
+
return false;
|
|
4396
|
+
});
|
|
4397
|
+
let payload = {};
|
|
4398
|
+
if (["md", "mdx"].includes(collection.format) && bodyField) {
|
|
4399
|
+
Object.entries(data).forEach(([key, value]) => {
|
|
4400
|
+
if (key !== bodyField.name) {
|
|
4401
|
+
payload[key] = value;
|
|
4374
4402
|
}
|
|
4375
|
-
return false;
|
|
4376
4403
|
});
|
|
4377
|
-
|
|
4378
|
-
|
|
4379
|
-
|
|
4380
|
-
if (key !== field.name) {
|
|
4381
|
-
payload[key] = value;
|
|
4382
|
-
}
|
|
4383
|
-
});
|
|
4384
|
-
payload["$_body"] = data[field.name];
|
|
4385
|
-
} else {
|
|
4386
|
-
payload = data;
|
|
4387
|
-
}
|
|
4388
|
-
const extension = import_path3.default.extname(filepath);
|
|
4389
|
-
const stringifiedFile = stringifyFile(payload, extension, templateInfo.type === "union", {
|
|
4390
|
-
frontmatterFormat: collection == null ? void 0 : collection.frontmatterFormat,
|
|
4391
|
-
frontmatterDelimiters: collection == null ? void 0 : collection.frontmatterDelimiters
|
|
4392
|
-
});
|
|
4393
|
-
return {
|
|
4394
|
-
stringifiedFile,
|
|
4395
|
-
payload,
|
|
4396
|
-
keepTemplateKey: templateInfo.type === "union"
|
|
4397
|
-
};
|
|
4404
|
+
payload["$_body"] = data[bodyField.name];
|
|
4405
|
+
} else {
|
|
4406
|
+
payload = data;
|
|
4398
4407
|
}
|
|
4408
|
+
return payload;
|
|
4409
|
+
};
|
|
4410
|
+
this.stringifyFile = async (filepath, payload, collection) => {
|
|
4411
|
+
const templateDetails = await this.getTemplateDetailsForFile(collection, payload);
|
|
4412
|
+
const writeTemplateKey = templateDetails.info.type === "union";
|
|
4413
|
+
const aliasedData = applyNameOverrides(templateDetails.template, payload);
|
|
4414
|
+
const extension = import_path3.default.extname(filepath);
|
|
4415
|
+
const stringifiedFile = stringifyFile(aliasedData, extension, writeTemplateKey, {
|
|
4416
|
+
frontmatterFormat: collection == null ? void 0 : collection.frontmatterFormat,
|
|
4417
|
+
frontmatterDelimiters: collection == null ? void 0 : collection.frontmatterDelimiters
|
|
4418
|
+
});
|
|
4419
|
+
return stringifiedFile;
|
|
4399
4420
|
};
|
|
4400
4421
|
this.flush = async (filepath) => {
|
|
4401
4422
|
const data = await this.get(filepath);
|
|
4402
|
-
const
|
|
4423
|
+
const dataFields = await this.formatBodyOnPayload(filepath, data);
|
|
4424
|
+
const collection = await this.collectionForPath(filepath);
|
|
4425
|
+
const stringifiedFile = await this.stringifyFile(filepath, dataFields, collection);
|
|
4403
4426
|
return stringifiedFile;
|
|
4404
4427
|
};
|
|
4405
4428
|
this.getLookup = async (returnType) => {
|
|
@@ -4793,6 +4816,28 @@ var Database = class {
|
|
|
4793
4816
|
throw new import_graphql5.GraphQLError("Error initializing LevelDB instance");
|
|
4794
4817
|
}
|
|
4795
4818
|
}
|
|
4819
|
+
async getTemplateDetailsForFile(collection, data) {
|
|
4820
|
+
const tinaSchema = await this.getSchema();
|
|
4821
|
+
const templateInfo = await tinaSchema.getTemplatesForCollectable(collection);
|
|
4822
|
+
let template;
|
|
4823
|
+
if (templateInfo.type === "object") {
|
|
4824
|
+
template = templateInfo.template;
|
|
4825
|
+
}
|
|
4826
|
+
if (templateInfo.type === "union") {
|
|
4827
|
+
if (hasOwnProperty(data, "_template")) {
|
|
4828
|
+
template = templateInfo.templates.find((t) => lastItem(t.namespace) === data._template);
|
|
4829
|
+
} else {
|
|
4830
|
+
throw new Error(`Expected _template to be provided for document in an ambiguous collection`);
|
|
4831
|
+
}
|
|
4832
|
+
}
|
|
4833
|
+
if (!template) {
|
|
4834
|
+
throw new Error(`Unable to determine template`);
|
|
4835
|
+
}
|
|
4836
|
+
return {
|
|
4837
|
+
template,
|
|
4838
|
+
info: templateInfo
|
|
4839
|
+
};
|
|
4840
|
+
}
|
|
4796
4841
|
clearCache() {
|
|
4797
4842
|
this.tinaSchema = null;
|
|
4798
4843
|
this._lookup = null;
|
|
@@ -4820,6 +4865,11 @@ var _indexContent = async (database, level, documentPaths, enqueueOps, collectio
|
|
|
4820
4865
|
throw new Error(`No indexDefinitions for collection ${collection.name}`);
|
|
4821
4866
|
}
|
|
4822
4867
|
}
|
|
4868
|
+
const tinaSchema = await database.getSchema();
|
|
4869
|
+
let templateInfo = null;
|
|
4870
|
+
if (collection) {
|
|
4871
|
+
templateInfo = await tinaSchema.getTemplatesForCollectable(collection);
|
|
4872
|
+
}
|
|
4823
4873
|
await sequential(documentPaths, async (filepath) => {
|
|
4824
4874
|
try {
|
|
4825
4875
|
const dataString = await database.bridge.get(normalizePath(filepath));
|
|
@@ -4828,12 +4878,13 @@ var _indexContent = async (database, level, documentPaths, enqueueOps, collectio
|
|
|
4828
4878
|
frontmatterFormat: collection == null ? void 0 : collection.frontmatterFormat
|
|
4829
4879
|
});
|
|
4830
4880
|
const normalizedPath = normalizePath(filepath);
|
|
4881
|
+
const aliasedData = templateInfo ? replaceNameOverrides(getTemplateForFile(templateInfo, data), data) : data;
|
|
4831
4882
|
await enqueueOps([
|
|
4832
|
-
...makeIndexOpsForDocument(normalizedPath, collection == null ? void 0 : collection.name, collectionIndexDefinitions,
|
|
4883
|
+
...makeIndexOpsForDocument(normalizedPath, collection == null ? void 0 : collection.name, collectionIndexDefinitions, aliasedData, "put", level),
|
|
4833
4884
|
{
|
|
4834
4885
|
type: "put",
|
|
4835
4886
|
key: normalizedPath,
|
|
4836
|
-
value:
|
|
4887
|
+
value: aliasedData,
|
|
4837
4888
|
sublevel: level.sublevel(CONTENT_ROOT_PREFIX, SUBLEVEL_OPTIONS)
|
|
4838
4889
|
}
|
|
4839
4890
|
]);
|
|
@@ -4868,6 +4919,19 @@ var _deleteIndexContent = async (database, documentPaths, enequeueOps, collectio
|
|
|
4868
4919
|
}
|
|
4869
4920
|
});
|
|
4870
4921
|
};
|
|
4922
|
+
var getTemplateForFile = (templateInfo, data) => {
|
|
4923
|
+
if (templateInfo.type === "object") {
|
|
4924
|
+
return templateInfo.template;
|
|
4925
|
+
}
|
|
4926
|
+
if (templateInfo.type === "union") {
|
|
4927
|
+
if (hasOwnProperty(data, "_template")) {
|
|
4928
|
+
return templateInfo.templates.find((t) => lastItem(t.namespace) === data._template);
|
|
4929
|
+
} else {
|
|
4930
|
+
throw new Error(`Expected _template to be provided for document in an ambiguous collection`);
|
|
4931
|
+
}
|
|
4932
|
+
}
|
|
4933
|
+
throw new Error(`Unable to determine template`);
|
|
4934
|
+
};
|
|
4871
4935
|
|
|
4872
4936
|
// src/level/tinaLevel.ts
|
|
4873
4937
|
var import_many_level = __toModule(require("many-level"));
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
|
|
3
3
|
*/
|
|
4
|
-
import type {
|
|
4
|
+
import type { ReferenceType, TinaField } from '@tinacms/schema-tools';
|
|
5
5
|
import { FilterCondition } from '../database/datalayer';
|
|
6
|
-
export declare type ReferenceResolver = (filter: Record<string, object>, fieldDefinition:
|
|
6
|
+
export declare type ReferenceResolver = (filter: Record<string, object>, fieldDefinition: ReferenceType) => Promise<{
|
|
7
7
|
edges: {
|
|
8
8
|
node: any;
|
|
9
9
|
}[];
|
|
10
10
|
values: any[];
|
|
11
11
|
}>;
|
|
12
|
-
export declare const resolveReferences: (filter: any, fields:
|
|
13
|
-
export declare const collectConditionsForField: (fieldName: string, field:
|
|
12
|
+
export declare const resolveReferences: (filter: any, fields: TinaField[], resolver: ReferenceResolver) => Promise<void>;
|
|
13
|
+
export declare const collectConditionsForField: (fieldName: string, field: TinaField, filterNode: Record<string, object>, pathExpression: string, collectCondition: (condition: FilterCondition) => void) => void;
|
package/dist/resolver/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
*/
|
|
4
4
|
import { Database } from '../database';
|
|
5
|
-
import type { Collectable,
|
|
5
|
+
import type { Collectable, Collection, TinaField, Template, TinaSchema } from '@tinacms/schema-tools';
|
|
6
6
|
import type { GraphQLConfig } from '../types';
|
|
7
7
|
interface ResolverConfig {
|
|
8
8
|
config?: GraphQLConfig;
|
|
@@ -23,47 +23,49 @@ export declare class Resolver {
|
|
|
23
23
|
isAudit: boolean;
|
|
24
24
|
constructor(init: ResolverConfig);
|
|
25
25
|
resolveCollection: (args: any, collectionName: string, hasDocuments?: boolean) => Promise<{
|
|
26
|
-
fields:
|
|
26
|
+
fields: TinaField<true>[];
|
|
27
27
|
templates?: undefined;
|
|
28
|
-
references?: ReferenceTypeWithNamespace[];
|
|
29
|
-
namespace: string[];
|
|
30
28
|
label?: string;
|
|
31
29
|
name: string;
|
|
32
30
|
path: string;
|
|
31
|
+
indexes?: {
|
|
32
|
+
name: string;
|
|
33
|
+
fields: {
|
|
34
|
+
name: string;
|
|
35
|
+
}[];
|
|
36
|
+
}[];
|
|
37
|
+
format?: "json" | "md" | "markdown" | "mdx" | "yaml" | "yml" | "toml";
|
|
38
|
+
ui?: import("@tinacms/schema-tools").UICollection;
|
|
33
39
|
defaultItem?: import("@tinacms/schema-tools").DefaultItem<Record<string, any>>;
|
|
34
|
-
indexes?: import("@tinacms/schema-tools").TinaIndex[];
|
|
35
|
-
format?: "json" | "md" | "markdown" | "mdx";
|
|
36
40
|
frontmatterFormat?: "json" | "yaml" | "toml";
|
|
37
41
|
frontmatterDelimiters?: string | [string, string];
|
|
38
|
-
ui?: import("@tinacms/schema-tools").UICollection;
|
|
39
42
|
match?: string;
|
|
43
|
+
namespace: string[];
|
|
40
44
|
documents: {
|
|
41
|
-
collection:
|
|
45
|
+
collection: Collection<true>;
|
|
42
46
|
hasDocuments: boolean;
|
|
43
47
|
};
|
|
44
48
|
} | {
|
|
45
|
-
templates:
|
|
46
|
-
label: string;
|
|
47
|
-
name: string;
|
|
48
|
-
ui?: import("@tinacms/schema-tools").UICollection;
|
|
49
|
-
fields: TinaFieldInner<true>[];
|
|
50
|
-
namespace: string[];
|
|
51
|
-
})[];
|
|
49
|
+
templates: Template<true>[];
|
|
52
50
|
fields?: undefined;
|
|
53
|
-
references?: ReferenceTypeWithNamespace[];
|
|
54
|
-
namespace: string[];
|
|
55
51
|
label?: string;
|
|
56
52
|
name: string;
|
|
57
53
|
path: string;
|
|
54
|
+
indexes?: {
|
|
55
|
+
name: string;
|
|
56
|
+
fields: {
|
|
57
|
+
name: string;
|
|
58
|
+
}[];
|
|
59
|
+
}[];
|
|
60
|
+
format?: "json" | "md" | "markdown" | "mdx" | "yaml" | "yml" | "toml";
|
|
61
|
+
ui?: import("@tinacms/schema-tools").UICollection;
|
|
58
62
|
defaultItem?: import("@tinacms/schema-tools").DefaultItem<Record<string, any>>;
|
|
59
|
-
indexes?: import("@tinacms/schema-tools").TinaIndex[];
|
|
60
|
-
format?: "json" | "md" | "markdown" | "mdx";
|
|
61
63
|
frontmatterFormat?: "json" | "yaml" | "toml";
|
|
62
64
|
frontmatterDelimiters?: string | [string, string];
|
|
63
|
-
ui?: import("@tinacms/schema-tools").UICollection;
|
|
64
65
|
match?: string;
|
|
66
|
+
namespace: string[];
|
|
65
67
|
documents: {
|
|
66
|
-
collection:
|
|
68
|
+
collection: Collection<true>;
|
|
67
69
|
hasDocuments: boolean;
|
|
68
70
|
};
|
|
69
71
|
}>;
|
|
@@ -76,7 +78,7 @@ export declare class Resolver {
|
|
|
76
78
|
path: string;
|
|
77
79
|
relativePath: string;
|
|
78
80
|
breadcrumbs: string[];
|
|
79
|
-
collection:
|
|
81
|
+
collection: Collection<true>;
|
|
80
82
|
template: string | number;
|
|
81
83
|
};
|
|
82
84
|
_values: {
|
|
@@ -99,7 +101,7 @@ export declare class Resolver {
|
|
|
99
101
|
[key: string]: unknown;
|
|
100
102
|
}[];
|
|
101
103
|
createResolveDocument: ({ collection, realPath, args, isAddPendingDocument, }: {
|
|
102
|
-
collection:
|
|
104
|
+
collection: Collection<true>;
|
|
103
105
|
realPath: string;
|
|
104
106
|
args: unknown;
|
|
105
107
|
isAddPendingDocument: boolean;
|
|
@@ -112,7 +114,7 @@ export declare class Resolver {
|
|
|
112
114
|
path: string;
|
|
113
115
|
relativePath: string;
|
|
114
116
|
breadcrumbs: string[];
|
|
115
|
-
collection:
|
|
117
|
+
collection: Collection<true>;
|
|
116
118
|
template: string | number;
|
|
117
119
|
};
|
|
118
120
|
_values: {
|
|
@@ -129,7 +131,7 @@ export declare class Resolver {
|
|
|
129
131
|
id: string;
|
|
130
132
|
}>;
|
|
131
133
|
updateResolveDocument: ({ collection, realPath, args, isAddPendingDocument, isCollectionSpecific, }: {
|
|
132
|
-
collection:
|
|
134
|
+
collection: Collection<true>;
|
|
133
135
|
realPath: string;
|
|
134
136
|
args: unknown;
|
|
135
137
|
isAddPendingDocument: boolean;
|
|
@@ -143,7 +145,7 @@ export declare class Resolver {
|
|
|
143
145
|
path: string;
|
|
144
146
|
relativePath: string;
|
|
145
147
|
breadcrumbs: string[];
|
|
146
|
-
collection:
|
|
148
|
+
collection: Collection<true>;
|
|
147
149
|
template: string | number;
|
|
148
150
|
};
|
|
149
151
|
_values: {
|
|
@@ -177,7 +179,7 @@ export declare class Resolver {
|
|
|
177
179
|
path: string;
|
|
178
180
|
relativePath: string;
|
|
179
181
|
breadcrumbs: string[];
|
|
180
|
-
collection:
|
|
182
|
+
collection: Collection<true>;
|
|
181
183
|
template: string | number;
|
|
182
184
|
};
|
|
183
185
|
_values: {
|
|
@@ -207,7 +209,7 @@ export declare class Resolver {
|
|
|
207
209
|
path: string;
|
|
208
210
|
relativePath: string;
|
|
209
211
|
breadcrumbs: string[];
|
|
210
|
-
collection:
|
|
212
|
+
collection: Collection<true>;
|
|
211
213
|
template: string | number;
|
|
212
214
|
};
|
|
213
215
|
_values: {
|
|
@@ -229,7 +231,7 @@ export declare class Resolver {
|
|
|
229
231
|
private resolveFilterConditions;
|
|
230
232
|
resolveCollectionConnection: ({ args, collection, hydrator, }: {
|
|
231
233
|
args: Record<string, Record<string, object> | string | number>;
|
|
232
|
-
collection:
|
|
234
|
+
collection: Collection<true>;
|
|
233
235
|
hydrator?: (string: any) => any;
|
|
234
236
|
}) => Promise<{
|
|
235
237
|
totalCount: number;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
*/
|
|
4
4
|
import type { GraphQLConfig } from '../types';
|
|
5
|
-
import type {
|
|
5
|
+
import type { Schema } from '@tinacms/schema-tools';
|
|
6
6
|
/**
|
|
7
7
|
* Strips away the Tina Cloud Asset URL from an `image` value
|
|
8
8
|
*
|
|
@@ -10,7 +10,7 @@ import type { TinaCloudSchemaEnriched } from '@tinacms/schema-tools';
|
|
|
10
10
|
* @param {GraphQLConfig} config
|
|
11
11
|
* @returns {string}
|
|
12
12
|
*/
|
|
13
|
-
export declare const resolveMediaCloudToRelative: (value: string, config: GraphQLConfig, schema:
|
|
13
|
+
export declare const resolveMediaCloudToRelative: (value: string, config: GraphQLConfig, schema: Schema<true>) => string;
|
|
14
14
|
/**
|
|
15
15
|
* Adds Tina Cloud Asset URL to an `image` value
|
|
16
16
|
*
|
|
@@ -18,4 +18,4 @@ export declare const resolveMediaCloudToRelative: (value: string, config: GraphQ
|
|
|
18
18
|
* @param {GraphQLConfig} config
|
|
19
19
|
* @returns {string}
|
|
20
20
|
*/
|
|
21
|
-
export declare const resolveMediaRelativeToCloud: (value: string, config: GraphQLConfig, schema:
|
|
21
|
+
export declare const resolveMediaRelativeToCloud: (value: string, config: GraphQLConfig, schema: Schema<true>) => string;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
|
|
3
3
|
*/
|
|
4
|
-
import { TinaSchema,
|
|
4
|
+
import { TinaSchema, Schema } from '@tinacms/schema-tools';
|
|
5
5
|
export declare const createSchema: ({ schema, flags, }: {
|
|
6
|
-
schema:
|
|
6
|
+
schema: Schema;
|
|
7
7
|
flags?: string[];
|
|
8
8
|
}) => Promise<TinaSchema>;
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
|
|
3
3
|
*/
|
|
4
|
-
import {
|
|
5
|
-
export declare const validateSchema: (schema:
|
|
4
|
+
import { Schema, Collection } from '@tinacms/schema-tools';
|
|
5
|
+
export declare const validateSchema: (schema: Schema) => Promise<{
|
|
6
|
+
collections: Collection<true>[];
|
|
7
|
+
config: import("@tinacms/schema-tools").Config<undefined, undefined, undefined, undefined>;
|
|
8
|
+
} | {
|
|
9
|
+
collections: Collection<true>[];
|
|
10
|
+
config?: undefined;
|
|
11
|
+
}>;
|