@snowtop/ent 0.0.3-4.alpha1 → 0.0.3-5.alpha
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/package.json +1 -1
- package/parse_schema/parse.d.ts +9 -2
- package/parse_schema/parse.js +29 -20
- package/schema/field.js +1 -1
package/package.json
CHANGED
package/parse_schema/parse.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Schema, AssocEdge, AssocEdgeGroup, Action } from "../schema";
|
|
1
|
+
import { Schema, Field, AssocEdge, AssocEdgeGroup, Action } from "../schema";
|
|
2
2
|
import { ActionField } from "../schema/schema";
|
|
3
3
|
declare enum NullableResult {
|
|
4
4
|
CONTENTS = "contents",
|
|
@@ -12,10 +12,11 @@ declare type ProcessedAssocEdge = Omit<AssocEdge, "actionOnlyFields" | "edgeActi
|
|
|
12
12
|
patternName?: string;
|
|
13
13
|
edgeActions?: OutputAction[];
|
|
14
14
|
};
|
|
15
|
-
declare type ProcessedSchema = Omit<Schema, "edges" | "actions" | "edgeGroups"> & {
|
|
15
|
+
declare type ProcessedSchema = Omit<Schema, "edges" | "actions" | "edgeGroups" | "fields"> & {
|
|
16
16
|
actions: OutputAction[];
|
|
17
17
|
assocEdges: ProcessedAssocEdge[];
|
|
18
18
|
assocEdgeGroups: ProcessedAssocEdgeGroup[];
|
|
19
|
+
fields: ProcessedField[];
|
|
19
20
|
};
|
|
20
21
|
declare type ProcessedAssocEdgeGroup = Omit<AssocEdgeGroup, "edgeAction"> & {
|
|
21
22
|
edgeAction?: OutputAction;
|
|
@@ -29,7 +30,13 @@ interface schemasDict {
|
|
|
29
30
|
interface ProcessedPattern {
|
|
30
31
|
name: string;
|
|
31
32
|
assocEdges: ProcessedAssocEdge[];
|
|
33
|
+
fields: ProcessedField[];
|
|
32
34
|
}
|
|
35
|
+
declare type ProcessedField = Omit<Field, "defaultValueOnEdit" | "defaultValueOnCreate"> & {
|
|
36
|
+
hasDefaultValueOnCreate?: boolean;
|
|
37
|
+
hasDefaultValueOnEdit?: boolean;
|
|
38
|
+
patternName?: string;
|
|
39
|
+
};
|
|
33
40
|
interface patternsDict {
|
|
34
41
|
[key: string]: ProcessedPattern;
|
|
35
42
|
}
|
package/parse_schema/parse.js
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parseSchema = void 0;
|
|
4
|
-
function processFields(
|
|
4
|
+
function processFields(src, patternName) {
|
|
5
|
+
const ret = [];
|
|
5
6
|
for (const field of src) {
|
|
6
7
|
let f = { ...field };
|
|
7
|
-
f
|
|
8
|
-
f
|
|
8
|
+
f.hasDefaultValueOnCreate = field.defaultValueOnCreate != undefined;
|
|
9
|
+
f.hasDefaultValueOnEdit = field.defaultValueOnEdit != undefined;
|
|
9
10
|
if (field.polymorphic) {
|
|
10
11
|
// convert boolean into object
|
|
11
12
|
// we keep boolean as an option to keep API simple
|
|
12
13
|
if (typeof field.polymorphic === "boolean") {
|
|
13
|
-
f
|
|
14
|
+
f.polymorphic = {};
|
|
14
15
|
}
|
|
15
16
|
else {
|
|
16
|
-
f
|
|
17
|
+
f.polymorphic = field.polymorphic;
|
|
17
18
|
}
|
|
18
19
|
}
|
|
19
20
|
// convert string to object to make API consumed by go simple
|
|
@@ -24,16 +25,22 @@ function processFields(processedSchema, src) {
|
|
|
24
25
|
};
|
|
25
26
|
}
|
|
26
27
|
}
|
|
27
|
-
|
|
28
|
+
if (patternName) {
|
|
29
|
+
f.patternName = patternName;
|
|
30
|
+
}
|
|
31
|
+
ret.push(f);
|
|
28
32
|
}
|
|
33
|
+
return ret;
|
|
29
34
|
}
|
|
30
|
-
function processEdges(
|
|
35
|
+
function processEdges(src, patternName) {
|
|
36
|
+
const ret = [];
|
|
31
37
|
for (const edge of src) {
|
|
32
38
|
let edge2 = { ...edge };
|
|
33
39
|
edge2.edgeActions = edge.edgeActions?.map((action) => processAction(action));
|
|
34
40
|
edge2.patternName = patternName;
|
|
35
|
-
|
|
41
|
+
ret.push(edge2);
|
|
36
42
|
}
|
|
43
|
+
return ret;
|
|
37
44
|
}
|
|
38
45
|
function processEdgeGroups(processedSchema, edgeGroups) {
|
|
39
46
|
// array-ify this
|
|
@@ -49,26 +56,26 @@ function processEdgeGroups(processedSchema, edgeGroups) {
|
|
|
49
56
|
}
|
|
50
57
|
}
|
|
51
58
|
function processPattern(patterns, pattern, processedSchema) {
|
|
52
|
-
|
|
53
|
-
|
|
59
|
+
const name = pattern.name;
|
|
60
|
+
const fields = processFields(pattern.fields, pattern.name);
|
|
61
|
+
processedSchema.fields.push(...fields);
|
|
62
|
+
if (pattern.edges) {
|
|
63
|
+
const edges = processEdges(pattern.edges, pattern.name);
|
|
64
|
+
processedSchema.assocEdges.push(...edges);
|
|
65
|
+
}
|
|
54
66
|
if (patterns[name] === undefined) {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
processEdges(edges, pattern.edges);
|
|
58
|
-
}
|
|
67
|
+
// intentionally processing separately and not passing pattern.name
|
|
68
|
+
const edges = processEdges(pattern.edges || []);
|
|
59
69
|
patterns[name] = {
|
|
60
70
|
name: pattern.name,
|
|
61
71
|
assocEdges: edges,
|
|
72
|
+
fields: fields,
|
|
62
73
|
};
|
|
63
74
|
}
|
|
64
75
|
else {
|
|
65
76
|
// TODO ideally we want to make sure that different patterns don't have the same name
|
|
66
77
|
// can't do a deepEqual check because function calls and therefore different instances in fields
|
|
67
78
|
}
|
|
68
|
-
processFields(processedSchema, pattern.fields);
|
|
69
|
-
if (pattern.edges) {
|
|
70
|
-
processEdges(processedSchema.assocEdges, pattern.edges, pattern.name);
|
|
71
|
-
}
|
|
72
79
|
}
|
|
73
80
|
var NullableResult;
|
|
74
81
|
(function (NullableResult) {
|
|
@@ -133,9 +140,11 @@ function parseSchema(potentialSchemas) {
|
|
|
133
140
|
processPattern(patterns, pattern, processedSchema);
|
|
134
141
|
}
|
|
135
142
|
}
|
|
136
|
-
processFields(
|
|
143
|
+
const fields = processFields(schema.fields);
|
|
144
|
+
processedSchema.fields.push(...fields);
|
|
137
145
|
if (schema.edges) {
|
|
138
|
-
processEdges(
|
|
146
|
+
const edges = processEdges(schema.edges);
|
|
147
|
+
processedSchema.assocEdges.push(...edges);
|
|
139
148
|
}
|
|
140
149
|
if (schema.edgeGroups) {
|
|
141
150
|
processEdgeGroups(processedSchema, schema.edgeGroups);
|
package/schema/field.js
CHANGED
|
@@ -100,7 +100,7 @@ class UUIDField extends BaseField {
|
|
|
100
100
|
throw new Error(`couldn't get loaderInfo for ${this.options.fieldEdge.schema}`);
|
|
101
101
|
}
|
|
102
102
|
if (this.isBuilder(val)) {
|
|
103
|
-
// if builder, the
|
|
103
|
+
// if builder, the nodeType of the builder and the nodeType of the loaderInfo should match
|
|
104
104
|
return val.nodeType === loaderInfo.nodeType;
|
|
105
105
|
}
|
|
106
106
|
// TODO we need context here to make sure that we hit local cache
|