@takeshape/schema 8.35.2 → 8.38.0
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/es/flatten-templates.js +26 -0
- package/es/index.js +2 -1
- package/es/layers/layers.js +1 -1
- package/es/layers/refs.js +1 -1
- package/es/refs.js +74 -2
- package/es/schema-util.js +28 -17
- package/es/template-shapes/index.js +35 -0
- package/es/template-shapes/templates.js +379 -0
- package/es/template-shapes/types.js +1 -0
- package/es/template-shapes/where.js +501 -0
- package/es/validate.js +2 -2
- package/examples/v4_0_0/rick-and-morty-notes/{character-notes.layer.json → layers/character-notes.json} +0 -0
- package/examples/v4_0_0/rick-and-morty-notes/{rick-and-morty.layer.json → layers/rick-and-morty.json} +0 -0
- package/examples/v4_0_0/rick-and-morty-notes/{takeshape-assets.layer.json → layers/takeshape-assets.json} +0 -0
- package/examples/v4_0_0/rick-and-morty-notes/{takeshape-builtins.layer.json → layers/takeshape-builtins.json} +0 -0
- package/examples/v4_0_0/rick-and-morty-notes/{takeshape-static-sites.layer.json → layers/takeshape-static-sites.json} +0 -0
- package/examples/v4_0_0/shopify-lookbook/{andrews-store.layer.json → layers/andrews-store.json} +0 -0
- package/examples/v4_0_0/shopify-lookbook/{lookbook.layer.json → layers/lookbook.json} +0 -0
- package/examples/v4_0_0/shopify-lookbook/{takeshape-assets.layer.json → layers/takeshape-assets.json} +0 -0
- package/examples/v4_0_0/shopify-lookbook/{takeshape-builtins.layer.json → layers/takeshape-builtins.json} +0 -0
- package/lib/flatten-templates.d.ts +3 -0
- package/lib/flatten-templates.d.ts.map +1 -0
- package/lib/flatten-templates.js +39 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +14 -0
- package/lib/layers/layers.js +3 -3
- package/lib/layers/refs.js +2 -2
- package/lib/refs.d.ts +26 -1
- package/lib/refs.d.ts.map +1 -1
- package/lib/refs.js +94 -11
- package/lib/schema-util.d.ts +7 -6
- package/lib/schema-util.d.ts.map +1 -1
- package/lib/schema-util.js +41 -29
- package/lib/template-shapes/index.d.ts +8 -0
- package/lib/template-shapes/index.d.ts.map +1 -0
- package/lib/template-shapes/index.js +46 -0
- package/lib/template-shapes/templates.d.ts +29 -0
- package/lib/template-shapes/templates.d.ts.map +1 -0
- package/lib/template-shapes/templates.js +427 -0
- package/lib/template-shapes/types.d.ts +10 -0
- package/lib/template-shapes/types.d.ts.map +1 -0
- package/lib/template-shapes/types.js +5 -0
- package/lib/template-shapes/where.d.ts +39 -0
- package/lib/template-shapes/where.d.ts.map +1 -0
- package/lib/template-shapes/where.js +534 -0
- package/lib/validate.js +1 -1
- package/package.json +4 -4
- package/es/template-shapes.js +0 -79
- package/lib/template-shapes.d.ts +0 -32
- package/lib/template-shapes.d.ts.map +0 -1
- package/lib/template-shapes.js +0 -101
package/lib/template-shapes.js
DELETED
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.createTemplateShapeName = createTemplateShapeName;
|
|
7
|
-
exports.isValidTemplate = isValidTemplate;
|
|
8
|
-
exports.knownTemplateShapes = void 0;
|
|
9
|
-
exports.parseReturnShape = parseReturnShape;
|
|
10
|
-
exports.parseTemplateShape = parseTemplateShape;
|
|
11
|
-
exports.untemplate = void 0;
|
|
12
|
-
|
|
13
|
-
var _utils = require("./types/utils");
|
|
14
|
-
|
|
15
|
-
var _refs = require("./refs");
|
|
16
|
-
|
|
17
|
-
const knownTemplateShapes = new Set(['TSGetArgs', 'TSGetSingletonArgs', 'PaginatedList', 'TSListArgs', 'CreateArgs', 'UpdateArgs', 'DuplicateArgs', 'DeleteArgs', 'CreateResult', 'UpdateResult', 'DuplicateResult', 'DeleteResult']);
|
|
18
|
-
/**
|
|
19
|
-
* Check if a string is a known template such as `PaginatedList`
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
|
-
exports.knownTemplateShapes = knownTemplateShapes;
|
|
23
|
-
|
|
24
|
-
function isValidTemplate(template) {
|
|
25
|
-
return knownTemplateShapes.has(template);
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Parse a template like `PaginatedList<Post>` and return both the template and the shape name.
|
|
29
|
-
*/
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
function parseTemplateShape(shape) {
|
|
33
|
-
const parts = shape.split('<');
|
|
34
|
-
|
|
35
|
-
if (parts.length > 1 && isValidTemplate(parts[0])) {
|
|
36
|
-
return {
|
|
37
|
-
shapeName: parts[1].replace(/(<|>)/, ''),
|
|
38
|
-
template: parts[0]
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
return {
|
|
43
|
-
shapeName: parts[0],
|
|
44
|
-
template: undefined
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function parseReturnShape(projectSchema, shape) {
|
|
49
|
-
if (typeof shape === 'object') {
|
|
50
|
-
if ((0, _utils.isRefSchema)(shape.items)) {
|
|
51
|
-
const ref = (0, _refs.getRef)(projectSchema, shape.items);
|
|
52
|
-
|
|
53
|
-
if (!ref) {
|
|
54
|
-
throw new Error(`Could not parse ${JSON.stringify(shape.items)}: invalid ref`);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
return {
|
|
58
|
-
isArray: true,
|
|
59
|
-
ref,
|
|
60
|
-
shapeName: (0, _refs.refItemToShapeName)(ref)
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
if (typeof shape.items.type !== 'string') {
|
|
65
|
-
throw new Error(`Could not parse ${JSON.stringify(shape.items)}: invalid type`);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
return {
|
|
69
|
-
isArray: true,
|
|
70
|
-
shapeName: shape.items.type
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
const ref = (0, _refs.refExpressionToRefItem)(projectSchema, shape);
|
|
75
|
-
const shapeName = (0, _refs.refItemToShapeName)(ref);
|
|
76
|
-
return {
|
|
77
|
-
isArray: false,
|
|
78
|
-
shapeName,
|
|
79
|
-
ref,
|
|
80
|
-
template: ref.template
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Create a template string like `PaginatedList<Post>` from a template and shape name.
|
|
85
|
-
*/
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
function createTemplateShapeName(template, shapeName) {
|
|
89
|
-
return `${template}<${shapeName}>`;
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* If the string is a template like `PaginatedList<Post>`, return the shape name,
|
|
93
|
-
* in this case `Post`. Otherwise return the input.
|
|
94
|
-
*/
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
const untemplate = input => {
|
|
98
|
-
return parseTemplateShape(input).shapeName;
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
exports.untemplate = untemplate;
|