@snowtop/ent 0.1.0-alpha138 → 0.1.0-alpha139
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 +8 -1
- package/action/executor.d.ts +16 -3
- package/action/executor.js +67 -12
- package/action/index.d.ts +1 -1
- package/action/operations.d.ts +125 -0
- package/action/operations.js +684 -0
- package/action/orchestrator.d.ts +13 -7
- package/action/orchestrator.js +109 -42
- package/core/base.d.ts +7 -1
- package/core/db.js +2 -0
- package/core/ent.d.ts +1 -84
- package/core/ent.js +20 -509
- package/index.d.ts +2 -1
- package/index.js +7 -5
- package/package.json +2 -2
- package/parse_schema/parse.js +1 -0
- package/schema/base_schema.d.ts +2 -0
- package/schema/base_schema.js +2 -0
- package/schema/schema.d.ts +2 -1
- package/testutils/action/complex_schemas.d.ts +1 -1
- package/testutils/builder.d.ts +3 -0
- package/testutils/builder.js +6 -0
- package/testutils/db/temp_db.d.ts +2 -1
- package/testutils/db/temp_db.js +41 -5
package/schema/schema.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Data, Ent, LoaderInfo, PrivacyPolicy, Viewer } from "../core/base";
|
|
2
2
|
import { Builder, Changeset } from "../action/action";
|
|
3
3
|
import { Clause } from "../core/clause";
|
|
4
|
-
import { AssocEdgeInput } from "../
|
|
4
|
+
import { AssocEdgeInput } from "../action/operations";
|
|
5
5
|
export declare type FieldMap = {
|
|
6
6
|
[key: string]: Field;
|
|
7
7
|
};
|
|
@@ -39,6 +39,7 @@ export default interface Schema {
|
|
|
39
39
|
indices?: Index[];
|
|
40
40
|
hideFromGraphQL?: boolean;
|
|
41
41
|
customGraphQLInterfaces?: string[];
|
|
42
|
+
supportUpsert?: boolean;
|
|
42
43
|
}
|
|
43
44
|
export interface AssocEdge {
|
|
44
45
|
name: string;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Ent, ID, Viewer, Data } from "../../core/base";
|
|
2
|
-
import { DataOperation } from "../../
|
|
2
|
+
import { DataOperation } from "../../action/operations";
|
|
3
3
|
import { Action, Builder, Executor, WriteOperation, Trigger, Observer, TriggerReturn } from "../../action/action";
|
|
4
4
|
import { EdgeInputData } from "../../action/orchestrator";
|
|
5
5
|
import { User, Group, Message, Contact, SimpleBuilder, BuilderSchema, SimpleAction, BaseEnt } from "../../testutils/builder";
|
package/testutils/builder.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { FieldMap, Schema } from "../schema";
|
|
|
5
5
|
import { SchemaConfig, EntSchema } from "../schema/base_schema";
|
|
6
6
|
import { FieldInfoMap } from "../schema/schema";
|
|
7
7
|
import { Clause } from "src/core/clause";
|
|
8
|
+
import { ChangesetOptions } from "../action/action";
|
|
8
9
|
export declare class BaseEnt {
|
|
9
10
|
viewer: Viewer;
|
|
10
11
|
readonly data: Data;
|
|
@@ -76,6 +77,7 @@ export declare class SimpleBuilder<T extends Ent, TExistingEnt extends TMaybleNu
|
|
|
76
77
|
storeData(k: string, v: any): void;
|
|
77
78
|
getStoredData(k: string): any;
|
|
78
79
|
build(): Promise<Changeset>;
|
|
80
|
+
buildWithOptions_BETA(options: ChangesetOptions): Promise<Changeset>;
|
|
79
81
|
editedEnt(): Promise<T | null>;
|
|
80
82
|
editedEntX(): Promise<T>;
|
|
81
83
|
save(): Promise<void>;
|
|
@@ -98,6 +100,7 @@ export declare class SimpleAction<T extends Ent, TExistingEnt extends TMaybleNul
|
|
|
98
100
|
getPrivacyPolicy(): PrivacyPolicy<Ent<Viewer<Ent<any> | null, ID | null>>, Viewer<Ent<any> | null, ID | null>>;
|
|
99
101
|
getInput(): Data;
|
|
100
102
|
changeset(): Promise<Changeset>;
|
|
103
|
+
changesetWithOptions_BETA(options: ChangesetOptions): Promise<Changeset>;
|
|
101
104
|
valid(): Promise<boolean>;
|
|
102
105
|
validX(): Promise<void>;
|
|
103
106
|
validWithErrors(): Promise<Error[]>;
|
package/testutils/builder.js
CHANGED
|
@@ -244,6 +244,9 @@ class SimpleBuilder {
|
|
|
244
244
|
build() {
|
|
245
245
|
return this.orchestrator.build();
|
|
246
246
|
}
|
|
247
|
+
buildWithOptions_BETA(options) {
|
|
248
|
+
return this.orchestrator.buildWithOptions_BETA(options);
|
|
249
|
+
}
|
|
247
250
|
async editedEnt() {
|
|
248
251
|
return await this.orchestrator.editedEnt();
|
|
249
252
|
}
|
|
@@ -292,6 +295,9 @@ class SimpleAction {
|
|
|
292
295
|
changeset() {
|
|
293
296
|
return this.builder.build();
|
|
294
297
|
}
|
|
298
|
+
changesetWithOptions_BETA(options) {
|
|
299
|
+
return this.builder.buildWithOptions_BETA(options);
|
|
300
|
+
}
|
|
295
301
|
valid() {
|
|
296
302
|
return this.builder.orchestrator.valid();
|
|
297
303
|
}
|
|
@@ -21,6 +21,7 @@ interface Column extends SchemaItem {
|
|
|
21
21
|
}
|
|
22
22
|
interface Constraint extends SchemaItem {
|
|
23
23
|
generate(): string;
|
|
24
|
+
postCreate?(): boolean;
|
|
24
25
|
}
|
|
25
26
|
interface Index extends SchemaItem {
|
|
26
27
|
generate(): string;
|
|
@@ -94,7 +95,7 @@ export declare class TempDB {
|
|
|
94
95
|
create(...tables: CoreConcept[]): Promise<void>;
|
|
95
96
|
}
|
|
96
97
|
export declare function assoc_edge_config_table(): Table;
|
|
97
|
-
export declare function assoc_edge_table(name: string, global?: boolean): Table;
|
|
98
|
+
export declare function assoc_edge_table(name: string, global?: boolean, unique_edge?: boolean): Table;
|
|
98
99
|
interface setupOptions {
|
|
99
100
|
disableDeleteAfterEachTest?: boolean;
|
|
100
101
|
}
|
package/testutils/db/temp_db.js
CHANGED
|
@@ -64,6 +64,20 @@ function check(name, condition) {
|
|
|
64
64
|
};
|
|
65
65
|
}
|
|
66
66
|
exports.check = check;
|
|
67
|
+
function unique(name, cols, tableName) {
|
|
68
|
+
return {
|
|
69
|
+
name,
|
|
70
|
+
generate() {
|
|
71
|
+
if (db_1.Dialect.SQLite === db_1.default.getDialect()) {
|
|
72
|
+
return `UNIQUE (${cols.join(",")})`;
|
|
73
|
+
}
|
|
74
|
+
return `ALTER TABLE ${tableName} ADD CONSTRAINT ${name} UNIQUE (${cols.join(", ")});`;
|
|
75
|
+
},
|
|
76
|
+
postCreate() {
|
|
77
|
+
return db_1.Dialect.Postgres === db_1.default.getDialect();
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
}
|
|
67
81
|
function isPostCreateIndex(s) {
|
|
68
82
|
return (s.postCreate !== undefined &&
|
|
69
83
|
s.postCreate());
|
|
@@ -478,6 +492,7 @@ class TempDB {
|
|
|
478
492
|
await db_1.default.getInstance().endPool();
|
|
479
493
|
// drop db
|
|
480
494
|
await this.client.query(`DROP DATABASE ${this.db}`);
|
|
495
|
+
// console.log(this.db);
|
|
481
496
|
await this.client.end();
|
|
482
497
|
}
|
|
483
498
|
getDB() {
|
|
@@ -522,10 +537,22 @@ function assoc_edge_config_table() {
|
|
|
522
537
|
exports.assoc_edge_config_table = assoc_edge_config_table;
|
|
523
538
|
// if global flag is true, add any column from testEdgeGlobalSchema
|
|
524
539
|
// up to caller to set/clear that as needed
|
|
525
|
-
function assoc_edge_table(name, global) {
|
|
526
|
-
const
|
|
527
|
-
|
|
528
|
-
|
|
540
|
+
function assoc_edge_table(name, global, unique_edge) {
|
|
541
|
+
const items = [
|
|
542
|
+
uuid("id1"),
|
|
543
|
+
text("id1_type"),
|
|
544
|
+
// same as in assoc_edge_config_table
|
|
545
|
+
text("edge_type"),
|
|
546
|
+
uuid("id2"),
|
|
547
|
+
text("id2_type"),
|
|
548
|
+
timestamptz("time"),
|
|
549
|
+
text("data", { nullable: true }),
|
|
550
|
+
primaryKey(`${name}_pkey`, ["id1", "id2", "edge_type"]),
|
|
551
|
+
];
|
|
552
|
+
if (unique_edge) {
|
|
553
|
+
items.push(unique(`${name}_unique_id1_edge_type`, ["id1", "edge_type"], name));
|
|
554
|
+
}
|
|
555
|
+
const t = table(name, ...items);
|
|
529
556
|
if (global) {
|
|
530
557
|
for (const k in test_edge_global_schema_1.testEdgeGlobalSchema.extraEdgeFields) {
|
|
531
558
|
const col = getColumnFromField(k, test_edge_global_schema_1.testEdgeGlobalSchema.extraEdgeFields[k], db_1.Dialect.Postgres);
|
|
@@ -607,6 +634,7 @@ function getSchemaTable(schema, dialect) {
|
|
|
607
634
|
for (const [fieldName, field] of fields) {
|
|
608
635
|
items.push(getColumnFromField(fieldName, field, dialect));
|
|
609
636
|
}
|
|
637
|
+
const tableName = (0, builder_1.getTableName)(schema);
|
|
610
638
|
if (schema.constraints) {
|
|
611
639
|
for (const constraint of schema.constraints) {
|
|
612
640
|
switch (constraint.type) {
|
|
@@ -628,10 +656,15 @@ function getSchemaTable(schema, dialect) {
|
|
|
628
656
|
}
|
|
629
657
|
items.push(check(constraint.name, constraint.condition));
|
|
630
658
|
break;
|
|
659
|
+
case schema_1.ConstraintType.Unique:
|
|
660
|
+
items.push(unique(constraint.name, constraint.columns, tableName));
|
|
661
|
+
break;
|
|
662
|
+
default:
|
|
663
|
+
throw new Error(`unknown constraint type ${constraint.type}`);
|
|
631
664
|
}
|
|
632
665
|
}
|
|
633
666
|
}
|
|
634
|
-
return table(
|
|
667
|
+
return table(tableName, ...items);
|
|
635
668
|
}
|
|
636
669
|
exports.getSchemaTable = getSchemaTable;
|
|
637
670
|
function getColumnForDbType(t, dialect) {
|
|
@@ -708,6 +741,9 @@ function buildOpts(f) {
|
|
|
708
741
|
if (f.serverDefault) {
|
|
709
742
|
ret.default = f.serverDefault;
|
|
710
743
|
}
|
|
744
|
+
if (f.unique) {
|
|
745
|
+
ret.unique = true;
|
|
746
|
+
}
|
|
711
747
|
return ret;
|
|
712
748
|
}
|
|
713
749
|
function storageKey(fieldName, f) {
|