@snowtop/ent 0.0.33 → 0.0.34
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 -0
- package/core/base.d.ts +6 -0
- package/package.json +1 -1
- package/schema/field.js +9 -12
- package/schema/schema.d.ts +4 -3
- package/testutils/builder.d.ts +1 -0
- package/testutils/builder.js +2 -0
package/action/action.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ export interface Builder<T extends Ent> {
|
|
|
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;
|
package/core/base.d.ts
CHANGED
|
@@ -92,6 +92,12 @@ export interface LoadEntOptions<T extends Ent> extends LoadableEntOptions<T>, Se
|
|
|
92
92
|
export interface LoadCustomEntOptions<T extends Ent> extends SelectBaseDataOptions {
|
|
93
93
|
ent: EntConstructor<T>;
|
|
94
94
|
}
|
|
95
|
+
export interface LoaderInfo {
|
|
96
|
+
tableName: string;
|
|
97
|
+
fields: string[];
|
|
98
|
+
nodeType: string;
|
|
99
|
+
loaderFactory: LoaderFactory<any, Data | null>;
|
|
100
|
+
}
|
|
95
101
|
export interface EditEntOptions<T extends Ent> extends LoadableEntOptions<T>, EditRowOptions {
|
|
96
102
|
}
|
|
97
103
|
declare enum privacyResult {
|
package/package.json
CHANGED
package/schema/field.js
CHANGED
|
@@ -22,7 +22,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
22
22
|
exports.UUIDListType = exports.EnumListType = exports.DateListType = exports.TimetzListType = exports.TimeListType = exports.TimestamptzListType = exports.TimestampListType = exports.BooleanListType = exports.BigIntegerListType = exports.FloatListType = exports.IntegerListType = exports.IntListType = exports.StringListType = exports.ListField = exports.EnumType = exports.EnumField = exports.DateType = exports.DateField = exports.TimetzType = exports.TimeType = exports.TimeField = exports.leftPad = exports.TimestamptzType = exports.TimestampType = exports.TimestampField = exports.StringType = exports.StringField = exports.BooleanType = exports.BooleanField = exports.FloatType = exports.FloatField = exports.BigIntegerType = exports.BigIntegerField = exports.IntegerType = exports.IntegerField = exports.UUIDType = exports.UUIDField = exports.BaseField = void 0;
|
|
23
23
|
const luxon_1 = require("luxon");
|
|
24
24
|
const snake_case_1 = require("snake-case");
|
|
25
|
-
const camel_case_1 = require("camel-case");
|
|
26
25
|
const db_1 = __importStar(require("../core/db"));
|
|
27
26
|
const schema_1 = require("./schema");
|
|
28
27
|
const util_1 = require("util");
|
|
@@ -84,8 +83,8 @@ class UUIDField extends BaseField {
|
|
|
84
83
|
}
|
|
85
84
|
}
|
|
86
85
|
if (options.fieldEdge?.enforceSchema &&
|
|
87
|
-
!options.fieldEdge.
|
|
88
|
-
throw new Error(`cannot enforceSchema if
|
|
86
|
+
!options.fieldEdge.getLoaderInfoFromSchema) {
|
|
87
|
+
throw new Error(`cannot enforceSchema if getLoaderInfoFromSchema wasn't passed in`);
|
|
89
88
|
}
|
|
90
89
|
}
|
|
91
90
|
isBuilder(val) {
|
|
@@ -95,19 +94,17 @@ class UUIDField extends BaseField {
|
|
|
95
94
|
if (!this.options.fieldEdge?.enforceSchema) {
|
|
96
95
|
return true;
|
|
97
96
|
}
|
|
98
|
-
|
|
99
|
-
const
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
if (!loadRowOptions) {
|
|
103
|
-
throw new Error(`couldn't get loaderOptions for ${f}`);
|
|
97
|
+
const getLoaderInfo = this.options.fieldEdge.getLoaderInfoFromSchema;
|
|
98
|
+
const loaderInfo = getLoaderInfo(this.options.fieldEdge.schema);
|
|
99
|
+
if (!loaderInfo) {
|
|
100
|
+
throw new Error(`couldn't get loaderInfo for ${this.options.fieldEdge.schema}`);
|
|
104
101
|
}
|
|
105
102
|
if (this.isBuilder(val)) {
|
|
106
|
-
// if builder, the
|
|
107
|
-
return val.
|
|
103
|
+
// if builder, the nodeType of the builder and the nodeType of the loaderInfo should match
|
|
104
|
+
return val.nodeType === loaderInfo.nodeType;
|
|
108
105
|
}
|
|
109
106
|
// TODO we need context here to make sure that we hit local cache
|
|
110
|
-
const row = await
|
|
107
|
+
const row = await loaderInfo.loaderFactory.createLoader().load(val);
|
|
111
108
|
return row !== null;
|
|
112
109
|
}
|
|
113
110
|
}
|
package/schema/schema.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Data, Ent,
|
|
1
|
+
import { Data, Ent, LoaderInfo } from "../core/base";
|
|
2
2
|
import { Builder } from "../action/action";
|
|
3
3
|
export default interface Schema {
|
|
4
4
|
fields: Field[];
|
|
@@ -102,7 +102,7 @@ export interface ForeignKey {
|
|
|
102
102
|
disableIndex?: boolean;
|
|
103
103
|
disableBuilderType?: boolean;
|
|
104
104
|
}
|
|
105
|
-
declare type
|
|
105
|
+
declare type getLoaderInfoFn = (type: string) => LoaderInfo;
|
|
106
106
|
export interface InverseFieldEdge {
|
|
107
107
|
name: string;
|
|
108
108
|
edgeConstName?: string;
|
|
@@ -113,7 +113,7 @@ export interface FieldEdge {
|
|
|
113
113
|
schema: string;
|
|
114
114
|
inverseEdge?: string | InverseFieldEdge;
|
|
115
115
|
enforceSchema?: boolean;
|
|
116
|
-
|
|
116
|
+
getLoaderInfoFromSchema?: getLoaderInfoFn;
|
|
117
117
|
disableBuilderType?: boolean;
|
|
118
118
|
}
|
|
119
119
|
export interface FieldOptions {
|
|
@@ -171,6 +171,7 @@ export interface ActionField {
|
|
|
171
171
|
nullable?: boolean | NullableListOptions;
|
|
172
172
|
list?: boolean;
|
|
173
173
|
actionName?: string;
|
|
174
|
+
excludedFields?: string[];
|
|
174
175
|
}
|
|
175
176
|
export interface Action {
|
|
176
177
|
operation: ActionOperation;
|
package/testutils/builder.d.ts
CHANGED
|
@@ -71,6 +71,7 @@ export declare class SimpleBuilder<T extends Ent> implements Builder<T> {
|
|
|
71
71
|
placeholderID: ID;
|
|
72
72
|
orchestrator: Orchestrator<T>;
|
|
73
73
|
fields: Map<string, any>;
|
|
74
|
+
nodeType: string;
|
|
74
75
|
constructor(viewer: Viewer, schema: BuilderSchema<T>, fields: Map<string, any>, operation?: WriteOperation, existingEnt?: T | undefined, action?: Action<T> | undefined);
|
|
75
76
|
build(): Promise<Changeset<T>>;
|
|
76
77
|
editedEnt(): Promise<T | null>;
|
package/testutils/builder.js
CHANGED
|
@@ -13,6 +13,7 @@ const pluralize_1 = __importDefault(require("pluralize"));
|
|
|
13
13
|
const snake_case_1 = require("snake-case");
|
|
14
14
|
const loaders_1 = require("../core/loaders");
|
|
15
15
|
const convert_1 = require("../core/convert");
|
|
16
|
+
const camel_case_1 = require("camel-case");
|
|
16
17
|
class User {
|
|
17
18
|
constructor(viewer, data) {
|
|
18
19
|
this.viewer = viewer;
|
|
@@ -126,6 +127,7 @@ class SimpleBuilder {
|
|
|
126
127
|
}
|
|
127
128
|
this.ent = schema.ent;
|
|
128
129
|
const tableName = getTableName(schema);
|
|
130
|
+
this.nodeType = (0, camel_case_1.camelCase)(schema.ent.name);
|
|
129
131
|
this.orchestrator = new orchestrator_1.Orchestrator({
|
|
130
132
|
viewer: this.viewer,
|
|
131
133
|
operation: operation,
|