@snowtop/ent 0.1.0-alpha31 → 0.1.0-alpha34
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 +1 -1
- package/action/orchestrator.js +14 -6
- package/package.json +1 -1
- package/schema/schema.d.ts +4 -4
package/action/action.d.ts
CHANGED
|
@@ -53,7 +53,7 @@ export interface Action<TEnt extends Ent<TViewer>, TBuilder extends Builder<TEnt
|
|
|
53
53
|
getObservers?(): Observer<TEnt, TBuilder, TViewer, TInput, TExistingEnt>[];
|
|
54
54
|
getValidators?(): Validator<TEnt, TBuilder, TViewer, TInput, TExistingEnt>[];
|
|
55
55
|
getInput(): TInput;
|
|
56
|
-
transformWrite?: (stmt: UpdateOperation<TEnt>) => Promise<TransformedUpdateOperation<TEnt>> | TransformedUpdateOperation<TEnt> | null;
|
|
56
|
+
transformWrite?: (stmt: UpdateOperation<TEnt, TViewer>) => Promise<TransformedUpdateOperation<TEnt>> | TransformedUpdateOperation<TEnt> | null;
|
|
57
57
|
valid(): Promise<boolean>;
|
|
58
58
|
validX(): Promise<void>;
|
|
59
59
|
viewerForEntLoad?(data: Data): TViewer | Promise<TViewer>;
|
package/action/orchestrator.js
CHANGED
|
@@ -379,23 +379,29 @@ class Orchestrator {
|
|
|
379
379
|
// if disable transformations set, don't do schema transform and just do the right thing
|
|
380
380
|
// else apply schema tranformation if it exists
|
|
381
381
|
let transformed = null;
|
|
382
|
+
const sqlOp = this.getSQLStatementOperation();
|
|
382
383
|
if (action?.transformWrite) {
|
|
383
384
|
transformed = await action.transformWrite({
|
|
384
|
-
|
|
385
|
-
|
|
385
|
+
builder,
|
|
386
|
+
input,
|
|
387
|
+
op: sqlOp,
|
|
386
388
|
data: editedFields,
|
|
387
|
-
existingEnt: this.existingEnt,
|
|
388
389
|
});
|
|
389
390
|
}
|
|
390
391
|
else if (!this.disableTransformations) {
|
|
391
392
|
transformed = (0, schema_1.getTransformedUpdateOp)(this.options.schema, {
|
|
392
|
-
|
|
393
|
-
|
|
393
|
+
builder,
|
|
394
|
+
input,
|
|
395
|
+
op: sqlOp,
|
|
394
396
|
data: editedFields,
|
|
395
|
-
existingEnt: this.existingEnt,
|
|
396
397
|
});
|
|
397
398
|
}
|
|
398
399
|
if (transformed) {
|
|
400
|
+
if (sqlOp === schema_1.SQLStatementOperation.Insert && sqlOp !== transformed.op) {
|
|
401
|
+
if (!transformed.existingEnt) {
|
|
402
|
+
throw new Error(`cannot transform an insert operation without providing an existing ent`);
|
|
403
|
+
}
|
|
404
|
+
}
|
|
399
405
|
if (transformed.data) {
|
|
400
406
|
updateInput = true;
|
|
401
407
|
for (const k in transformed.data) {
|
|
@@ -418,6 +424,8 @@ class Orchestrator {
|
|
|
418
424
|
if (transformed.existingEnt) {
|
|
419
425
|
// @ts-ignore
|
|
420
426
|
this.existingEnt = transformed.existingEnt;
|
|
427
|
+
// modify existing ent in builder. it's readonly in generated ents but doesn't apply here
|
|
428
|
+
builder.existingEnt = transformed.existingEnt;
|
|
421
429
|
}
|
|
422
430
|
}
|
|
423
431
|
// transforming before doing default fields so that we don't create a new id
|
package/package.json
CHANGED
package/schema/schema.d.ts
CHANGED
|
@@ -82,10 +82,10 @@ export declare enum SQLStatementOperation {
|
|
|
82
82
|
Update = "update",
|
|
83
83
|
Delete = "delete"
|
|
84
84
|
}
|
|
85
|
-
export interface UpdateOperation<
|
|
85
|
+
export interface UpdateOperation<TEnt extends Ent<TViewer>, TViewer extends Viewer = Viewer> {
|
|
86
86
|
op: SQLStatementOperation;
|
|
87
|
-
|
|
88
|
-
|
|
87
|
+
builder: Builder<TEnt, TViewer>;
|
|
88
|
+
input: Data;
|
|
89
89
|
data?: Map<string, any>;
|
|
90
90
|
}
|
|
91
91
|
export interface TransformedUpdateOperation<T extends Ent> {
|
|
@@ -204,7 +204,7 @@ interface objectLoaderOptions {
|
|
|
204
204
|
instanceKey?: string;
|
|
205
205
|
}
|
|
206
206
|
export declare function getObjectLoaderProperties(value: SchemaInputType, tableName: string): objectLoaderOptions | undefined;
|
|
207
|
-
export declare function getTransformedUpdateOp<
|
|
207
|
+
export declare function getTransformedUpdateOp<TEnt extends Ent<TViewer>, TViewer extends Viewer>(value: SchemaInputType, stmt: UpdateOperation<TEnt, TViewer>): TransformedUpdateOperation<TEnt> | null;
|
|
208
208
|
export declare enum ActionOperation {
|
|
209
209
|
Create = 1,
|
|
210
210
|
Edit = 2,
|