@snowtop/ent 0.1.0-alpha10 → 0.1.0-alpha14
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 +27 -25
- package/action/executor.d.ts +3 -3
- package/action/experimental_action.d.ts +21 -20
- package/action/experimental_action.js +1 -1
- package/action/orchestrator.d.ts +23 -16
- package/action/orchestrator.js +31 -14
- package/action/privacy.d.ts +2 -2
- package/core/base.d.ts +20 -20
- package/core/context.d.ts +2 -2
- package/core/ent.d.ts +13 -13
- package/core/loaders/assoc_count_loader.d.ts +2 -2
- package/core/loaders/assoc_edge_loader.d.ts +2 -2
- package/core/loaders/object_loader.d.ts +3 -3
- package/core/loaders/query_loader.d.ts +2 -2
- package/core/loaders/raw_count_loader.d.ts +2 -2
- package/core/privacy.d.ts +24 -24
- package/core/query/assoc_query.d.ts +6 -6
- package/core/query/custom_query.d.ts +5 -5
- package/core/query/query.d.ts +1 -1
- package/core/viewer.d.ts +3 -3
- package/graphql/query/edge_connection.d.ts +9 -9
- package/graphql/query/page_info.d.ts +1 -1
- package/package.json +1 -1
- package/schema/schema.d.ts +15 -5
- package/schema/schema.js +16 -4
- package/scripts/move_generated.d.ts +1 -0
- package/scripts/move_generated.js +142 -0
- package/scripts/transform_code.js +1 -2
- package/scripts/transform_schema.js +1 -3
- package/testutils/builder.d.ts +19 -13
- package/testutils/builder.js +43 -20
- package/testutils/fake_data/fake_contact.d.ts +1 -1
- package/testutils/fake_data/fake_contact.js +2 -1
- package/testutils/fake_data/fake_event.d.ts +1 -1
- package/testutils/fake_data/fake_event.js +2 -1
- package/testutils/fake_data/fake_user.d.ts +2 -2
- package/testutils/fake_data/fake_user.js +2 -1
- package/testutils/fake_data/user_query.d.ts +2 -2
- package/testutils/fake_log.d.ts +3 -3
- package/tsc/ast.d.ts +1 -0
- package/tsc/ast.js +24 -1
- package/tsc/compilerOptions.d.ts +2 -1
- package/tsc/compilerOptions.js +6 -1
package/testutils/builder.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.SimpleAction = exports.SimpleBuilder = exports.getTableName = exports.getSchemaName = exports.getBuilderSchemaTZFromFields = exports.getBuilderSchemaFromFields = exports.getBuilderSchema = exports.Address = exports.Message = exports.Group = exports.Contact = exports.Event = exports.User = void 0;
|
|
6
|
+
exports.SimpleAction = exports.SimpleBuilder = exports.getFieldInfo = exports.getTableName = exports.getSchemaName = exports.getBuilderSchemaTZFromFields = exports.getBuilderSchemaFromFields = exports.getBuilderSchema = exports.Address = exports.Message = exports.Group = exports.Contact = exports.Event = exports.User = void 0;
|
|
7
7
|
const privacy_1 = require("../core/privacy");
|
|
8
8
|
const orchestrator_1 = require("../action/orchestrator");
|
|
9
9
|
const action_1 = require("../action");
|
|
@@ -15,6 +15,7 @@ const loaders_1 = require("../core/loaders");
|
|
|
15
15
|
const convert_1 = require("../core/convert");
|
|
16
16
|
const camel_case_1 = require("camel-case");
|
|
17
17
|
const base_schema_1 = require("../schema/base_schema");
|
|
18
|
+
const schema_2 = require("../schema/schema");
|
|
18
19
|
class User {
|
|
19
20
|
constructor(viewer, data) {
|
|
20
21
|
this.viewer = viewer;
|
|
@@ -130,9 +131,21 @@ exports.getTableName = getTableName;
|
|
|
130
131
|
function randomNum() {
|
|
131
132
|
return Math.random().toString(10).substring(2);
|
|
132
133
|
}
|
|
134
|
+
function getFieldInfo(value) {
|
|
135
|
+
const fields = (0, schema_1.getFields)(value);
|
|
136
|
+
let ret = {};
|
|
137
|
+
for (const [k, f] of fields) {
|
|
138
|
+
ret[k] = {
|
|
139
|
+
dbCol: (0, schema_2.getStorageKey)(f, k),
|
|
140
|
+
inputKey: (0, camel_case_1.camelCase)(k),
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
return ret;
|
|
144
|
+
}
|
|
145
|
+
exports.getFieldInfo = getFieldInfo;
|
|
133
146
|
// reuses orchestrator and standard things
|
|
134
147
|
class SimpleBuilder {
|
|
135
|
-
constructor(viewer, schema, fields, operation = action_1.WriteOperation.Insert, existingEnt
|
|
148
|
+
constructor(viewer, schema, fields, operation = action_1.WriteOperation.Insert, existingEnt, action) {
|
|
136
149
|
this.viewer = viewer;
|
|
137
150
|
this.schema = schema;
|
|
138
151
|
this.operation = operation;
|
|
@@ -162,11 +175,13 @@ class SimpleBuilder {
|
|
|
162
175
|
this.ent = schema.ent;
|
|
163
176
|
const tableName = getTableName(schema);
|
|
164
177
|
this.nodeType = (0, camel_case_1.camelCase)(schema.ent.name);
|
|
178
|
+
const fieldInfo = getFieldInfo(schema);
|
|
165
179
|
this.orchestrator = new orchestrator_1.Orchestrator({
|
|
166
180
|
viewer: this.viewer,
|
|
167
181
|
operation: operation,
|
|
168
182
|
tableName: tableName,
|
|
169
183
|
key,
|
|
184
|
+
fieldInfo,
|
|
170
185
|
loaderOptions: {
|
|
171
186
|
loaderFactory: new loaders_1.ObjectLoaderFactory({
|
|
172
187
|
tableName: tableName,
|
|
@@ -176,7 +191,7 @@ class SimpleBuilder {
|
|
|
176
191
|
ent: schema.ent,
|
|
177
192
|
tableName: tableName,
|
|
178
193
|
fields: [],
|
|
179
|
-
fieldPrivacy: (0, schema_1.getFieldsWithPrivacy)(schema),
|
|
194
|
+
fieldPrivacy: (0, schema_1.getFieldsWithPrivacy)(schema, fieldInfo),
|
|
180
195
|
},
|
|
181
196
|
builder: this,
|
|
182
197
|
action: action,
|
|
@@ -189,24 +204,32 @@ class SimpleBuilder {
|
|
|
189
204
|
}
|
|
190
205
|
return m;
|
|
191
206
|
},
|
|
192
|
-
updateInput: (
|
|
193
|
-
const knownFields = (0, schema_1.getFields)(this.schema);
|
|
194
|
-
for (const k in input) {
|
|
195
|
-
if (knownFields.has(k)) {
|
|
196
|
-
this.fields.set(k, input[k]);
|
|
197
|
-
}
|
|
198
|
-
else {
|
|
199
|
-
// related to #510. we do camelCase to pass fields in here but fields may be snakeCase and we want that to pass in tests
|
|
200
|
-
// we do camelCase in
|
|
201
|
-
const sc = (0, snake_case_1.snakeCase)(k);
|
|
202
|
-
if (knownFields.has(sc)) {
|
|
203
|
-
this.fields.set(sc, input[k]);
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
},
|
|
207
|
+
updateInput: this.updateInput.bind(this),
|
|
208
208
|
});
|
|
209
209
|
}
|
|
210
|
+
getInput() {
|
|
211
|
+
let ret = {};
|
|
212
|
+
for (const [k, v] of this.fields) {
|
|
213
|
+
ret[k] = v;
|
|
214
|
+
}
|
|
215
|
+
return ret;
|
|
216
|
+
}
|
|
217
|
+
updateInput(input) {
|
|
218
|
+
const knownFields = (0, schema_1.getFields)(this.schema);
|
|
219
|
+
for (const k in input) {
|
|
220
|
+
if (knownFields.has(k)) {
|
|
221
|
+
this.fields.set(k, input[k]);
|
|
222
|
+
}
|
|
223
|
+
else {
|
|
224
|
+
// related to #510. we do camelCase to pass fields in here but fields may be snakeCase and we want that to pass in tests
|
|
225
|
+
// we do camelCase in
|
|
226
|
+
const sc = (0, snake_case_1.snakeCase)(k);
|
|
227
|
+
if (knownFields.has(sc)) {
|
|
228
|
+
this.fields.set(sc, input[k]);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|
|
210
233
|
build() {
|
|
211
234
|
return this.orchestrator.build();
|
|
212
235
|
}
|
|
@@ -231,7 +254,7 @@ class SimpleBuilder {
|
|
|
231
254
|
}
|
|
232
255
|
exports.SimpleBuilder = SimpleBuilder;
|
|
233
256
|
class SimpleAction {
|
|
234
|
-
constructor(viewer, schema, fields, operation = action_1.WriteOperation.Insert, existingEnt
|
|
257
|
+
constructor(viewer, schema, fields, operation = action_1.WriteOperation.Insert, existingEnt) {
|
|
235
258
|
this.viewer = viewer;
|
|
236
259
|
this.fields = fields;
|
|
237
260
|
this.validators = [];
|
|
@@ -28,6 +28,6 @@ export interface ContactCreateInput {
|
|
|
28
28
|
emailAddress: string;
|
|
29
29
|
userID: ID;
|
|
30
30
|
}
|
|
31
|
-
export declare function getContactBuilder(viewer: Viewer, input: ContactCreateInput): SimpleBuilder<FakeContact>;
|
|
31
|
+
export declare function getContactBuilder(viewer: Viewer, input: ContactCreateInput): SimpleBuilder<FakeContact, null>;
|
|
32
32
|
export declare function createContact(viewer: Viewer, input: ContactCreateInput): Promise<void>;
|
|
33
33
|
export declare const contactLoader: ObjectLoaderFactory<unknown>;
|
|
@@ -9,6 +9,7 @@ const const_1 = require("./const");
|
|
|
9
9
|
const test_db_1 = require("../db/test_db");
|
|
10
10
|
const loaders_1 = require("../../core/loaders");
|
|
11
11
|
const convert_1 = require("../../core/convert");
|
|
12
|
+
const action_1 = require("../../action");
|
|
12
13
|
class FakeContact {
|
|
13
14
|
constructor(viewer, data) {
|
|
14
15
|
this.viewer = viewer;
|
|
@@ -77,7 +78,7 @@ function getContactBuilder(viewer, input) {
|
|
|
77
78
|
//To lock in the value of Date now incase of advanceTo/advanceBy
|
|
78
79
|
m.set("createdAt", new Date());
|
|
79
80
|
m.set("updatedAt", new Date());
|
|
80
|
-
return new builder_1.SimpleBuilder(viewer, exports.FakeContactSchema, m);
|
|
81
|
+
return new builder_1.SimpleBuilder(viewer, exports.FakeContactSchema, m, action_1.WriteOperation.Insert, null);
|
|
81
82
|
}
|
|
82
83
|
exports.getContactBuilder = getContactBuilder;
|
|
83
84
|
async function createContact(viewer, input) {
|
|
@@ -31,5 +31,5 @@ export interface EventCreateInput {
|
|
|
31
31
|
description?: string | null;
|
|
32
32
|
userID: ID;
|
|
33
33
|
}
|
|
34
|
-
export declare function getEventBuilder(viewer: Viewer, input: EventCreateInput): SimpleBuilder<FakeEvent>;
|
|
34
|
+
export declare function getEventBuilder(viewer: Viewer, input: EventCreateInput): SimpleBuilder<FakeEvent, null>;
|
|
35
35
|
export declare function createEvent(viewer: Viewer, input: EventCreateInput): Promise<void>;
|
|
@@ -9,6 +9,7 @@ const const_1 = require("./const");
|
|
|
9
9
|
const test_db_1 = require("../db/test_db");
|
|
10
10
|
const loaders_1 = require("../../core/loaders");
|
|
11
11
|
const convert_1 = require("../../core/convert");
|
|
12
|
+
const action_1 = require("../../action");
|
|
12
13
|
class FakeEvent {
|
|
13
14
|
constructor(viewer, data) {
|
|
14
15
|
this.viewer = viewer;
|
|
@@ -86,7 +87,7 @@ function getEventBuilder(viewer, input) {
|
|
|
86
87
|
for (const key in input) {
|
|
87
88
|
m.set(key, input[key]);
|
|
88
89
|
}
|
|
89
|
-
return new builder_1.SimpleBuilder(viewer, exports.FakeEventSchema, m);
|
|
90
|
+
return new builder_1.SimpleBuilder(viewer, exports.FakeEventSchema, m, action_1.WriteOperation.Insert, null);
|
|
90
91
|
}
|
|
91
92
|
exports.getEventBuilder = getEventBuilder;
|
|
92
93
|
async function createEvent(viewer, input) {
|
|
@@ -40,8 +40,8 @@ export interface UserCreateInput {
|
|
|
40
40
|
password: string | null;
|
|
41
41
|
}
|
|
42
42
|
export declare type UserEditInput = Partial<UserCreateInput>;
|
|
43
|
-
export declare function getUserBuilder(viewer: Viewer, input: UserCreateInput): import("../builder").SimpleBuilder<FakeUser>;
|
|
44
|
-
export declare function getUserAction(viewer: Viewer, input: UserCreateInput): SimpleAction<FakeUser>;
|
|
43
|
+
export declare function getUserBuilder(viewer: Viewer, input: UserCreateInput): import("../builder").SimpleBuilder<FakeUser, null>;
|
|
44
|
+
export declare function getUserAction(viewer: Viewer, input: UserCreateInput): SimpleAction<FakeUser, null>;
|
|
45
45
|
export declare function createUser(viewer: Viewer, input: UserCreateInput): Promise<FakeUser>;
|
|
46
46
|
export declare const userLoader: ObjectLoaderFactory<unknown>;
|
|
47
47
|
export declare const userEmailLoader: ObjectLoaderFactory<unknown>;
|
|
@@ -11,6 +11,7 @@ const viewer_1 = require("../../core/viewer");
|
|
|
11
11
|
const test_db_1 = require("../db/test_db");
|
|
12
12
|
const loaders_1 = require("../../core/loaders");
|
|
13
13
|
const convert_1 = require("../../core/convert");
|
|
14
|
+
const action_1 = require("../../action");
|
|
14
15
|
class ViewerWithAccessToken extends viewer_1.IDViewer {
|
|
15
16
|
constructor(viewerID, opts) {
|
|
16
17
|
super(viewerID, opts);
|
|
@@ -110,7 +111,7 @@ function getUserAction(viewer, input) {
|
|
|
110
111
|
for (const key in input) {
|
|
111
112
|
m.set(key, input[key]);
|
|
112
113
|
}
|
|
113
|
-
const action = new builder_1.SimpleAction(viewer, exports.FakeUserSchema, m);
|
|
114
|
+
const action = new builder_1.SimpleAction(viewer, exports.FakeUserSchema, m, action_1.WriteOperation.Insert, null);
|
|
114
115
|
action.viewerForEntLoad = (data) => {
|
|
115
116
|
// load the created ent using a VC of the newly created user.
|
|
116
117
|
return new viewer_1.IDViewer(data.id);
|
|
@@ -53,7 +53,7 @@ export declare class UserToFriendRequestsQuery extends AssocEdgeQueryBase<FakeUs
|
|
|
53
53
|
}
|
|
54
54
|
export declare class UserToIncomingFriendRequestsQuery extends AssocEdgeQueryBase<FakeUser, FakeUser, AssocEdge> {
|
|
55
55
|
constructor(viewer: Viewer, src: EdgeQuerySource<FakeUser, FakeUser>);
|
|
56
|
-
getPrivacyPolicy(): import("../../core/base").PrivacyPolicy<Ent
|
|
56
|
+
getPrivacyPolicy(): import("../../core/base").PrivacyPolicy<Ent<Viewer<Ent<any> | null, ID | null>>, Viewer<Ent<any> | null, ID | null>>;
|
|
57
57
|
sourceEnt(id: ID): Promise<FakeUser | null>;
|
|
58
58
|
static query(viewer: Viewer, src: EdgeQuerySource<FakeUser, FakeUser>): UserToIncomingFriendRequestsQuery;
|
|
59
59
|
queryContacts(): UserToContactsQuery;
|
|
@@ -90,7 +90,7 @@ export declare class UserToEventsInNextWeekQuery extends CustomEdgeQueryBase<Fak
|
|
|
90
90
|
constructor(viewer: Viewer, src: ID | FakeUser);
|
|
91
91
|
static query(viewer: Viewer, src: FakeUser | ID): UserToEventsInNextWeekQuery;
|
|
92
92
|
sourceEnt(id: ID): Promise<FakeUser | null>;
|
|
93
|
-
getPrivacyPolicy(): import("../../core/base").PrivacyPolicy<Ent
|
|
93
|
+
getPrivacyPolicy(): import("../../core/base").PrivacyPolicy<Ent<Viewer<Ent<any> | null, ID | null>>, Viewer<Ent<any> | null, ID | null>>;
|
|
94
94
|
}
|
|
95
95
|
export declare class UserToFollowingQuery extends AssocEdgeQueryBase<FakeUser, Ent, AssocEdge> {
|
|
96
96
|
constructor(viewer: Viewer, src: EdgeQuerySource<FakeUser, FakeUser>);
|
package/testutils/fake_log.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Ent } from "../core/base";
|
|
1
|
+
import { Ent, Viewer } from "../core/base";
|
|
2
2
|
import { Builder } from "./../action";
|
|
3
3
|
export declare class FakeLogger {
|
|
4
4
|
private static logs;
|
|
@@ -8,6 +8,6 @@ export declare class FakeLogger {
|
|
|
8
8
|
static contains(line: string): boolean;
|
|
9
9
|
static clear(): void;
|
|
10
10
|
}
|
|
11
|
-
export declare class EntCreationObserver<
|
|
12
|
-
observe(builder: Builder<
|
|
11
|
+
export declare class EntCreationObserver<TEnt extends Ent<TViewer>, TViewer extends Viewer = Viewer> {
|
|
12
|
+
observe(builder: Builder<TEnt, TViewer>): Promise<void>;
|
|
13
13
|
}
|
package/tsc/ast.d.ts
CHANGED
|
@@ -17,4 +17,5 @@ interface transformOpts {
|
|
|
17
17
|
transform?: transformImportFn;
|
|
18
18
|
}
|
|
19
19
|
export declare function transformImport(fileContents: string, importNode: ts.ImportDeclaration, sourceFile: ts.SourceFile, opts?: transformOpts): string | undefined;
|
|
20
|
+
export declare function updateImportPath(fileContents: string, importNode: ts.ImportDeclaration, sourceFile: ts.SourceFile, newPath: string): string | undefined;
|
|
20
21
|
export {};
|
package/tsc/ast.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.transformImport = exports.getClassInfo = exports.getPreText = void 0;
|
|
6
|
+
exports.updateImportPath = exports.transformImport = exports.getClassInfo = exports.getPreText = void 0;
|
|
7
7
|
const typescript_1 = __importDefault(require("typescript"));
|
|
8
8
|
function getPreText(fileContents, node, sourceFile) {
|
|
9
9
|
return fileContents.substring(node.getFullStart(), node.getStart(sourceFile));
|
|
@@ -129,3 +129,26 @@ function transformImport(fileContents, importNode, sourceFile, opts) {
|
|
|
129
129
|
'";');
|
|
130
130
|
}
|
|
131
131
|
exports.transformImport = transformImport;
|
|
132
|
+
function updateImportPath(fileContents, importNode, sourceFile, newPath) {
|
|
133
|
+
const comment = getPreText(fileContents, importNode, sourceFile);
|
|
134
|
+
// all this copied from above...
|
|
135
|
+
const importText = importNode.importClause?.getText(sourceFile) || "";
|
|
136
|
+
const start = importText.indexOf("{");
|
|
137
|
+
const end = importText.lastIndexOf("}");
|
|
138
|
+
if (start === -1 || end === -1) {
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
const imports = importText
|
|
142
|
+
.substring(start + 1, end)
|
|
143
|
+
// .trim()
|
|
144
|
+
.split(",");
|
|
145
|
+
return (comment +
|
|
146
|
+
"import " +
|
|
147
|
+
importText.substring(0, start + 1) +
|
|
148
|
+
Array.from(imports).join(", ") +
|
|
149
|
+
importText.substring(end) +
|
|
150
|
+
' from "' +
|
|
151
|
+
newPath +
|
|
152
|
+
'";');
|
|
153
|
+
}
|
|
154
|
+
exports.updateImportPath = updateImportPath;
|
package/tsc/compilerOptions.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import ts from "typescript";
|
|
2
2
|
export declare function readCompilerOptions(filePath: string): ts.CompilerOptions;
|
|
3
|
-
export declare function getTarget(target?: string): ts.ScriptTarget
|
|
3
|
+
export declare function getTarget(target?: string): ts.ScriptTarget;
|
|
4
|
+
export declare function getTargetFromCurrentDir(): ts.ScriptTarget;
|
|
4
5
|
export declare function createSourceFile(target: ts.ScriptTarget, file: string): {
|
|
5
6
|
contents: string;
|
|
6
7
|
sourceFile: ts.SourceFile;
|
package/tsc/compilerOptions.js
CHANGED
|
@@ -22,7 +22,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
22
22
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
23
|
};
|
|
24
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
exports.createSourceFile = exports.getTarget = exports.readCompilerOptions = void 0;
|
|
25
|
+
exports.createSourceFile = exports.getTargetFromCurrentDir = exports.getTarget = exports.readCompilerOptions = void 0;
|
|
26
26
|
const fs = __importStar(require("fs"));
|
|
27
27
|
const json5_1 = __importDefault(require("json5"));
|
|
28
28
|
const typescript_1 = __importDefault(require("typescript"));
|
|
@@ -86,6 +86,11 @@ function getTarget(target) {
|
|
|
86
86
|
}
|
|
87
87
|
}
|
|
88
88
|
exports.getTarget = getTarget;
|
|
89
|
+
function getTargetFromCurrentDir() {
|
|
90
|
+
const options = readCompilerOptions(".");
|
|
91
|
+
return getTarget(options.target?.toString());
|
|
92
|
+
}
|
|
93
|
+
exports.getTargetFromCurrentDir = getTargetFromCurrentDir;
|
|
89
94
|
function createSourceFile(target, file) {
|
|
90
95
|
let contents = fs.readFileSync(file).toString();
|
|
91
96
|
// go through the file and print everything back if not starting immediately after other position
|