@takeshape/schema 8.159.6 → 8.159.10
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/create-input-schema.d.ts +10 -0
- package/dist/create-input-schema.d.ts.map +1 -0
- package/dist/{rewrite.js → create-input-schema.js} +15 -17
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -4
- package/dist/migration/types.d.ts +7 -2
- package/dist/migration/types.d.ts.map +1 -1
- package/dist/template-shapes/templates.d.ts.map +1 -1
- package/dist/template-shapes/templates.js +4 -8
- package/es/{rewrite.js → create-input-schema.js} +14 -16
- package/es/index.js +1 -1
- package/es/template-shapes/templates.js +4 -8
- package/package.json +4 -4
- package/dist/rewrite.d.ts +0 -10
- package/dist/rewrite.d.ts.map +0 -1
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ProjectSchema, ShapeSchema, PropertySchema } from './project-schema';
|
|
2
|
+
export interface CreateInputSchemaOptions {
|
|
3
|
+
isUpdate?: boolean;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Convert all output properties in the schema to be input properties,
|
|
7
|
+
* For an update, remove `required` and `default` fields as well.
|
|
8
|
+
*/
|
|
9
|
+
export declare function createInputSchema<T extends ProjectSchema | ShapeSchema | PropertySchema>(schema: T, options?: CreateInputSchemaOptions): T;
|
|
10
|
+
//# sourceMappingURL=create-input-schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-input-schema.d.ts","sourceRoot":"","sources":["../../src/create-input-schema.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,aAAa,EAAE,WAAW,EAAE,cAAc,EAAC,MAAM,kBAAkB,CAAC;AAE5E,MAAM,WAAW,wBAAwB;IACvC,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAkBD;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,SAAS,aAAa,GAAG,WAAW,GAAG,cAAc,EACtF,MAAM,EAAE,CAAC,EACT,OAAO,GAAE,wBAA6B,GACrC,CAAC,CA+CH"}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.createInputSchema = createInputSchema;
|
|
7
7
|
|
|
8
8
|
var _defaults = _interopRequireDefault(require("lodash/fp/defaults"));
|
|
9
9
|
|
|
@@ -11,33 +11,31 @@ var _util = require("@takeshape/util");
|
|
|
11
11
|
|
|
12
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
13
|
|
|
14
|
-
const
|
|
14
|
+
const inputSchemaCache = new Map();
|
|
15
15
|
|
|
16
|
-
function
|
|
16
|
+
function getInputSchemaCache(options) {
|
|
17
17
|
// Ensure key order does not invalidate the cache
|
|
18
18
|
const key = JSON.stringify(options, Object.keys(options).sort());
|
|
19
|
-
let cache =
|
|
19
|
+
let cache = inputSchemaCache.get(key);
|
|
20
20
|
|
|
21
21
|
if (!cache) {
|
|
22
22
|
cache = new WeakMap();
|
|
23
|
-
|
|
23
|
+
inputSchemaCache.set(key, cache);
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
return cache;
|
|
27
27
|
}
|
|
28
28
|
/**
|
|
29
|
-
*
|
|
29
|
+
* Convert all output properties in the schema to be input properties,
|
|
30
|
+
* For an update, remove `required` and `default` fields as well.
|
|
30
31
|
*/
|
|
31
|
-
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
32
32
|
|
|
33
33
|
|
|
34
|
-
function
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
removeRequired: false,
|
|
38
|
-
replaceInput: false
|
|
34
|
+
function createInputSchema(schema, options = {}) {
|
|
35
|
+
const inputSchemaCache = getInputSchemaCache((0, _defaults.default)({
|
|
36
|
+
isUpdate: false
|
|
39
37
|
}, options));
|
|
40
|
-
let rewrittenSchema =
|
|
38
|
+
let rewrittenSchema = inputSchemaCache.get(schema);
|
|
41
39
|
|
|
42
40
|
if (rewrittenSchema) {
|
|
43
41
|
return rewrittenSchema;
|
|
@@ -46,16 +44,16 @@ function rewriteSchema(schema, options) {
|
|
|
46
44
|
rewrittenSchema = JSON.parse(JSON.stringify(schema), (_key, value) => {
|
|
47
45
|
if ((0, _util.isRecord)(value)) {
|
|
48
46
|
// Remove required
|
|
49
|
-
if (options.
|
|
47
|
+
if (options.isUpdate && Array.isArray(value.required) && value.required.length) {
|
|
50
48
|
delete value.required;
|
|
51
49
|
} // Remove default
|
|
52
50
|
|
|
53
51
|
|
|
54
|
-
if (options.
|
|
52
|
+
if (options.isUpdate && value.type !== undefined && value.default !== undefined) {
|
|
55
53
|
delete value.default;
|
|
56
54
|
}
|
|
57
55
|
|
|
58
|
-
if (
|
|
56
|
+
if ((0, _util.isRecord)(value['@input'])) {
|
|
59
57
|
const {
|
|
60
58
|
'@input': input,
|
|
61
59
|
'@l10n': l10n,
|
|
@@ -76,6 +74,6 @@ function rewriteSchema(schema, options) {
|
|
|
76
74
|
|
|
77
75
|
return value;
|
|
78
76
|
});
|
|
79
|
-
|
|
77
|
+
inputSchemaCache.set(schema, rewrittenSchema);
|
|
80
78
|
return rewrittenSchema;
|
|
81
79
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -27,6 +27,6 @@ export * from './types/types';
|
|
|
27
27
|
export * from './types/utils';
|
|
28
28
|
export * from './flatten-templates';
|
|
29
29
|
export * from './relationships';
|
|
30
|
-
export * from './
|
|
30
|
+
export * from './create-input-schema';
|
|
31
31
|
export * from './schema-transform';
|
|
32
32
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAC,mBAAmB,EAAE,6BAA6B,EAAC,MAAM,mBAAmB,CAAC;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ACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,OAAO,EAAC,aAAa,EAAC,MAAM,kBAAkB,CAAC;AAC/C,cAAc,YAAY,CAAC;AAC3B,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,WAAW,CAAC;AAC1B,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,qBAAqB,CAAC;AACpC,cAAc,iBAAiB,CAAC;AAChC,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -377,16 +377,16 @@ Object.keys(_relationships).forEach(function (key) {
|
|
|
377
377
|
});
|
|
378
378
|
});
|
|
379
379
|
|
|
380
|
-
var
|
|
380
|
+
var _createInputSchema = require("./create-input-schema");
|
|
381
381
|
|
|
382
|
-
Object.keys(
|
|
382
|
+
Object.keys(_createInputSchema).forEach(function (key) {
|
|
383
383
|
if (key === "default" || key === "__esModule") return;
|
|
384
384
|
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
385
|
-
if (key in exports && exports[key] ===
|
|
385
|
+
if (key in exports && exports[key] === _createInputSchema[key]) return;
|
|
386
386
|
Object.defineProperty(exports, key, {
|
|
387
387
|
enumerable: true,
|
|
388
388
|
get: function () {
|
|
389
|
-
return
|
|
389
|
+
return _createInputSchema[key];
|
|
390
390
|
}
|
|
391
391
|
});
|
|
392
392
|
});
|
|
@@ -1,14 +1,19 @@
|
|
|
1
|
-
import type { ProjectSchema, FormConfig, Workflow, Shape } from '../project-schema';
|
|
1
|
+
import type { ProjectSchema, FormConfig, Workflow, Shape, StoredServiceConfig, Query } from '../project-schema';
|
|
2
2
|
import type { EncryptFn, SafeDecryptFn } from '../services';
|
|
3
|
+
import { IndexedShapeConfig } from '../project-schema';
|
|
3
4
|
export interface ProjectSchemaMigrationContext {
|
|
4
5
|
generateDataKeyFn: () => Promise<string>;
|
|
5
6
|
encryptFn: EncryptFn;
|
|
6
7
|
decryptFn: SafeDecryptFn;
|
|
7
8
|
}
|
|
8
|
-
export interface ProjectSchemaUpdate extends Omit<Partial<ProjectSchema>, 'shapes' | 'forms' | 'workflows'> {
|
|
9
|
+
export interface ProjectSchemaUpdate extends Omit<Partial<ProjectSchema>, 'queries' | 'mutations' | 'shapes' | 'forms' | 'workflows' | 'indexedShapes' | 'services'> {
|
|
10
|
+
queries?: Record<string, Query | null>;
|
|
11
|
+
mutations?: Record<string, Query | null>;
|
|
9
12
|
shapes?: Record<string, Shape | null>;
|
|
10
13
|
forms?: Record<string, FormConfig | null>;
|
|
11
14
|
workflows?: Record<string, Workflow | null>;
|
|
15
|
+
services?: Record<string, StoredServiceConfig | null>;
|
|
16
|
+
indexedShapes?: Record<string, IndexedShapeConfig | null>;
|
|
12
17
|
deactivated?: number;
|
|
13
18
|
}
|
|
14
19
|
export declare type MigrateFunction<FromSchema, ToSchema> = (context: ProjectSchemaMigrationContext, fromSchema: FromSchema) => Promise<ToSchema>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/migration/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,aAAa,EAAE,UAAU,EAAE,QAAQ,EAAE,KAAK,EAAC,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/migration/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,aAAa,EAAE,UAAU,EAAE,QAAQ,EAAE,KAAK,EAAE,mBAAmB,EAAE,KAAK,EAAC,MAAM,mBAAmB,CAAC;AAC9G,OAAO,KAAK,EAAC,SAAS,EAAE,aAAa,EAAC,MAA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M,EAAE,IAAI,EAAE,aAAa,uBAM9C,eAAe,SAAS,KAAK,KAAG,gBAAgB,CA4E1E;AAED,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,aAAa,aACtC,OAAO,SAAS,KAAK,KAAG,gBAAgB,CAiB1D;AAED,eAAO,MAAM,gBAAgB,EAAE,YAwB9B,CAAC;AAuBF,wBAAgB,qBAAqB,CAAC,YAAY,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,aAC5D,eAAe,SAAS,KAAK,KAAG,gBAAgB,CA0BlE"}
|
|
@@ -31,7 +31,7 @@ var _where = require("./where");
|
|
|
31
31
|
|
|
32
32
|
var _util2 = require("../util");
|
|
33
33
|
|
|
34
|
-
var
|
|
34
|
+
var _createInputSchema = require("../create-input-schema");
|
|
35
35
|
|
|
36
36
|
var _get = _interopRequireDefault(require("lodash/get"));
|
|
37
37
|
|
|
@@ -298,10 +298,8 @@ function getMutationArgs(templateName, verb) {
|
|
|
298
298
|
let inputShapeSchema;
|
|
299
299
|
|
|
300
300
|
if (verb !== _types.TemplateVerbs.Delete) {
|
|
301
|
-
rewrittenSchema = (0,
|
|
302
|
-
|
|
303
|
-
removeRequired: isUpdate,
|
|
304
|
-
replaceInput: true
|
|
301
|
+
rewrittenSchema = (0, _createInputSchema.createInputSchema)(shape.schema, {
|
|
302
|
+
isUpdate
|
|
305
303
|
});
|
|
306
304
|
inputShapeSchema = rewriteRefs(rewrittenSchema, getInputShapeName);
|
|
307
305
|
}
|
|
@@ -343,9 +341,7 @@ function getMutationArgs(templateName, verb) {
|
|
|
343
341
|
}).map(shapeName => {
|
|
344
342
|
const shape = projectSchema.shapes[shapeName]; // We only allow partial input at the top-level
|
|
345
343
|
|
|
346
|
-
return (0, _schemaUtil.createShape)(getInputShapeName(shapeName), rewriteRefs((0,
|
|
347
|
-
replaceInput: true
|
|
348
|
-
}), getInputShapeName));
|
|
344
|
+
return (0, _schemaUtil.createShape)(getInputShapeName(shapeName), rewriteRefs((0, _createInputSchema.createInputSchema)(shape.schema), getInputShapeName));
|
|
349
345
|
}), 'name')),
|
|
350
346
|
...(addStructure ? {
|
|
351
347
|
ContentStructureInput
|
|
@@ -1,32 +1,30 @@
|
|
|
1
1
|
import defaults from 'lodash/fp/defaults';
|
|
2
2
|
import { isRecord } from '@takeshape/util';
|
|
3
|
-
const
|
|
3
|
+
const inputSchemaCache = new Map();
|
|
4
4
|
|
|
5
|
-
function
|
|
5
|
+
function getInputSchemaCache(options) {
|
|
6
6
|
// Ensure key order does not invalidate the cache
|
|
7
7
|
const key = JSON.stringify(options, Object.keys(options).sort());
|
|
8
|
-
let cache =
|
|
8
|
+
let cache = inputSchemaCache.get(key);
|
|
9
9
|
|
|
10
10
|
if (!cache) {
|
|
11
11
|
cache = new WeakMap();
|
|
12
|
-
|
|
12
|
+
inputSchemaCache.set(key, cache);
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
return cache;
|
|
16
16
|
}
|
|
17
17
|
/**
|
|
18
|
-
*
|
|
18
|
+
* Convert all output properties in the schema to be input properties,
|
|
19
|
+
* For an update, remove `required` and `default` fields as well.
|
|
19
20
|
*/
|
|
20
|
-
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
21
21
|
|
|
22
22
|
|
|
23
|
-
export function
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
removeRequired: false,
|
|
27
|
-
replaceInput: false
|
|
23
|
+
export function createInputSchema(schema, options = {}) {
|
|
24
|
+
const inputSchemaCache = getInputSchemaCache(defaults({
|
|
25
|
+
isUpdate: false
|
|
28
26
|
}, options));
|
|
29
|
-
let rewrittenSchema =
|
|
27
|
+
let rewrittenSchema = inputSchemaCache.get(schema);
|
|
30
28
|
|
|
31
29
|
if (rewrittenSchema) {
|
|
32
30
|
return rewrittenSchema;
|
|
@@ -35,16 +33,16 @@ export function rewriteSchema(schema, options) {
|
|
|
35
33
|
rewrittenSchema = JSON.parse(JSON.stringify(schema), (_key, value) => {
|
|
36
34
|
if (isRecord(value)) {
|
|
37
35
|
// Remove required
|
|
38
|
-
if (options.
|
|
36
|
+
if (options.isUpdate && Array.isArray(value.required) && value.required.length) {
|
|
39
37
|
delete value.required;
|
|
40
38
|
} // Remove default
|
|
41
39
|
|
|
42
40
|
|
|
43
|
-
if (options.
|
|
41
|
+
if (options.isUpdate && value.type !== undefined && value.default !== undefined) {
|
|
44
42
|
delete value.default;
|
|
45
43
|
}
|
|
46
44
|
|
|
47
|
-
if (
|
|
45
|
+
if (isRecord(value['@input'])) {
|
|
48
46
|
const {
|
|
49
47
|
'@input': input,
|
|
50
48
|
'@l10n': l10n,
|
|
@@ -65,6 +63,6 @@ export function rewriteSchema(schema, options) {
|
|
|
65
63
|
|
|
66
64
|
return value;
|
|
67
65
|
});
|
|
68
|
-
|
|
66
|
+
inputSchemaCache.set(schema, rewrittenSchema);
|
|
69
67
|
return rewrittenSchema;
|
|
70
68
|
}
|
package/es/index.js
CHANGED
|
@@ -6,7 +6,7 @@ import { createShape, getShapeDependencies, isIndexedRemoteShape } from '../sche
|
|
|
6
6
|
import { getFlattenedTemplateShapeName, getRefShapeName } from '../refs';
|
|
7
7
|
import { getWhereSearchArg } from './where';
|
|
8
8
|
import { mergeObjectSchemas, mergeSchemaProperties } from '../util';
|
|
9
|
-
import {
|
|
9
|
+
import { createInputSchema } from '../create-input-schema';
|
|
10
10
|
import get from 'lodash/get';
|
|
11
11
|
export const TSGetArgs = getIDQueryArgs('TSGetArgs');
|
|
12
12
|
export const TSGetSingletonArgs = getIDQueryArgs('TSGetSingletonArgs');
|
|
@@ -243,10 +243,8 @@ export function getMutationArgs(templateName, verb) {
|
|
|
243
243
|
let inputShapeSchema;
|
|
244
244
|
|
|
245
245
|
if (verb !== TemplateVerbs.Delete) {
|
|
246
|
-
rewrittenSchema =
|
|
247
|
-
|
|
248
|
-
removeRequired: isUpdate,
|
|
249
|
-
replaceInput: true
|
|
246
|
+
rewrittenSchema = createInputSchema(shape.schema, {
|
|
247
|
+
isUpdate
|
|
250
248
|
});
|
|
251
249
|
inputShapeSchema = rewriteRefs(rewrittenSchema, getInputShapeName);
|
|
252
250
|
}
|
|
@@ -288,9 +286,7 @@ export function getMutationArgs(templateName, verb) {
|
|
|
288
286
|
}).map(shapeName => {
|
|
289
287
|
const shape = projectSchema.shapes[shapeName]; // We only allow partial input at the top-level
|
|
290
288
|
|
|
291
|
-
return createShape(getInputShapeName(shapeName), rewriteRefs(
|
|
292
|
-
replaceInput: true
|
|
293
|
-
}), getInputShapeName));
|
|
289
|
+
return createShape(getInputShapeName(shapeName), rewriteRefs(createInputSchema(shape.schema), getInputShapeName));
|
|
294
290
|
}), 'name')),
|
|
295
291
|
...(addStructure ? {
|
|
296
292
|
ContentStructureInput
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@takeshape/schema",
|
|
3
|
-
"version": "8.159.
|
|
3
|
+
"version": "8.159.10",
|
|
4
4
|
"description": "TakeShape Schema",
|
|
5
5
|
"homepage": "https://www.takeshape.io",
|
|
6
6
|
"repository": {
|
|
@@ -21,9 +21,9 @@
|
|
|
21
21
|
"examples"
|
|
22
22
|
],
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@takeshape/errors": "8.159.
|
|
25
|
-
"@takeshape/json-schema": "8.159.
|
|
26
|
-
"@takeshape/util": "8.159.
|
|
24
|
+
"@takeshape/errors": "8.159.10",
|
|
25
|
+
"@takeshape/json-schema": "8.159.10",
|
|
26
|
+
"@takeshape/util": "8.159.10",
|
|
27
27
|
"ajv": "^8.10.0",
|
|
28
28
|
"ajv-formats": "^2.1.1",
|
|
29
29
|
"blueimp-md5": "^2.10.0",
|
package/dist/rewrite.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export interface RewriteSchemaOptions {
|
|
2
|
-
removeRequired?: boolean;
|
|
3
|
-
removeDefault?: boolean;
|
|
4
|
-
replaceInput?: boolean;
|
|
5
|
-
}
|
|
6
|
-
/**
|
|
7
|
-
* Rewrite a schema, applying optional modifications.
|
|
8
|
-
*/
|
|
9
|
-
export declare function rewriteSchema<T extends object>(schema: T, options: RewriteSchemaOptions): T;
|
|
10
|
-
//# sourceMappingURL=rewrite.d.ts.map
|
package/dist/rewrite.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"rewrite.d.ts","sourceRoot":"","sources":["../../src/rewrite.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,oBAAoB;IACnC,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB;AAkBD;;GAEG;AAEH,wBAAgB,aAAa,CAAC,CAAC,SAAS,MAAM,EAAE,MAAM,EAAE,CAAC,EAAE,OAAO,EAAE,oBAAoB,GAAG,CAAC,CAiD3F"}
|