@tinacms/graphql 1.4.1 → 1.4.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/database/index.d.ts +1 -0
- package/dist/index.es.js +74 -27
- package/dist/index.js +75 -28
- package/dist/level/tinaLevel.d.ts +2 -0
- package/package.json +7 -7
package/dist/database/index.d.ts
CHANGED
package/dist/index.es.js
CHANGED
|
@@ -2491,7 +2491,7 @@ var validateField = async (field) => {
|
|
|
2491
2491
|
// package.json
|
|
2492
2492
|
var package_default = {
|
|
2493
2493
|
name: "@tinacms/graphql",
|
|
2494
|
-
version: "1.4.
|
|
2494
|
+
version: "1.4.3",
|
|
2495
2495
|
main: "dist/index.js",
|
|
2496
2496
|
module: "dist/index.es.js",
|
|
2497
2497
|
typings: "dist/index.d.ts",
|
|
@@ -4494,9 +4494,30 @@ var parseFile = (content, format, yupSchema, markdownParseConfig) => {
|
|
|
4494
4494
|
};
|
|
4495
4495
|
|
|
4496
4496
|
// src/database/alias-utils.ts
|
|
4497
|
+
var replaceBlockAliases = (template, item) => {
|
|
4498
|
+
const output = { ...item };
|
|
4499
|
+
const templateKey = template.templateKey || "_template";
|
|
4500
|
+
const templateName = output[templateKey];
|
|
4501
|
+
const matchingTemplate = template.templates.find(
|
|
4502
|
+
(t) => t.nameOverride == templateName || t.name == templateName
|
|
4503
|
+
);
|
|
4504
|
+
if (!matchingTemplate) {
|
|
4505
|
+
throw new Error(
|
|
4506
|
+
`Block template "${templateName}" is not defined for field "${template.name}"`
|
|
4507
|
+
);
|
|
4508
|
+
}
|
|
4509
|
+
output._template = matchingTemplate.name;
|
|
4510
|
+
if (templateKey != "_template") {
|
|
4511
|
+
delete output[templateKey];
|
|
4512
|
+
}
|
|
4513
|
+
return output;
|
|
4514
|
+
};
|
|
4497
4515
|
var replaceNameOverrides = (template, obj) => {
|
|
4498
4516
|
if (template.list) {
|
|
4499
4517
|
return obj.map((item) => {
|
|
4518
|
+
if (isBlockField(template)) {
|
|
4519
|
+
item = replaceBlockAliases(template, item);
|
|
4520
|
+
}
|
|
4500
4521
|
return _replaceNameOverrides(
|
|
4501
4522
|
getTemplateForData(template, item).fields,
|
|
4502
4523
|
item
|
|
@@ -4506,6 +4527,9 @@ var replaceNameOverrides = (template, obj) => {
|
|
|
4506
4527
|
return _replaceNameOverrides(getTemplateForData(template, obj).fields, obj);
|
|
4507
4528
|
}
|
|
4508
4529
|
};
|
|
4530
|
+
function isBlockField(field) {
|
|
4531
|
+
return field && field.type === "object" && field.templates?.length > 0;
|
|
4532
|
+
}
|
|
4509
4533
|
var _replaceNameOverrides = (fields, obj) => {
|
|
4510
4534
|
const output = {};
|
|
4511
4535
|
Object.keys(obj).forEach((key) => {
|
|
@@ -4516,36 +4540,56 @@ var _replaceNameOverrides = (fields, obj) => {
|
|
|
4516
4540
|
});
|
|
4517
4541
|
return output;
|
|
4518
4542
|
};
|
|
4519
|
-
var getTemplateKey = (field) => {
|
|
4520
|
-
const DEFAULT_TEMPLATE_KEY = "_template";
|
|
4521
|
-
if (field.templates?.length) {
|
|
4522
|
-
const templateField = field.templates[0]?.fields?.find(
|
|
4523
|
-
(field2) => field2.name === DEFAULT_TEMPLATE_KEY
|
|
4524
|
-
);
|
|
4525
|
-
return templateField?.alias || DEFAULT_TEMPLATE_KEY;
|
|
4526
|
-
}
|
|
4527
|
-
return DEFAULT_TEMPLATE_KEY;
|
|
4528
|
-
};
|
|
4529
4543
|
var getTemplateForData = (field, data) => {
|
|
4530
4544
|
if (field.templates?.length) {
|
|
4531
|
-
const templateKey =
|
|
4545
|
+
const templateKey = "_template";
|
|
4532
4546
|
if (data[templateKey]) {
|
|
4533
|
-
|
|
4534
|
-
(template) => template.name === data[templateKey]
|
|
4547
|
+
const result = field.templates.find(
|
|
4548
|
+
(template) => template.nameOverride === data[templateKey] || template.name === data[templateKey]
|
|
4549
|
+
);
|
|
4550
|
+
if (result) {
|
|
4551
|
+
return result;
|
|
4552
|
+
}
|
|
4553
|
+
throw new Error(
|
|
4554
|
+
`Template "${data[templateKey]}" is not defined for field "${field.name}"`
|
|
4535
4555
|
);
|
|
4536
4556
|
}
|
|
4557
|
+
throw new Error(
|
|
4558
|
+
`Missing required key "${templateKey}" on field "${field.name}"`
|
|
4559
|
+
);
|
|
4537
4560
|
} else {
|
|
4538
4561
|
return field;
|
|
4539
4562
|
}
|
|
4540
|
-
|
|
4563
|
+
};
|
|
4564
|
+
var applyBlockAliases = (template, item) => {
|
|
4565
|
+
const output = { ...item };
|
|
4566
|
+
const templateKey = template.templateKey || "_template";
|
|
4567
|
+
const templateName = output._template;
|
|
4568
|
+
const matchingTemplate = template.templates.find(
|
|
4569
|
+
(t) => t.nameOverride == templateName || t.name == templateName
|
|
4570
|
+
);
|
|
4571
|
+
if (!matchingTemplate) {
|
|
4572
|
+
throw new Error(
|
|
4573
|
+
`Block template "${templateName}" is not defined for field "${template.name}"`
|
|
4574
|
+
);
|
|
4575
|
+
}
|
|
4576
|
+
output[templateKey] = matchingTemplate.nameOverride || matchingTemplate.name;
|
|
4577
|
+
if (templateKey != "_template") {
|
|
4578
|
+
delete output._template;
|
|
4579
|
+
}
|
|
4580
|
+
return output;
|
|
4541
4581
|
};
|
|
4542
4582
|
var applyNameOverrides = (template, obj) => {
|
|
4543
4583
|
if (template.list) {
|
|
4544
4584
|
return obj.map((item) => {
|
|
4545
|
-
|
|
4585
|
+
let result = _applyNameOverrides(
|
|
4546
4586
|
getTemplateForData(template, item).fields,
|
|
4547
4587
|
item
|
|
4548
4588
|
);
|
|
4589
|
+
if (isBlockField(template)) {
|
|
4590
|
+
result = applyBlockAliases(template, result);
|
|
4591
|
+
}
|
|
4592
|
+
return result;
|
|
4549
4593
|
});
|
|
4550
4594
|
} else {
|
|
4551
4595
|
return _applyNameOverrides(getTemplateForData(template, obj).fields, obj);
|
|
@@ -5218,7 +5262,7 @@ var Database = class {
|
|
|
5218
5262
|
`"${path4}" Found in multiple collections: ${filesSeen.get(path4).map((collection2) => `"${collection2}"`).join(
|
|
5219
5263
|
", "
|
|
5220
5264
|
)}. This can cause unexpected behavior. We recommend updating the \`match\` property of those collections so that each file is in only one collection.
|
|
5221
|
-
This will be an error in the future.
|
|
5265
|
+
This will be an error in the future. See https://tina.io/docs/errors/file-in-mutpliple-collections/
|
|
5222
5266
|
`
|
|
5223
5267
|
);
|
|
5224
5268
|
});
|
|
@@ -5372,11 +5416,15 @@ var _indexContent = async (database, level, documentPaths, enqueueOps, collectio
|
|
|
5372
5416
|
frontmatterFormat: collection?.frontmatterFormat
|
|
5373
5417
|
}
|
|
5374
5418
|
);
|
|
5419
|
+
const template = getTemplateForFile(templateInfo, data);
|
|
5420
|
+
if (!template) {
|
|
5421
|
+
console.warn(
|
|
5422
|
+
`Document: ${filepath} has an ambiguous template, skipping from indexing`
|
|
5423
|
+
);
|
|
5424
|
+
return;
|
|
5425
|
+
}
|
|
5375
5426
|
const normalizedPath = normalizePath(filepath);
|
|
5376
|
-
const aliasedData = templateInfo ? replaceNameOverrides(
|
|
5377
|
-
getTemplateForFile(templateInfo, data),
|
|
5378
|
-
data
|
|
5379
|
-
) : data;
|
|
5427
|
+
const aliasedData = templateInfo ? replaceNameOverrides(template, data) : data;
|
|
5380
5428
|
await enqueueOps([
|
|
5381
5429
|
...makeIndexOpsForDocument(
|
|
5382
5430
|
normalizedPath,
|
|
@@ -5453,9 +5501,7 @@ var getTemplateForFile = (templateInfo, data) => {
|
|
|
5453
5501
|
}
|
|
5454
5502
|
return template;
|
|
5455
5503
|
} else {
|
|
5456
|
-
|
|
5457
|
-
`Expected _template to be provided for document in an ambiguous collection`
|
|
5458
|
-
);
|
|
5504
|
+
return void 0;
|
|
5459
5505
|
}
|
|
5460
5506
|
}
|
|
5461
5507
|
throw new Error(`Unable to determine template`);
|
|
@@ -5466,14 +5512,15 @@ import { ManyLevelGuest } from "many-level";
|
|
|
5466
5512
|
import { pipeline } from "readable-stream";
|
|
5467
5513
|
import { connect } from "net";
|
|
5468
5514
|
var TinaLevelClient = class extends ManyLevelGuest {
|
|
5469
|
-
constructor() {
|
|
5470
|
-
super(
|
|
5515
|
+
constructor(port) {
|
|
5516
|
+
super();
|
|
5471
5517
|
this._connected = false;
|
|
5518
|
+
this.port = port || 9e3;
|
|
5472
5519
|
}
|
|
5473
5520
|
openConnection() {
|
|
5474
5521
|
if (this._connected)
|
|
5475
5522
|
return;
|
|
5476
|
-
const socket = connect(
|
|
5523
|
+
const socket = connect(this.port);
|
|
5477
5524
|
pipeline(socket, this.createRpcStream(), socket, () => {
|
|
5478
5525
|
this._connected = false;
|
|
5479
5526
|
});
|
package/dist/index.js
CHANGED
|
@@ -2542,7 +2542,7 @@ var validateField = async (field) => {
|
|
|
2542
2542
|
// package.json
|
|
2543
2543
|
var package_default = {
|
|
2544
2544
|
name: "@tinacms/graphql",
|
|
2545
|
-
version: "1.4.
|
|
2545
|
+
version: "1.4.3",
|
|
2546
2546
|
main: "dist/index.js",
|
|
2547
2547
|
module: "dist/index.es.js",
|
|
2548
2548
|
typings: "dist/index.d.ts",
|
|
@@ -4545,9 +4545,30 @@ var parseFile = (content, format, yupSchema, markdownParseConfig) => {
|
|
|
4545
4545
|
};
|
|
4546
4546
|
|
|
4547
4547
|
// src/database/alias-utils.ts
|
|
4548
|
+
var replaceBlockAliases = (template, item) => {
|
|
4549
|
+
const output = { ...item };
|
|
4550
|
+
const templateKey = template.templateKey || "_template";
|
|
4551
|
+
const templateName = output[templateKey];
|
|
4552
|
+
const matchingTemplate = template.templates.find(
|
|
4553
|
+
(t) => t.nameOverride == templateName || t.name == templateName
|
|
4554
|
+
);
|
|
4555
|
+
if (!matchingTemplate) {
|
|
4556
|
+
throw new Error(
|
|
4557
|
+
`Block template "${templateName}" is not defined for field "${template.name}"`
|
|
4558
|
+
);
|
|
4559
|
+
}
|
|
4560
|
+
output._template = matchingTemplate.name;
|
|
4561
|
+
if (templateKey != "_template") {
|
|
4562
|
+
delete output[templateKey];
|
|
4563
|
+
}
|
|
4564
|
+
return output;
|
|
4565
|
+
};
|
|
4548
4566
|
var replaceNameOverrides = (template, obj) => {
|
|
4549
4567
|
if (template.list) {
|
|
4550
4568
|
return obj.map((item) => {
|
|
4569
|
+
if (isBlockField(template)) {
|
|
4570
|
+
item = replaceBlockAliases(template, item);
|
|
4571
|
+
}
|
|
4551
4572
|
return _replaceNameOverrides(
|
|
4552
4573
|
getTemplateForData(template, item).fields,
|
|
4553
4574
|
item
|
|
@@ -4557,6 +4578,10 @@ var replaceNameOverrides = (template, obj) => {
|
|
|
4557
4578
|
return _replaceNameOverrides(getTemplateForData(template, obj).fields, obj);
|
|
4558
4579
|
}
|
|
4559
4580
|
};
|
|
4581
|
+
function isBlockField(field) {
|
|
4582
|
+
var _a;
|
|
4583
|
+
return field && field.type === "object" && ((_a = field.templates) == null ? void 0 : _a.length) > 0;
|
|
4584
|
+
}
|
|
4560
4585
|
var _replaceNameOverrides = (fields, obj) => {
|
|
4561
4586
|
const output = {};
|
|
4562
4587
|
Object.keys(obj).forEach((key) => {
|
|
@@ -4567,38 +4592,57 @@ var _replaceNameOverrides = (fields, obj) => {
|
|
|
4567
4592
|
});
|
|
4568
4593
|
return output;
|
|
4569
4594
|
};
|
|
4570
|
-
var getTemplateKey = (field) => {
|
|
4571
|
-
var _a, _b, _c;
|
|
4572
|
-
const DEFAULT_TEMPLATE_KEY = "_template";
|
|
4573
|
-
if ((_a = field.templates) == null ? void 0 : _a.length) {
|
|
4574
|
-
const templateField = (_c = (_b = field.templates[0]) == null ? void 0 : _b.fields) == null ? void 0 : _c.find(
|
|
4575
|
-
(field2) => field2.name === DEFAULT_TEMPLATE_KEY
|
|
4576
|
-
);
|
|
4577
|
-
return (templateField == null ? void 0 : templateField.alias) || DEFAULT_TEMPLATE_KEY;
|
|
4578
|
-
}
|
|
4579
|
-
return DEFAULT_TEMPLATE_KEY;
|
|
4580
|
-
};
|
|
4581
4595
|
var getTemplateForData = (field, data) => {
|
|
4582
4596
|
var _a;
|
|
4583
4597
|
if ((_a = field.templates) == null ? void 0 : _a.length) {
|
|
4584
|
-
const templateKey =
|
|
4598
|
+
const templateKey = "_template";
|
|
4585
4599
|
if (data[templateKey]) {
|
|
4586
|
-
|
|
4587
|
-
(template) => template.name === data[templateKey]
|
|
4600
|
+
const result = field.templates.find(
|
|
4601
|
+
(template) => template.nameOverride === data[templateKey] || template.name === data[templateKey]
|
|
4602
|
+
);
|
|
4603
|
+
if (result) {
|
|
4604
|
+
return result;
|
|
4605
|
+
}
|
|
4606
|
+
throw new Error(
|
|
4607
|
+
`Template "${data[templateKey]}" is not defined for field "${field.name}"`
|
|
4588
4608
|
);
|
|
4589
4609
|
}
|
|
4610
|
+
throw new Error(
|
|
4611
|
+
`Missing required key "${templateKey}" on field "${field.name}"`
|
|
4612
|
+
);
|
|
4590
4613
|
} else {
|
|
4591
4614
|
return field;
|
|
4592
4615
|
}
|
|
4593
|
-
|
|
4616
|
+
};
|
|
4617
|
+
var applyBlockAliases = (template, item) => {
|
|
4618
|
+
const output = { ...item };
|
|
4619
|
+
const templateKey = template.templateKey || "_template";
|
|
4620
|
+
const templateName = output._template;
|
|
4621
|
+
const matchingTemplate = template.templates.find(
|
|
4622
|
+
(t) => t.nameOverride == templateName || t.name == templateName
|
|
4623
|
+
);
|
|
4624
|
+
if (!matchingTemplate) {
|
|
4625
|
+
throw new Error(
|
|
4626
|
+
`Block template "${templateName}" is not defined for field "${template.name}"`
|
|
4627
|
+
);
|
|
4628
|
+
}
|
|
4629
|
+
output[templateKey] = matchingTemplate.nameOverride || matchingTemplate.name;
|
|
4630
|
+
if (templateKey != "_template") {
|
|
4631
|
+
delete output._template;
|
|
4632
|
+
}
|
|
4633
|
+
return output;
|
|
4594
4634
|
};
|
|
4595
4635
|
var applyNameOverrides = (template, obj) => {
|
|
4596
4636
|
if (template.list) {
|
|
4597
4637
|
return obj.map((item) => {
|
|
4598
|
-
|
|
4638
|
+
let result = _applyNameOverrides(
|
|
4599
4639
|
getTemplateForData(template, item).fields,
|
|
4600
4640
|
item
|
|
4601
4641
|
);
|
|
4642
|
+
if (isBlockField(template)) {
|
|
4643
|
+
result = applyBlockAliases(template, result);
|
|
4644
|
+
}
|
|
4645
|
+
return result;
|
|
4602
4646
|
});
|
|
4603
4647
|
} else {
|
|
4604
4648
|
return _applyNameOverrides(getTemplateForData(template, obj).fields, obj);
|
|
@@ -5276,7 +5320,7 @@ var Database = class {
|
|
|
5276
5320
|
`"${path4}" Found in multiple collections: ${filesSeen.get(path4).map((collection2) => `"${collection2}"`).join(
|
|
5277
5321
|
", "
|
|
5278
5322
|
)}. This can cause unexpected behavior. We recommend updating the \`match\` property of those collections so that each file is in only one collection.
|
|
5279
|
-
This will be an error in the future.
|
|
5323
|
+
This will be an error in the future. See https://tina.io/docs/errors/file-in-mutpliple-collections/
|
|
5280
5324
|
`
|
|
5281
5325
|
);
|
|
5282
5326
|
});
|
|
@@ -5430,11 +5474,15 @@ var _indexContent = async (database, level, documentPaths, enqueueOps, collectio
|
|
|
5430
5474
|
frontmatterFormat: collection == null ? void 0 : collection.frontmatterFormat
|
|
5431
5475
|
}
|
|
5432
5476
|
);
|
|
5477
|
+
const template = getTemplateForFile(templateInfo, data);
|
|
5478
|
+
if (!template) {
|
|
5479
|
+
console.warn(
|
|
5480
|
+
`Document: ${filepath} has an ambiguous template, skipping from indexing`
|
|
5481
|
+
);
|
|
5482
|
+
return;
|
|
5483
|
+
}
|
|
5433
5484
|
const normalizedPath = (0, import_schema_tools3.normalizePath)(filepath);
|
|
5434
|
-
const aliasedData = templateInfo ? replaceNameOverrides(
|
|
5435
|
-
getTemplateForFile(templateInfo, data),
|
|
5436
|
-
data
|
|
5437
|
-
) : data;
|
|
5485
|
+
const aliasedData = templateInfo ? replaceNameOverrides(template, data) : data;
|
|
5438
5486
|
await enqueueOps([
|
|
5439
5487
|
...makeIndexOpsForDocument(
|
|
5440
5488
|
normalizedPath,
|
|
@@ -5511,9 +5559,7 @@ var getTemplateForFile = (templateInfo, data) => {
|
|
|
5511
5559
|
}
|
|
5512
5560
|
return template;
|
|
5513
5561
|
} else {
|
|
5514
|
-
|
|
5515
|
-
`Expected _template to be provided for document in an ambiguous collection`
|
|
5516
|
-
);
|
|
5562
|
+
return void 0;
|
|
5517
5563
|
}
|
|
5518
5564
|
}
|
|
5519
5565
|
throw new Error(`Unable to determine template`);
|
|
@@ -5524,14 +5570,15 @@ var import_many_level = require("many-level");
|
|
|
5524
5570
|
var import_readable_stream = require("readable-stream");
|
|
5525
5571
|
var import_net = require("net");
|
|
5526
5572
|
var TinaLevelClient = class extends import_many_level.ManyLevelGuest {
|
|
5527
|
-
constructor() {
|
|
5528
|
-
super(
|
|
5573
|
+
constructor(port) {
|
|
5574
|
+
super();
|
|
5529
5575
|
this._connected = false;
|
|
5576
|
+
this.port = port || 9e3;
|
|
5530
5577
|
}
|
|
5531
5578
|
openConnection() {
|
|
5532
5579
|
if (this._connected)
|
|
5533
5580
|
return;
|
|
5534
|
-
const socket = (0, import_net.connect)(
|
|
5581
|
+
const socket = (0, import_net.connect)(this.port);
|
|
5535
5582
|
(0, import_readable_stream.pipeline)(socket, this.createRpcStream(), socket, () => {
|
|
5536
5583
|
this._connected = false;
|
|
5537
5584
|
});
|
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { ManyLevelGuest } from 'many-level';
|
|
5
5
|
export declare class TinaLevelClient extends ManyLevelGuest<string, Record<string, any>> {
|
|
6
|
+
private port;
|
|
6
7
|
private _connected;
|
|
8
|
+
constructor(port?: number);
|
|
7
9
|
openConnection(): void;
|
|
8
10
|
}
|
|
9
11
|
export interface Bridge {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tinacms/graphql",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.3",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"module": "dist/index.es.js",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
@@ -25,8 +25,6 @@
|
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"@graphql-tools/relay-operation-optimizer": "^6.4.1",
|
|
27
27
|
"@iarna/toml": "^2.2.5",
|
|
28
|
-
"@tinacms/mdx": "1.3.6",
|
|
29
|
-
"@tinacms/schema-tools": "1.4.1",
|
|
30
28
|
"abstract-level": "^1.0.3",
|
|
31
29
|
"body-parser": "^1.19.0",
|
|
32
30
|
"cors": "^2.8.5",
|
|
@@ -73,7 +71,9 @@
|
|
|
73
71
|
"unist-util-visit": "^4.0.0",
|
|
74
72
|
"vfile": "^4.2.0",
|
|
75
73
|
"ws": "^7.3.1",
|
|
76
|
-
"yup": "^0.32.9"
|
|
74
|
+
"yup": "^0.32.9",
|
|
75
|
+
"@tinacms/mdx": "1.3.7",
|
|
76
|
+
"@tinacms/schema-tools": "1.4.2"
|
|
77
77
|
},
|
|
78
78
|
"publishConfig": {
|
|
79
79
|
"registry": "https://registry.npmjs.org"
|
|
@@ -83,8 +83,6 @@
|
|
|
83
83
|
"directory": "packages/tina-graphql"
|
|
84
84
|
},
|
|
85
85
|
"devDependencies": {
|
|
86
|
-
"@tinacms/schema-tools": "1.4.1",
|
|
87
|
-
"@tinacms/scripts": "1.1.0",
|
|
88
86
|
"@types/cors": "^2.8.7",
|
|
89
87
|
"@types/estree": "^0.0.50",
|
|
90
88
|
"@types/express": "^4.17.8",
|
|
@@ -107,7 +105,9 @@
|
|
|
107
105
|
"jest-matcher-utils": "27.0.6",
|
|
108
106
|
"memory-level": "^1.0.0",
|
|
109
107
|
"nodemon": "2.0.19",
|
|
110
|
-
"typescript": "4.3.5"
|
|
108
|
+
"typescript": "4.3.5",
|
|
109
|
+
"@tinacms/schema-tools": "1.4.2",
|
|
110
|
+
"@tinacms/scripts": "1.1.0"
|
|
111
111
|
},
|
|
112
112
|
"scripts": {
|
|
113
113
|
"types": "pnpm tsc",
|