@tinacms/graphql 1.4.1 → 1.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.es.js +31 -24
- package/dist/index.js +32 -25
- package/dist/level/tinaLevel.d.ts +2 -0
- package/package.json +4 -4
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.2",
|
|
2495
2495
|
main: "dist/index.js",
|
|
2496
2496
|
module: "dist/index.es.js",
|
|
2497
2497
|
typings: "dist/index.d.ts",
|
|
@@ -4497,6 +4497,10 @@ var parseFile = (content, format, yupSchema, markdownParseConfig) => {
|
|
|
4497
4497
|
var replaceNameOverrides = (template, obj) => {
|
|
4498
4498
|
if (template.list) {
|
|
4499
4499
|
return obj.map((item) => {
|
|
4500
|
+
if (isBlockField(template) && template.templateKey) {
|
|
4501
|
+
item._template = item[template.templateKey];
|
|
4502
|
+
delete item[template.templateKey];
|
|
4503
|
+
}
|
|
4500
4504
|
return _replaceNameOverrides(
|
|
4501
4505
|
getTemplateForData(template, item).fields,
|
|
4502
4506
|
item
|
|
@@ -4506,6 +4510,9 @@ var replaceNameOverrides = (template, obj) => {
|
|
|
4506
4510
|
return _replaceNameOverrides(getTemplateForData(template, obj).fields, obj);
|
|
4507
4511
|
}
|
|
4508
4512
|
};
|
|
4513
|
+
function isBlockField(field) {
|
|
4514
|
+
return field && field.type === "object" && field.templates?.length > 0;
|
|
4515
|
+
}
|
|
4509
4516
|
var _replaceNameOverrides = (fields, obj) => {
|
|
4510
4517
|
const output = {};
|
|
4511
4518
|
Object.keys(obj).forEach((key) => {
|
|
@@ -4516,36 +4523,33 @@ var _replaceNameOverrides = (fields, obj) => {
|
|
|
4516
4523
|
});
|
|
4517
4524
|
return output;
|
|
4518
4525
|
};
|
|
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
4526
|
var getTemplateForData = (field, data) => {
|
|
4530
4527
|
if (field.templates?.length) {
|
|
4531
|
-
const templateKey =
|
|
4528
|
+
const templateKey = "_template";
|
|
4532
4529
|
if (data[templateKey]) {
|
|
4533
4530
|
return field.templates.find(
|
|
4534
4531
|
(template) => template.name === data[templateKey]
|
|
4535
4532
|
);
|
|
4536
4533
|
}
|
|
4534
|
+
throw new Error(
|
|
4535
|
+
`Missing required key "${templateKey}" on field ${field.name}`
|
|
4536
|
+
);
|
|
4537
4537
|
} else {
|
|
4538
4538
|
return field;
|
|
4539
4539
|
}
|
|
4540
|
-
throw new Error("No template found for field " + field.name);
|
|
4541
4540
|
};
|
|
4542
4541
|
var applyNameOverrides = (template, obj) => {
|
|
4543
4542
|
if (template.list) {
|
|
4544
4543
|
return obj.map((item) => {
|
|
4545
|
-
|
|
4544
|
+
const result = _applyNameOverrides(
|
|
4546
4545
|
getTemplateForData(template, item).fields,
|
|
4547
4546
|
item
|
|
4548
4547
|
);
|
|
4548
|
+
if (isBlockField(template) && template.templateKey) {
|
|
4549
|
+
result[template.templateKey] = result._template;
|
|
4550
|
+
delete result._template;
|
|
4551
|
+
}
|
|
4552
|
+
return result;
|
|
4549
4553
|
});
|
|
4550
4554
|
} else {
|
|
4551
4555
|
return _applyNameOverrides(getTemplateForData(template, obj).fields, obj);
|
|
@@ -5372,11 +5376,15 @@ var _indexContent = async (database, level, documentPaths, enqueueOps, collectio
|
|
|
5372
5376
|
frontmatterFormat: collection?.frontmatterFormat
|
|
5373
5377
|
}
|
|
5374
5378
|
);
|
|
5379
|
+
const template = getTemplateForFile(templateInfo, data);
|
|
5380
|
+
if (!template) {
|
|
5381
|
+
console.warn(
|
|
5382
|
+
`Document: ${filepath} has an ambiguous template, skipping from indexing`
|
|
5383
|
+
);
|
|
5384
|
+
return;
|
|
5385
|
+
}
|
|
5375
5386
|
const normalizedPath = normalizePath(filepath);
|
|
5376
|
-
const aliasedData = templateInfo ? replaceNameOverrides(
|
|
5377
|
-
getTemplateForFile(templateInfo, data),
|
|
5378
|
-
data
|
|
5379
|
-
) : data;
|
|
5387
|
+
const aliasedData = templateInfo ? replaceNameOverrides(template, data) : data;
|
|
5380
5388
|
await enqueueOps([
|
|
5381
5389
|
...makeIndexOpsForDocument(
|
|
5382
5390
|
normalizedPath,
|
|
@@ -5453,9 +5461,7 @@ var getTemplateForFile = (templateInfo, data) => {
|
|
|
5453
5461
|
}
|
|
5454
5462
|
return template;
|
|
5455
5463
|
} else {
|
|
5456
|
-
|
|
5457
|
-
`Expected _template to be provided for document in an ambiguous collection`
|
|
5458
|
-
);
|
|
5464
|
+
return void 0;
|
|
5459
5465
|
}
|
|
5460
5466
|
}
|
|
5461
5467
|
throw new Error(`Unable to determine template`);
|
|
@@ -5466,14 +5472,15 @@ import { ManyLevelGuest } from "many-level";
|
|
|
5466
5472
|
import { pipeline } from "readable-stream";
|
|
5467
5473
|
import { connect } from "net";
|
|
5468
5474
|
var TinaLevelClient = class extends ManyLevelGuest {
|
|
5469
|
-
constructor() {
|
|
5470
|
-
super(
|
|
5475
|
+
constructor(port) {
|
|
5476
|
+
super();
|
|
5471
5477
|
this._connected = false;
|
|
5478
|
+
this.port = port || 9e3;
|
|
5472
5479
|
}
|
|
5473
5480
|
openConnection() {
|
|
5474
5481
|
if (this._connected)
|
|
5475
5482
|
return;
|
|
5476
|
-
const socket = connect(
|
|
5483
|
+
const socket = connect(this.port);
|
|
5477
5484
|
pipeline(socket, this.createRpcStream(), socket, () => {
|
|
5478
5485
|
this._connected = false;
|
|
5479
5486
|
});
|
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.2",
|
|
2546
2546
|
main: "dist/index.js",
|
|
2547
2547
|
module: "dist/index.es.js",
|
|
2548
2548
|
typings: "dist/index.d.ts",
|
|
@@ -4548,6 +4548,10 @@ var parseFile = (content, format, yupSchema, markdownParseConfig) => {
|
|
|
4548
4548
|
var replaceNameOverrides = (template, obj) => {
|
|
4549
4549
|
if (template.list) {
|
|
4550
4550
|
return obj.map((item) => {
|
|
4551
|
+
if (isBlockField(template) && template.templateKey) {
|
|
4552
|
+
item._template = item[template.templateKey];
|
|
4553
|
+
delete item[template.templateKey];
|
|
4554
|
+
}
|
|
4551
4555
|
return _replaceNameOverrides(
|
|
4552
4556
|
getTemplateForData(template, item).fields,
|
|
4553
4557
|
item
|
|
@@ -4557,6 +4561,10 @@ var replaceNameOverrides = (template, obj) => {
|
|
|
4557
4561
|
return _replaceNameOverrides(getTemplateForData(template, obj).fields, obj);
|
|
4558
4562
|
}
|
|
4559
4563
|
};
|
|
4564
|
+
function isBlockField(field) {
|
|
4565
|
+
var _a;
|
|
4566
|
+
return field && field.type === "object" && ((_a = field.templates) == null ? void 0 : _a.length) > 0;
|
|
4567
|
+
}
|
|
4560
4568
|
var _replaceNameOverrides = (fields, obj) => {
|
|
4561
4569
|
const output = {};
|
|
4562
4570
|
Object.keys(obj).forEach((key) => {
|
|
@@ -4567,38 +4575,34 @@ var _replaceNameOverrides = (fields, obj) => {
|
|
|
4567
4575
|
});
|
|
4568
4576
|
return output;
|
|
4569
4577
|
};
|
|
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
4578
|
var getTemplateForData = (field, data) => {
|
|
4582
4579
|
var _a;
|
|
4583
4580
|
if ((_a = field.templates) == null ? void 0 : _a.length) {
|
|
4584
|
-
const templateKey =
|
|
4581
|
+
const templateKey = "_template";
|
|
4585
4582
|
if (data[templateKey]) {
|
|
4586
4583
|
return field.templates.find(
|
|
4587
4584
|
(template) => template.name === data[templateKey]
|
|
4588
4585
|
);
|
|
4589
4586
|
}
|
|
4587
|
+
throw new Error(
|
|
4588
|
+
`Missing required key "${templateKey}" on field ${field.name}`
|
|
4589
|
+
);
|
|
4590
4590
|
} else {
|
|
4591
4591
|
return field;
|
|
4592
4592
|
}
|
|
4593
|
-
throw new Error("No template found for field " + field.name);
|
|
4594
4593
|
};
|
|
4595
4594
|
var applyNameOverrides = (template, obj) => {
|
|
4596
4595
|
if (template.list) {
|
|
4597
4596
|
return obj.map((item) => {
|
|
4598
|
-
|
|
4597
|
+
const result = _applyNameOverrides(
|
|
4599
4598
|
getTemplateForData(template, item).fields,
|
|
4600
4599
|
item
|
|
4601
4600
|
);
|
|
4601
|
+
if (isBlockField(template) && template.templateKey) {
|
|
4602
|
+
result[template.templateKey] = result._template;
|
|
4603
|
+
delete result._template;
|
|
4604
|
+
}
|
|
4605
|
+
return result;
|
|
4602
4606
|
});
|
|
4603
4607
|
} else {
|
|
4604
4608
|
return _applyNameOverrides(getTemplateForData(template, obj).fields, obj);
|
|
@@ -5430,11 +5434,15 @@ var _indexContent = async (database, level, documentPaths, enqueueOps, collectio
|
|
|
5430
5434
|
frontmatterFormat: collection == null ? void 0 : collection.frontmatterFormat
|
|
5431
5435
|
}
|
|
5432
5436
|
);
|
|
5437
|
+
const template = getTemplateForFile(templateInfo, data);
|
|
5438
|
+
if (!template) {
|
|
5439
|
+
console.warn(
|
|
5440
|
+
`Document: ${filepath} has an ambiguous template, skipping from indexing`
|
|
5441
|
+
);
|
|
5442
|
+
return;
|
|
5443
|
+
}
|
|
5433
5444
|
const normalizedPath = (0, import_schema_tools3.normalizePath)(filepath);
|
|
5434
|
-
const aliasedData = templateInfo ? replaceNameOverrides(
|
|
5435
|
-
getTemplateForFile(templateInfo, data),
|
|
5436
|
-
data
|
|
5437
|
-
) : data;
|
|
5445
|
+
const aliasedData = templateInfo ? replaceNameOverrides(template, data) : data;
|
|
5438
5446
|
await enqueueOps([
|
|
5439
5447
|
...makeIndexOpsForDocument(
|
|
5440
5448
|
normalizedPath,
|
|
@@ -5511,9 +5519,7 @@ var getTemplateForFile = (templateInfo, data) => {
|
|
|
5511
5519
|
}
|
|
5512
5520
|
return template;
|
|
5513
5521
|
} else {
|
|
5514
|
-
|
|
5515
|
-
`Expected _template to be provided for document in an ambiguous collection`
|
|
5516
|
-
);
|
|
5522
|
+
return void 0;
|
|
5517
5523
|
}
|
|
5518
5524
|
}
|
|
5519
5525
|
throw new Error(`Unable to determine template`);
|
|
@@ -5524,14 +5530,15 @@ var import_many_level = require("many-level");
|
|
|
5524
5530
|
var import_readable_stream = require("readable-stream");
|
|
5525
5531
|
var import_net = require("net");
|
|
5526
5532
|
var TinaLevelClient = class extends import_many_level.ManyLevelGuest {
|
|
5527
|
-
constructor() {
|
|
5528
|
-
super(
|
|
5533
|
+
constructor(port) {
|
|
5534
|
+
super();
|
|
5529
5535
|
this._connected = false;
|
|
5536
|
+
this.port = port || 9e3;
|
|
5530
5537
|
}
|
|
5531
5538
|
openConnection() {
|
|
5532
5539
|
if (this._connected)
|
|
5533
5540
|
return;
|
|
5534
|
-
const socket = (0, import_net.connect)(
|
|
5541
|
+
const socket = (0, import_net.connect)(this.port);
|
|
5535
5542
|
(0, import_readable_stream.pipeline)(socket, this.createRpcStream(), socket, () => {
|
|
5536
5543
|
this._connected = false;
|
|
5537
5544
|
});
|
|
@@ -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.2",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"module": "dist/index.es.js",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
@@ -25,8 +25,8 @@
|
|
|
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.
|
|
29
|
-
"@tinacms/schema-tools": "1.4.
|
|
28
|
+
"@tinacms/mdx": "1.3.7",
|
|
29
|
+
"@tinacms/schema-tools": "1.4.2",
|
|
30
30
|
"abstract-level": "^1.0.3",
|
|
31
31
|
"body-parser": "^1.19.0",
|
|
32
32
|
"cors": "^2.8.5",
|
|
@@ -83,7 +83,7 @@
|
|
|
83
83
|
"directory": "packages/tina-graphql"
|
|
84
84
|
},
|
|
85
85
|
"devDependencies": {
|
|
86
|
-
"@tinacms/schema-tools": "1.4.
|
|
86
|
+
"@tinacms/schema-tools": "1.4.2",
|
|
87
87
|
"@tinacms/scripts": "1.1.0",
|
|
88
88
|
"@types/cors": "^2.8.7",
|
|
89
89
|
"@types/estree": "^0.0.50",
|