@snowtop/ent 0.0.2 → 0.0.3-4.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/action/action.d.ts +6 -6
- package/action/action.js +2 -2
- package/action/executor.d.ts +7 -12
- package/action/executor.js +39 -33
- package/action/experimental_action.d.ts +4 -2
- package/action/experimental_action.js +27 -2
- package/action/index.d.ts +1 -1
- package/action/orchestrator.d.ts +14 -6
- package/action/orchestrator.js +188 -99
- package/action/privacy.js +4 -4
- package/auth/auth.js +2 -2
- package/core/base.js +12 -9
- package/core/clause.d.ts +1 -0
- package/core/clause.js +6 -2
- package/core/config.d.ts +20 -0
- package/core/config.js +2 -2
- package/core/context.js +3 -3
- package/core/convert.d.ts +4 -0
- package/core/convert.js +25 -2
- package/core/db.d.ts +18 -1
- package/core/db.js +4 -7
- package/core/ent.d.ts +17 -10
- package/core/ent.js +38 -15
- package/core/loaders/assoc_count_loader.js +5 -5
- package/core/loaders/assoc_edge_loader.js +10 -10
- package/core/loaders/loader.js +3 -3
- package/core/loaders/object_loader.js +6 -6
- package/core/loaders/query_loader.js +7 -7
- package/core/loaders/raw_count_loader.js +4 -4
- package/core/logger.js +2 -2
- package/core/privacy.d.ts +21 -1
- package/core/privacy.js +91 -47
- package/core/query/assoc_query.d.ts +12 -12
- package/core/query/assoc_query.js +86 -51
- package/core/query/custom_query.d.ts +10 -7
- package/core/query/custom_query.js +29 -3
- package/core/query/query.d.ts +24 -8
- package/core/query/query.js +41 -4
- package/core/query/shared_assoc_test.js +257 -13
- package/core/query/shared_test.d.ts +1 -1
- package/core/query/shared_test.js +11 -11
- package/core/viewer.js +1 -0
- package/graphql/builtins/connection.js +4 -3
- package/graphql/builtins/edge.js +3 -2
- package/graphql/builtins/node.js +2 -1
- package/graphql/graphql.d.ts +2 -0
- package/graphql/graphql.js +83 -61
- package/graphql/index.d.ts +1 -1
- package/graphql/index.js +2 -1
- package/graphql/node_resolver.d.ts +1 -0
- package/graphql/node_resolver.js +14 -1
- package/graphql/query/connection_type.d.ts +5 -4
- package/graphql/query/connection_type.js +6 -6
- package/graphql/query/edge_connection.d.ts +7 -7
- package/graphql/query/page_info.js +5 -4
- package/graphql/query/shared_assoc_test.js +9 -9
- package/graphql/query/shared_edge_connection.d.ts +1 -1
- package/graphql/query/shared_edge_connection.js +4 -4
- package/graphql/scalars/time.js +1 -1
- package/imports/dataz/example1/_auth.js +8 -8
- package/imports/dataz/example1/_viewer.js +4 -4
- package/imports/index.d.ts +1 -1
- package/imports/index.js +3 -5
- package/index.d.ts +2 -1
- package/index.js +6 -2
- package/package.json +17 -10
- package/parse_schema/parse.d.ts +41 -0
- package/parse_schema/parse.js +147 -0
- package/schema/base_schema.d.ts +2 -0
- package/schema/base_schema.js +17 -7
- package/schema/field.d.ts +52 -15
- package/schema/field.js +252 -47
- package/schema/index.d.ts +1 -0
- package/schema/index.js +1 -0
- package/schema/json_field.d.ts +17 -0
- package/schema/json_field.js +48 -0
- package/schema/schema.d.ts +39 -4
- package/schema/schema.js +2 -0
- package/scripts/custom_compiler.js +8 -10
- package/scripts/custom_graphql.js +45 -10
- package/scripts/read_schema.js +6 -108
- package/testutils/builder.d.ts +6 -3
- package/testutils/builder.js +31 -15
- package/testutils/db/test_db.d.ts +16 -8
- package/testutils/db/test_db.js +65 -9
- package/testutils/db_mock.js +5 -5
- package/testutils/ent-graphql-tests/index.d.ts +1 -0
- package/testutils/ent-graphql-tests/index.js +13 -13
- package/testutils/fake_comms.d.ts +1 -0
- package/testutils/fake_comms.js +4 -0
- package/testutils/fake_data/const.d.ts +5 -1
- package/testutils/fake_data/const.js +19 -1
- package/testutils/fake_data/events_query.d.ts +16 -11
- package/testutils/fake_data/events_query.js +15 -0
- package/testutils/fake_data/fake_contact.js +9 -9
- package/testutils/fake_data/fake_event.js +14 -14
- package/testutils/fake_data/fake_user.js +12 -10
- package/testutils/fake_data/test_helpers.d.ts +5 -1
- package/testutils/fake_data/test_helpers.js +49 -16
- package/testutils/fake_data/user_query.d.ts +25 -9
- package/testutils/fake_data/user_query.js +52 -5
- package/testutils/parse_sql.js +19 -3
- package/testutils/write.js +6 -6
package/action/action.d.ts
CHANGED
|
@@ -7,13 +7,14 @@ export declare enum WriteOperation {
|
|
|
7
7
|
Delete = "delete"
|
|
8
8
|
}
|
|
9
9
|
export interface Builder<T extends Ent> {
|
|
10
|
-
existingEnt?:
|
|
10
|
+
existingEnt?: T;
|
|
11
11
|
ent: EntConstructor<T>;
|
|
12
12
|
placeholderID: ID;
|
|
13
13
|
readonly viewer: Viewer;
|
|
14
14
|
build(): Promise<Changeset<T>>;
|
|
15
15
|
operation: WriteOperation;
|
|
16
16
|
editedEnt?(): Promise<T | null>;
|
|
17
|
+
nodeType: string;
|
|
17
18
|
}
|
|
18
19
|
export interface Executor extends Iterable<DataOperation>, Iterator<DataOperation> {
|
|
19
20
|
placeholderID: ID;
|
|
@@ -27,11 +28,10 @@ export interface Changeset<T extends Ent> {
|
|
|
27
28
|
executor(): Executor;
|
|
28
29
|
viewer: Viewer;
|
|
29
30
|
placeholderID: ID;
|
|
30
|
-
ent: EntConstructor<T>;
|
|
31
31
|
changesets?: Changeset<Ent>[];
|
|
32
|
-
dependencies?: Map<ID, Builder<
|
|
32
|
+
dependencies?: Map<ID, Builder<Ent>>;
|
|
33
33
|
}
|
|
34
|
-
export declare type TriggerReturn = void | Promise<Changeset<Ent> | void | Changeset<Ent>
|
|
34
|
+
export declare type TriggerReturn = void | Promise<Changeset<Ent> | void | (Changeset<Ent> | void)[]> | Promise<Changeset<Ent>>[];
|
|
35
35
|
export interface Trigger<T extends Ent> {
|
|
36
36
|
changeset(builder: Builder<T>, input: Data): TriggerReturn;
|
|
37
37
|
}
|
|
@@ -57,8 +57,8 @@ export interface Action<T extends Ent> {
|
|
|
57
57
|
export declare function saveBuilder<T extends Ent>(builder: Builder<T>): Promise<void>;
|
|
58
58
|
export declare function saveBuilderX<T extends Ent>(builder: Builder<T>): Promise<void>;
|
|
59
59
|
interface Orchestrator {
|
|
60
|
-
addOutboundEdge<T2 extends Ent>(id2: ID | Builder<T2>, edgeType: string, nodeType: string, options?: AssocEdgeInputOptions):
|
|
61
|
-
removeOutboundEdge(id2: ID, edgeType: string):
|
|
60
|
+
addOutboundEdge<T2 extends Ent>(id2: ID | Builder<T2>, edgeType: string, nodeType: string, options?: AssocEdgeInputOptions): void;
|
|
61
|
+
removeOutboundEdge(id2: ID, edgeType: string): void;
|
|
62
62
|
viewer: Viewer;
|
|
63
63
|
}
|
|
64
64
|
export declare function setEdgeTypeInGroup<T extends string>(orchestrator: Orchestrator, inputEnumValue: string, id1: ID, id2: ID, nodeType: string, m: Map<T, string>): Promise<void>;
|
package/action/action.js
CHANGED
|
@@ -23,7 +23,7 @@ async function saveBuilderImpl(builder, throwErr) {
|
|
|
23
23
|
changeset = await builder.build();
|
|
24
24
|
}
|
|
25
25
|
catch (e) {
|
|
26
|
-
logger_1.log("error", e);
|
|
26
|
+
(0, logger_1.log)("error", e);
|
|
27
27
|
if (throwErr) {
|
|
28
28
|
throw e;
|
|
29
29
|
}
|
|
@@ -46,7 +46,7 @@ async function saveBuilderImpl(builder, throwErr) {
|
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
async function modifyEdgeSet(orchestrator, id1, id2, inputEnumValue, enumValue, edgeType, nodeType) {
|
|
49
|
-
let edge = await ent_1.loadEdgeForID2({
|
|
49
|
+
let edge = await (0, ent_1.loadEdgeForID2)({
|
|
50
50
|
id1: id1,
|
|
51
51
|
id2: id2,
|
|
52
52
|
edgeType: edgeType,
|
package/action/executor.d.ts
CHANGED
|
@@ -1,22 +1,21 @@
|
|
|
1
|
-
import { ID, Ent, Viewer,
|
|
1
|
+
import { ID, Data, Ent, Viewer, Context } from "../core/base";
|
|
2
2
|
import { DataOperation } from "../core/ent";
|
|
3
|
-
import { Changeset, Executor } from "../action";
|
|
3
|
+
import { Changeset, Executor } from "../action/action";
|
|
4
4
|
import { Builder } from "../action";
|
|
5
5
|
import { OrchestratorOptions } from "./orchestrator";
|
|
6
6
|
import { Queryer } from "../core/db";
|
|
7
7
|
export declare class ListBasedExecutor<T extends Ent> implements Executor {
|
|
8
8
|
private viewer;
|
|
9
9
|
placeholderID: ID;
|
|
10
|
-
private ent;
|
|
11
10
|
private operations;
|
|
12
11
|
private options?;
|
|
13
12
|
private idx;
|
|
14
|
-
constructor(viewer: Viewer, placeholderID: ID,
|
|
13
|
+
constructor(viewer: Viewer, placeholderID: ID, operations: DataOperation<T>[], options?: OrchestratorOptions<T, Data> | undefined);
|
|
15
14
|
private lastOp;
|
|
16
15
|
private createdEnt;
|
|
17
16
|
resolveValue(val: ID): Ent | null;
|
|
18
17
|
[Symbol.iterator](): this;
|
|
19
|
-
next(): IteratorResult<DataOperation
|
|
18
|
+
next(): IteratorResult<DataOperation<T>>;
|
|
20
19
|
executeObservers(): Promise<void>;
|
|
21
20
|
execute(): Promise<void>;
|
|
22
21
|
preFetch?(queryer: Queryer, context: Context): Promise<void>;
|
|
@@ -25,23 +24,19 @@ export declare class ListBasedExecutor<T extends Ent> implements Executor {
|
|
|
25
24
|
export declare class ComplexExecutor<T extends Ent> implements Executor {
|
|
26
25
|
private viewer;
|
|
27
26
|
placeholderID: ID;
|
|
28
|
-
private ent;
|
|
29
|
-
private options?;
|
|
30
27
|
private idx;
|
|
31
28
|
private mapper;
|
|
32
29
|
private lastOp;
|
|
33
30
|
private allOperations;
|
|
34
|
-
private changesetMap;
|
|
35
|
-
private nodeOpMap;
|
|
36
31
|
private executors;
|
|
37
|
-
constructor(viewer: Viewer, placeholderID: ID,
|
|
32
|
+
constructor(viewer: Viewer, placeholderID: ID, operations: DataOperation[], dependencies: Map<ID, Builder<T>>, changesets: Changeset<T>[], options?: OrchestratorOptions<T, Data>);
|
|
38
33
|
[Symbol.iterator](): this;
|
|
39
34
|
private handleCreatedEnt;
|
|
40
|
-
next(): IteratorResult<DataOperation
|
|
35
|
+
next(): IteratorResult<DataOperation<Ent>>;
|
|
41
36
|
resolveValue(val: ID): Ent | null;
|
|
42
37
|
executeObservers(): Promise<void>;
|
|
43
38
|
execute(): Promise<void>;
|
|
44
39
|
preFetch?(queryer: Queryer, context: Context): Promise<void>;
|
|
45
40
|
postFetch?(queryer: Queryer, context: Context): Promise<void>;
|
|
46
41
|
}
|
|
47
|
-
export declare function executeOperations(executor: Executor, context?: Context, trackOps?: true): Promise<DataOperation[]>;
|
|
42
|
+
export declare function executeOperations(executor: Executor, context?: Context, trackOps?: true): Promise<DataOperation<Ent>[]>;
|
package/action/executor.js
CHANGED
|
@@ -9,10 +9,9 @@ const db_1 = __importDefault(require("../core/db"));
|
|
|
9
9
|
const logger_1 = require("../core/logger");
|
|
10
10
|
// private to ent
|
|
11
11
|
class ListBasedExecutor {
|
|
12
|
-
constructor(viewer, placeholderID,
|
|
12
|
+
constructor(viewer, placeholderID, operations, options) {
|
|
13
13
|
this.viewer = viewer;
|
|
14
14
|
this.placeholderID = placeholderID;
|
|
15
|
-
this.ent = ent;
|
|
16
15
|
this.operations = operations;
|
|
17
16
|
this.options = options;
|
|
18
17
|
this.idx = 0;
|
|
@@ -27,8 +26,9 @@ class ListBasedExecutor {
|
|
|
27
26
|
[Symbol.iterator]() {
|
|
28
27
|
return this;
|
|
29
28
|
}
|
|
29
|
+
// returns true and null|undefined when done
|
|
30
30
|
next() {
|
|
31
|
-
let createdEnt = getCreatedEnt(this.viewer, this.lastOp
|
|
31
|
+
let createdEnt = getCreatedEnt(this.viewer, this.lastOp);
|
|
32
32
|
if (createdEnt) {
|
|
33
33
|
this.createdEnt = createdEnt;
|
|
34
34
|
}
|
|
@@ -36,6 +36,10 @@ class ListBasedExecutor {
|
|
|
36
36
|
const op = this.operations[this.idx];
|
|
37
37
|
this.idx++;
|
|
38
38
|
this.lastOp = op;
|
|
39
|
+
// reset since this could be called multiple times. not needed if we have getSortedOps or something like that
|
|
40
|
+
if (done) {
|
|
41
|
+
this.idx = 0;
|
|
42
|
+
}
|
|
39
43
|
return {
|
|
40
44
|
value: op,
|
|
41
45
|
done: done,
|
|
@@ -47,8 +51,8 @@ class ListBasedExecutor {
|
|
|
47
51
|
return;
|
|
48
52
|
}
|
|
49
53
|
const builder = this.options.builder;
|
|
50
|
-
await Promise.all(action.observers.map((observer) => {
|
|
51
|
-
observer.observe(builder, action.getInput());
|
|
54
|
+
await Promise.all(action.observers.map(async (observer) => {
|
|
55
|
+
await observer.observe(builder, action.getInput());
|
|
52
56
|
}));
|
|
53
57
|
}
|
|
54
58
|
async execute() {
|
|
@@ -74,30 +78,24 @@ class ListBasedExecutor {
|
|
|
74
78
|
}
|
|
75
79
|
}
|
|
76
80
|
exports.ListBasedExecutor = ListBasedExecutor;
|
|
77
|
-
function getCreatedEnt(viewer, op
|
|
78
|
-
if (op && op.
|
|
79
|
-
|
|
80
|
-
if (row) {
|
|
81
|
-
return new ent(viewer, row);
|
|
82
|
-
}
|
|
81
|
+
function getCreatedEnt(viewer, op) {
|
|
82
|
+
if (op && op.createdEnt) {
|
|
83
|
+
return op.createdEnt(viewer);
|
|
83
84
|
}
|
|
84
85
|
return null;
|
|
85
86
|
}
|
|
86
87
|
class ComplexExecutor {
|
|
87
|
-
constructor(viewer, placeholderID,
|
|
88
|
+
constructor(viewer, placeholderID, operations, dependencies, changesets, options) {
|
|
88
89
|
this.viewer = viewer;
|
|
89
90
|
this.placeholderID = placeholderID;
|
|
90
|
-
this.ent = ent;
|
|
91
|
-
this.options = options;
|
|
92
91
|
this.idx = 0;
|
|
93
92
|
this.mapper = new Map();
|
|
94
93
|
this.allOperations = [];
|
|
95
|
-
this.changesetMap = new Map();
|
|
96
|
-
this.nodeOpMap = new Map();
|
|
97
94
|
this.executors = [];
|
|
98
|
-
let graph = graph_data_structure_1.default();
|
|
95
|
+
let graph = (0, graph_data_structure_1.default)();
|
|
96
|
+
const changesetMap = new Map();
|
|
99
97
|
const impl = (c) => {
|
|
100
|
-
|
|
98
|
+
changesetMap.set(c.placeholderID.toString(), c);
|
|
101
99
|
graph.addNode(c.placeholderID.toString());
|
|
102
100
|
if (c.dependencies) {
|
|
103
101
|
for (let [key, builder] of c.dependencies) {
|
|
@@ -117,20 +115,19 @@ class ComplexExecutor {
|
|
|
117
115
|
impl({
|
|
118
116
|
viewer: this.viewer,
|
|
119
117
|
placeholderID: this.placeholderID,
|
|
120
|
-
ent: this.ent,
|
|
121
118
|
changesets: changesets,
|
|
122
119
|
dependencies: dependencies,
|
|
123
120
|
executor: () => {
|
|
124
|
-
return new ListBasedExecutor(this.viewer, this.placeholderID,
|
|
121
|
+
return new ListBasedExecutor(this.viewer, this.placeholderID, operations, options);
|
|
125
122
|
},
|
|
126
123
|
});
|
|
127
124
|
// use a set to handle repeated ops because of how the executor logic currently works
|
|
128
|
-
// TODO: this logic
|
|
125
|
+
// TODO: can this logic be rewritten to not have a set yet avoid duplicates?
|
|
129
126
|
let nodeOps = new Set();
|
|
130
127
|
let remainOps = new Set();
|
|
131
128
|
let sorted = graph.topologicalSort(graph.nodes());
|
|
132
129
|
sorted.forEach((node) => {
|
|
133
|
-
let c =
|
|
130
|
+
let c = changesetMap.get(node);
|
|
134
131
|
if (!c) {
|
|
135
132
|
// phew. expect it to be handled somewhere else
|
|
136
133
|
// we can just skip it and expect the resolver to handle this correctly
|
|
@@ -143,9 +140,8 @@ class ComplexExecutor {
|
|
|
143
140
|
// get ordered list of ops
|
|
144
141
|
let executor = c.executor();
|
|
145
142
|
for (let op of executor) {
|
|
146
|
-
if (op.
|
|
143
|
+
if (op.createdEnt) {
|
|
147
144
|
nodeOps.add(op);
|
|
148
|
-
this.nodeOpMap.set(op, c);
|
|
149
145
|
}
|
|
150
146
|
else {
|
|
151
147
|
remainOps.add(op);
|
|
@@ -165,26 +161,30 @@ class ComplexExecutor {
|
|
|
165
161
|
return this;
|
|
166
162
|
}
|
|
167
163
|
handleCreatedEnt() {
|
|
168
|
-
|
|
169
|
-
if (!c) {
|
|
170
|
-
// nothing to do here
|
|
164
|
+
if (!this.lastOp) {
|
|
171
165
|
return;
|
|
172
166
|
}
|
|
173
|
-
let createdEnt = getCreatedEnt(this.viewer, this.lastOp
|
|
167
|
+
let createdEnt = getCreatedEnt(this.viewer, this.lastOp);
|
|
174
168
|
if (!createdEnt) {
|
|
175
169
|
return;
|
|
176
170
|
}
|
|
177
|
-
|
|
171
|
+
const placeholderID = this.lastOp.placeholderID;
|
|
172
|
+
if (!placeholderID) {
|
|
173
|
+
console.error(`op ${this.lastOp} which implements getCreatedEnt doesn't have a placeholderID`);
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
178
176
|
this.mapper.set(placeholderID, createdEnt);
|
|
179
177
|
}
|
|
180
178
|
next() {
|
|
181
|
-
|
|
182
|
-
this.handleCreatedEnt();
|
|
183
|
-
}
|
|
179
|
+
this.handleCreatedEnt();
|
|
184
180
|
const done = this.idx === this.allOperations.length;
|
|
185
181
|
const op = this.allOperations[this.idx];
|
|
186
182
|
this.idx++;
|
|
187
183
|
this.lastOp = op;
|
|
184
|
+
// reset since this could be called multiple times. not needed if we have getSortedOps or something like that
|
|
185
|
+
if (done) {
|
|
186
|
+
this.idx = 0;
|
|
187
|
+
}
|
|
188
188
|
return {
|
|
189
189
|
value: op,
|
|
190
190
|
done: done,
|
|
@@ -195,6 +195,12 @@ class ComplexExecutor {
|
|
|
195
195
|
if (ent) {
|
|
196
196
|
return ent;
|
|
197
197
|
}
|
|
198
|
+
for (const c of this.executors) {
|
|
199
|
+
const ent = c.resolveValue(val);
|
|
200
|
+
if (ent) {
|
|
201
|
+
return ent;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
198
204
|
return null;
|
|
199
205
|
}
|
|
200
206
|
async executeObservers() {
|
|
@@ -276,7 +282,7 @@ async function executeOperations(executor, context, trackOps) {
|
|
|
276
282
|
if (!isSyncClient(client)) {
|
|
277
283
|
await client.query("ROLLBACK");
|
|
278
284
|
}
|
|
279
|
-
logger_1.log("error", e);
|
|
285
|
+
(0, logger_1.log)("error", e);
|
|
280
286
|
throw e;
|
|
281
287
|
}
|
|
282
288
|
finally {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Viewer, Ent } from "../core/base";
|
|
1
|
+
import { Viewer, Ent, Data } from "../core/base";
|
|
2
2
|
import { Action, WriteOperation, Builder, Trigger, Observer, Changeset, Validator } from "./action";
|
|
3
3
|
export interface ActionOptions<T extends Ent> {
|
|
4
4
|
existingEnt?: T | null;
|
|
@@ -33,6 +33,8 @@ export declare class BaseAction<T extends Ent> implements Action<T> {
|
|
|
33
33
|
getInput(): {};
|
|
34
34
|
}
|
|
35
35
|
interface BuilderConstructor<T extends Ent> {
|
|
36
|
-
new (viewer: Viewer, operation: WriteOperation, action: Action<T>, existingEnt?: T |
|
|
36
|
+
new (viewer: Viewer, operation: WriteOperation, action: Action<T>, existingEnt?: T | undefined): EntBuilder<T>;
|
|
37
37
|
}
|
|
38
|
+
export declare function updateRawObject<TEnt extends Ent, TInput extends Data>(viewer: Viewer, builderCtr: BuilderConstructor<TEnt>, existingEnt: TEnt, input: TInput): Promise<TEnt>;
|
|
39
|
+
export declare function getSimpleEditAction<TEnt extends Ent, TInput extends Data>(viewer: Viewer, builderCtr: BuilderConstructor<TEnt>, existingEnt: TEnt, input: TInput): Action<TEnt>;
|
|
38
40
|
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BaseAction = void 0;
|
|
3
|
+
exports.getSimpleEditAction = exports.updateRawObject = exports.BaseAction = void 0;
|
|
4
4
|
const privacy_1 = require("../core/privacy");
|
|
5
5
|
const action_1 = require("./action");
|
|
6
6
|
class BaseAction {
|
|
@@ -20,7 +20,7 @@ class BaseAction {
|
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
22
|
this.input = options?.input || {};
|
|
23
|
-
this.builder = new builderCtr(viewer, operation, this, options?.existingEnt);
|
|
23
|
+
this.builder = new builderCtr(viewer, operation, this, options?.existingEnt || undefined);
|
|
24
24
|
}
|
|
25
25
|
getPrivacyPolicy() {
|
|
26
26
|
return privacy_1.AlwaysAllowPrivacyPolicy;
|
|
@@ -66,3 +66,28 @@ class BaseAction {
|
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
68
|
exports.BaseAction = BaseAction;
|
|
69
|
+
// this provides a way to just update a row in the database.
|
|
70
|
+
// skips privacy, triggers, observers, etc
|
|
71
|
+
// does do field validation
|
|
72
|
+
// note that only editable fields in the builder can be passed here
|
|
73
|
+
async function updateRawObject(viewer, builderCtr, existingEnt, input) {
|
|
74
|
+
const action = new BaseAction(viewer, builderCtr, {
|
|
75
|
+
existingEnt: existingEnt,
|
|
76
|
+
operation: action_1.WriteOperation.Edit,
|
|
77
|
+
input,
|
|
78
|
+
});
|
|
79
|
+
return action.saveX();
|
|
80
|
+
}
|
|
81
|
+
exports.updateRawObject = updateRawObject;
|
|
82
|
+
// creates an action which has no privacy, triggers, observers etc
|
|
83
|
+
// does do field validation
|
|
84
|
+
// useful to batch a bunch of writes together with BaseAction.bulkAction
|
|
85
|
+
// note that only editable fields in the builder can be passed here
|
|
86
|
+
function getSimpleEditAction(viewer, builderCtr, existingEnt, input) {
|
|
87
|
+
return new BaseAction(viewer, builderCtr, {
|
|
88
|
+
existingEnt: existingEnt,
|
|
89
|
+
operation: action_1.WriteOperation.Edit,
|
|
90
|
+
input,
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
exports.getSimpleEditAction = getSimpleEditAction;
|
package/action/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { WriteOperation, Builder,
|
|
1
|
+
export { WriteOperation, Builder, Changeset, Trigger, Observer, Validator, Action, saveBuilder, saveBuilderX, setEdgeTypeInGroup, TriggerReturn, } from "./action";
|
|
2
2
|
export { OrchestratorOptions, Orchestrator, EntChangeset, EdgeInputData, } from "./orchestrator";
|
|
3
3
|
export { DenyIfBuilder, AllowIfBuilder } from "./privacy";
|
package/action/orchestrator.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { ID, Data, Ent, Viewer, EntConstructor, LoadEntOptions } from "../core/base";
|
|
2
2
|
import { AssocEdgeInputOptions, DataOperation } from "../core/ent";
|
|
3
3
|
import { SchemaInputType } from "../schema/schema";
|
|
4
|
-
import { Changeset, Executor } from "../action";
|
|
4
|
+
import { Changeset, Executor } from "../action/action";
|
|
5
5
|
import { WriteOperation, Builder, Action } from "../action";
|
|
6
|
-
export interface OrchestratorOptions<T extends Ent> {
|
|
6
|
+
export interface OrchestratorOptions<T extends Ent, TData extends Data> {
|
|
7
7
|
viewer: Viewer;
|
|
8
8
|
operation: WriteOperation;
|
|
9
9
|
tableName: string;
|
|
@@ -13,6 +13,7 @@ export interface OrchestratorOptions<T extends Ent> {
|
|
|
13
13
|
action?: Action<T>;
|
|
14
14
|
schema: SchemaInputType;
|
|
15
15
|
editedFields(): Map<string, any>;
|
|
16
|
+
updateInput?: (data: TData) => void;
|
|
16
17
|
}
|
|
17
18
|
interface edgeInputDataOpts {
|
|
18
19
|
edgeType: string;
|
|
@@ -38,7 +39,9 @@ export declare class Orchestrator<T extends Ent> {
|
|
|
38
39
|
private fieldsToResolve;
|
|
39
40
|
private mainOp;
|
|
40
41
|
viewer: Viewer;
|
|
41
|
-
|
|
42
|
+
private defaultFieldsByFieldName;
|
|
43
|
+
private defaultFieldsByTSName;
|
|
44
|
+
constructor(options: OrchestratorOptions<T, Data>);
|
|
42
45
|
private addEdge;
|
|
43
46
|
addInboundEdge<T2 extends Ent>(id1: ID | Builder<T2>, edgeType: string, nodeType: string, options?: AssocEdgeInputOptions): void;
|
|
44
47
|
addOutboundEdge<T2 extends Ent>(id2: ID | Builder<T2>, edgeType: string, nodeType: string, options?: AssocEdgeInputOptions): void;
|
|
@@ -50,11 +53,15 @@ export declare class Orchestrator<T extends Ent> {
|
|
|
50
53
|
private getEdgeOperation;
|
|
51
54
|
private buildEdgeOps;
|
|
52
55
|
private throwError;
|
|
56
|
+
private getEntForPrivacyPolicy;
|
|
53
57
|
private validate;
|
|
54
58
|
private triggers;
|
|
55
59
|
private validators;
|
|
56
60
|
private isBuilder;
|
|
57
|
-
private
|
|
61
|
+
private getFieldsWithDefaultValues;
|
|
62
|
+
private hasData;
|
|
63
|
+
private transformFieldValue;
|
|
64
|
+
private formatAndValidateFields;
|
|
58
65
|
valid(): Promise<boolean>;
|
|
59
66
|
validX(): Promise<void>;
|
|
60
67
|
build(): Promise<EntChangeset<T>>;
|
|
@@ -68,10 +75,11 @@ export declare class EntChangeset<T extends Ent> implements Changeset<T> {
|
|
|
68
75
|
readonly placeholderID: ID;
|
|
69
76
|
readonly ent: EntConstructor<T>;
|
|
70
77
|
operations: DataOperation[];
|
|
71
|
-
dependencies?: Map<ID, Builder<
|
|
78
|
+
dependencies?: Map<ID, Builder<Ent>> | undefined;
|
|
72
79
|
changesets?: Changeset<Ent>[] | undefined;
|
|
73
80
|
private options?;
|
|
74
|
-
|
|
81
|
+
private _executor;
|
|
82
|
+
constructor(viewer: Viewer, placeholderID: ID, ent: EntConstructor<T>, operations: DataOperation[], dependencies?: Map<ID, Builder<Ent>> | undefined, changesets?: Changeset<Ent>[] | undefined, options?: OrchestratorOptions<T, Data> | undefined);
|
|
75
83
|
executor(): Executor;
|
|
76
84
|
}
|
|
77
85
|
export {};
|