@kollors/deep-json-server 1.0.0-alpha.4 → 1.0.0-alpha.5
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/README.md +43 -35
- package/README.ru.md +43 -35
- package/dist/src/constants.d.ts +1 -1
- package/dist/src/constants.js +1 -1
- package/dist/src/engine.d.ts +0 -1
- package/dist/src/engine.js +2 -3
- package/dist/src/engine.js.map +1 -1
- package/dist/src/graphql/preflight.js +9 -0
- package/dist/src/graphql/preflight.js.map +1 -1
- package/dist/src/graphql/resolvers.d.ts +2 -1
- package/dist/src/graphql/resolvers.js +1 -1
- package/dist/src/graphql/resolvers.js.map +1 -1
- package/dist/src/graphql.js +8 -2
- package/dist/src/graphql.js.map +1 -1
- package/dist/src/model.d.ts +4 -0
- package/dist/src/model.js +26 -4
- package/dist/src/model.js.map +1 -1
- package/dist/src/mutations/write.d.ts +2 -1
- package/dist/src/mutations/write.js +22 -18
- package/dist/src/mutations/write.js.map +1 -1
- package/dist/src/openapi/document.js +30 -42
- package/dist/src/openapi/document.js.map +1 -1
- package/dist/src/records.js +3 -5
- package/dist/src/records.js.map +1 -1
- package/dist/src/rest/options.d.ts +5 -6
- package/dist/src/rest/options.js +33 -55
- package/dist/src/rest/options.js.map +1 -1
- package/dist/src/rest/projection.d.ts +5 -4
- package/dist/src/rest/projection.js +35 -18
- package/dist/src/rest/projection.js.map +1 -1
- package/dist/src/rest/routes.js +8 -8
- package/dist/src/rest/routes.js.map +1 -1
- package/package.json +1 -1
package/dist/src/rest/options.js
CHANGED
|
@@ -1,43 +1,42 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { badQuery, childrenOf, nodeAt } from '../query/options.js';
|
|
1
|
+
import { badQuery, childrenOf } from '../query/options.js';
|
|
3
2
|
import { isObject, isSafeKey } from '../utils.js';
|
|
4
|
-
export const ownScope = { '*': true };
|
|
3
|
+
export const ownScope = [{ '*': true }];
|
|
5
4
|
export function scopeFor(scope, key) {
|
|
6
|
-
const selection = Object.hasOwn(scope, key) ? scope[key] : true;
|
|
5
|
+
const selection = Object.hasOwn(scope[0], key) ? scope[0][key] : true;
|
|
7
6
|
return selection === true ? ownScope : selection;
|
|
8
7
|
}
|
|
9
|
-
export function parseRestOptions(query
|
|
8
|
+
export function parseRestOptions(query) {
|
|
10
9
|
if (!isObject(query))
|
|
11
10
|
badQuery('Invalid query');
|
|
12
|
-
const allowed = list ? ['scope', 'nested', 'where', 'order', 'pager'] : ['scope', 'nested'];
|
|
13
11
|
for (const key of Object.keys(query))
|
|
14
|
-
if (
|
|
12
|
+
if (key !== 'scope')
|
|
15
13
|
badQuery(`Unknown query parameter ${key}`);
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
catch {
|
|
28
|
-
badQuery(`Invalid JSON in ${key}`);
|
|
29
|
-
}
|
|
14
|
+
if (query.scope === undefined)
|
|
15
|
+
return { scope: ownScope };
|
|
16
|
+
if (typeof query.scope !== 'string')
|
|
17
|
+
badQuery('scope must occur once and contain JSON');
|
|
18
|
+
if (query.scope.length > 10000)
|
|
19
|
+
badQuery('scope must contain at most 10000 characters');
|
|
20
|
+
try {
|
|
21
|
+
return { scope: JSON.parse(query.scope) };
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
badQuery('Invalid JSON in scope');
|
|
30
25
|
}
|
|
31
|
-
if (!isObject(result.nested))
|
|
32
|
-
badQuery('nested must be an object');
|
|
33
|
-
return result;
|
|
34
26
|
}
|
|
35
|
-
export function validateScope(node, scope, depth = 0) {
|
|
36
|
-
if (!isObject(scope))
|
|
37
|
-
badQuery('scope must be a JSON object');
|
|
27
|
+
export function validateScope(node, scope, list = false, depth = 0) {
|
|
38
28
|
if (depth > 32)
|
|
39
29
|
badQuery('scope is too deep');
|
|
40
|
-
|
|
30
|
+
if (!Array.isArray(scope) || scope.length < 1 || scope.length > 2 || !isObject(scope[0]))
|
|
31
|
+
badQuery('scope must be [fields, arguments?]');
|
|
32
|
+
if (scope.length === 2) {
|
|
33
|
+
if (!list || node.mixed)
|
|
34
|
+
badQuery('scope arguments require a list with consistent object types');
|
|
35
|
+
if (!isObject(scope[1]) || Object.keys(scope[1]).some((key) => !['where', 'order', 'pager'].includes(key)))
|
|
36
|
+
badQuery('Invalid scope arguments');
|
|
37
|
+
}
|
|
38
|
+
const children = childrenOf(node);
|
|
39
|
+
for (const [key, selection] of Object.entries(scope[0])) {
|
|
41
40
|
if (key === '*') {
|
|
42
41
|
if (selection !== true)
|
|
43
42
|
badQuery('scope wildcard must be true');
|
|
@@ -45,34 +44,13 @@ export function validateScope(node, scope, depth = 0) {
|
|
|
45
44
|
}
|
|
46
45
|
if (!/^[A-Za-z][A-Za-z0-9_]*$/.test(key) || !isSafeKey(key))
|
|
47
46
|
badQuery(`Invalid scope field ${key}`);
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
const child = childrenOf(node)[key];
|
|
51
|
-
if (!Object.hasOwn(childrenOf(node), key) || child.writeOnly)
|
|
47
|
+
const child = children[key];
|
|
48
|
+
if (!Object.hasOwn(children, key) || child.writeOnly)
|
|
52
49
|
badQuery(`Unknown or inaccessible scope field ${key}`);
|
|
53
|
-
if (
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
export function validateNested(root, scope, nested) {
|
|
61
|
-
for (const [path, options] of Object.entries(nested)) {
|
|
62
|
-
const node = nodeAt(root, path);
|
|
63
|
-
if (!node.many || (!node.relation && node.base !== 'object'))
|
|
64
|
-
badQuery(`nested.${path} must address an object list`);
|
|
65
|
-
if (!isObject(options) || Object.keys(options).some((k) => !['where', 'order', 'pager'].includes(k)))
|
|
66
|
-
badQuery(`Invalid nested options at ${path}`);
|
|
67
|
-
let current = root;
|
|
68
|
-
let selection = scope;
|
|
69
|
-
for (const key of pathParts(path)) {
|
|
70
|
-
const child = childrenOf(current)[key];
|
|
71
|
-
if (!Object.hasOwn(selection, key) && !(Object.hasOwn(selection, '*') && !child.relation))
|
|
72
|
-
badQuery(`nested path ${path} is not selected by scope`);
|
|
73
|
-
selection = scopeFor(selection, key);
|
|
74
|
-
current = child;
|
|
75
|
-
}
|
|
50
|
+
if (child.relation || child.base === 'object')
|
|
51
|
+
validateScope(child, selection, child.many, depth + 1);
|
|
52
|
+
else if (selection !== true)
|
|
53
|
+
badQuery(`Scalar field ${key} must be true`);
|
|
76
54
|
}
|
|
77
55
|
}
|
|
78
56
|
//# sourceMappingURL=options.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"options.js","sourceRoot":"","sources":["../../../src/rest/options.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"options.js","sourceRoot":"","sources":["../../../src/rest/options.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAoB,MAAM,qBAAqB,CAAC;AAC7E,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAQlD,MAAM,CAAC,MAAM,QAAQ,GAAU,CAAC,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC;AAC/C,MAAM,UAAU,QAAQ,CAAC,KAAY,EAAE,GAAW;IAChD,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IACtE,OAAO,SAAS,KAAK,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC;AACnD,CAAC;AACD,MAAM,UAAU,gBAAgB,CAAC,KAAc;IAC7C,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC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-
import {
|
|
2
|
-
import type { Entity } from '../model.js';
|
|
1
|
+
import type { Engine, PreparedList } from '../engine.js';
|
|
2
|
+
import type { Entity, Node } from '../model.js';
|
|
3
|
+
import { type Ref } from '../records.js';
|
|
3
4
|
import type { JsonObject } from '../types.js';
|
|
4
5
|
import { type RestOptions, type Scope } from './options.js';
|
|
5
|
-
export declare function validateRest(engine: Engine, entity: Entity, options: RestOptions): Map<
|
|
6
|
-
export declare function project(engine: Engine, ref: Ref, scope?: Scope,
|
|
6
|
+
export declare function validateRest(engine: Engine, entity: Entity, options: RestOptions, list?: boolean): Map<Scope | Node, PreparedList>;
|
|
7
|
+
export declare function project(engine: Engine, ref: Ref, scope?: Scope, plans?: Map<Node | Scope, PreparedList>): JsonObject;
|
|
@@ -1,35 +1,52 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { ownScope, scopeFor,
|
|
4
|
-
export function validateRest(engine, entity, options) {
|
|
5
|
-
validateScope(entity.root, options.scope);
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import { childrenOf } from '../query/options.js';
|
|
2
|
+
import { isRef, resolveField } from '../records.js';
|
|
3
|
+
import { ownScope, scopeFor, validateScope } from './options.js';
|
|
4
|
+
export function validateRest(engine, entity, options, list = false) {
|
|
5
|
+
validateScope(entity.root, options.scope, list);
|
|
6
|
+
const plans = new Map();
|
|
7
|
+
if (list)
|
|
8
|
+
plans.set(options.scope, engine.prepareOptions(entity.root, options.scope[1]));
|
|
9
|
+
const visit = (node, scope) => {
|
|
10
|
+
for (const [key, selection] of Object.entries(scope[0])) {
|
|
11
|
+
if (selection === true)
|
|
12
|
+
continue;
|
|
13
|
+
const child = childrenOf(node)[key];
|
|
14
|
+
if (selection[1])
|
|
15
|
+
plans.set(selection, engine.prepareOptions(child, selection[1]));
|
|
16
|
+
visit(child, selection);
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
visit(entity.root, options.scope);
|
|
20
|
+
return plans;
|
|
8
21
|
}
|
|
9
|
-
export function project(engine, ref, scope = ownScope,
|
|
22
|
+
export function project(engine, ref, scope = ownScope, plans = new Map()) {
|
|
10
23
|
const output = Object.create(null);
|
|
11
24
|
const children = childrenOf(ref.node);
|
|
12
25
|
for (const [key, node] of Object.entries(children)) {
|
|
13
|
-
if (node.writeOnly || (!Object.hasOwn(scope, key) && !(Object.hasOwn(scope, '*') && !node.relation)))
|
|
26
|
+
if (node.writeOnly || (!Object.hasOwn(scope[0], key) && !(Object.hasOwn(scope[0], '*') && !node.relation)))
|
|
14
27
|
continue;
|
|
15
28
|
const value = resolveField(ref, node);
|
|
16
29
|
const selection = scopeFor(scope, key);
|
|
17
|
-
const path = prefix + key;
|
|
18
30
|
if (value === undefined)
|
|
19
31
|
continue;
|
|
20
32
|
if (isRef(value))
|
|
21
|
-
output[key] = project(engine, value, selection,
|
|
22
|
-
else if (Array.isArray(value)
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
33
|
+
output[key] = project(engine, value, selection, plans);
|
|
34
|
+
else if (Array.isArray(value)) {
|
|
35
|
+
if (value.every(isRef) && (value.length > 0 || node.relation || node.base === 'object')) {
|
|
36
|
+
const planKey = selection === ownScope ? node : selection;
|
|
37
|
+
const prepared = plans.get(planKey) ?? engine.prepareOptions(node, selection[1]);
|
|
38
|
+
plans.set(planKey, prepared);
|
|
39
|
+
const page = engine.list(value, node, selection[1], prepared);
|
|
40
|
+
output[key] = { data: page.data.map((v) => project(engine, v, selection, plans)), total: page.total };
|
|
41
|
+
}
|
|
42
|
+
else
|
|
43
|
+
output[key] = value.map((item) => (isRef(item) ? project(engine, item, selection, plans) : structuredClone(item)));
|
|
27
44
|
}
|
|
28
45
|
else
|
|
29
46
|
output[key] = structuredClone(value);
|
|
30
47
|
}
|
|
31
|
-
// Schemaless REST includes
|
|
32
|
-
if (!ref.context.model.explicit && scope['*'] === true)
|
|
48
|
+
// Schemaless REST includes raw fields absent from the inferred model.
|
|
49
|
+
if (!ref.context.model.explicit && scope[0]['*'] === true)
|
|
33
50
|
for (const [key, value] of Object.entries(ref.value))
|
|
34
51
|
if (!Object.hasOwn(output, key) && !children[key]?.relation)
|
|
35
52
|
output[key] = structuredClone(value);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"projection.js","sourceRoot":"","sources":["../../../src/rest/projection.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"projection.js","sourceRoot":"","sources":["../../../src/rest/projection.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,KAAK,EAAY,YAAY,EAAE,MAAM,eAAe,CAAC;AAE9D,OAAO,EAAE,QAAQ,EAAgC,QAAQ,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC/F,MAAM,UAAU,YAAY,CAAC,MAAc,EAAE,MAAc,EAAE,OAAoB,EAAE,IAAI,GAAG,KAAK;IAC7F,aAAa,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IAChD,MAAM,KAAK,GAAG,IAAI,GAAG,EAA8B,CAAC;IACpD,IAAI,IAAI;QAAE,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,cAAc,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACzF,MAAM,KAAK,GAAG,CAAC,IAAU,EAAE,KAAY,EAAQ,EAAE;QAC/C,KAAK,MAAM,CAAC,GAAG,EAAE,SAAS,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;YACxD,IAAI,SAAS,KAAK,IAAI;gBAAE,SAAS;YACjC,MAAM,KAAK,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;YACpC,IAAI,SAAS,CAAC,CAAC,CAAC;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CAAC;IAC3D,CAAC;IACD,sEAAsE;IACtE,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,QAAQ,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,IAAI;QACvD,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC;YAAE,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,QAAQ;gBAAE,MAAM,CAAC,GAAG,CAAC,GAAG,eAAe,CAAC,KAAK,CAAC,CAAC;IAC1J,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
package/dist/src/rest/routes.js
CHANGED
|
@@ -9,20 +9,20 @@ export function registerRestRoutes(server, engine) {
|
|
|
9
9
|
server.get(path, async (request) => {
|
|
10
10
|
const context = await engine.context();
|
|
11
11
|
const entity = context.model.byCollection.get(initial.collection);
|
|
12
|
-
const options = parseRestOptions(request.query
|
|
13
|
-
const plans = validateRest(engine, entity, options);
|
|
14
|
-
const page = engine.list(engine.records(context, entity), entity.root, options);
|
|
15
|
-
return { data: page.data.map((ref) => project(engine, ref, options.scope,
|
|
12
|
+
const options = parseRestOptions(request.query);
|
|
13
|
+
const plans = validateRest(engine, entity, options, true);
|
|
14
|
+
const page = engine.list(engine.records(context, entity), entity.root, undefined, plans.get(options.scope));
|
|
15
|
+
return { data: page.data.map((ref) => project(engine, ref, options.scope, plans)), total: page.total };
|
|
16
16
|
});
|
|
17
17
|
server.get(itemPath, async (request) => {
|
|
18
18
|
const context = await engine.context();
|
|
19
19
|
const entity = context.model.byCollection.get(initial.collection);
|
|
20
|
-
const options = parseRestOptions(request.query
|
|
20
|
+
const options = parseRestOptions(request.query);
|
|
21
21
|
const plans = validateRest(engine, entity, options);
|
|
22
22
|
const ref = engine.find(context, entity, request.params[entity.primary]);
|
|
23
23
|
if (!ref)
|
|
24
24
|
throw domainError('NOT_FOUND', 'Record not found');
|
|
25
|
-
return project(engine, ref, options.scope,
|
|
25
|
+
return project(engine, ref, options.scope, plans);
|
|
26
26
|
});
|
|
27
27
|
for (const [method, mode] of [
|
|
28
28
|
['POST', 'create'],
|
|
@@ -34,10 +34,10 @@ export function registerRestRoutes(server, engine) {
|
|
|
34
34
|
method,
|
|
35
35
|
url: mode === 'create' ? path : itemPath,
|
|
36
36
|
handler: async (request, reply) => {
|
|
37
|
-
const options = parseRestOptions(request.query
|
|
37
|
+
const options = parseRestOptions(request.query);
|
|
38
38
|
const result = await engine.mutate(initial, mode, request.params[initial.primary], request.body, (ref) => {
|
|
39
39
|
const plans = validateRest(engine, ref.entity, options);
|
|
40
|
-
return project(engine, ref, options.scope,
|
|
40
|
+
return project(engine, ref, options.scope, plans);
|
|
41
41
|
});
|
|
42
42
|
return reply.code(mode === 'create' ? 201 : 200).send(result);
|
|
43
43
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"routes.js","sourceRoot":"","sources":["../../../src/rest/routes.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AACxD,MAAM,UAAU,kBAAkB,CAAC,MAAuB,EAAE,MAAc;IACxE,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,IAAI,EAAE,CAAC,CAAC,EAAE,SAAS,EAAE,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC,CAAC;IACvG,KAAK,MAAM,OAAO,IAAI,MAAM,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC;QAC5C,MAAM,IAAI,GAAG,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