@snowtop/ent 0.1.0-alpha10 → 0.1.0-alpha12

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.
@@ -1,6 +1,6 @@
1
1
  import { ID, Data, Ent, Viewer, EntConstructor, LoadEntOptions } from "../core/base";
2
2
  import { AssocEdgeInputOptions, DataOperation } from "../core/ent";
3
- import { SchemaInputType } from "../schema/schema";
3
+ import { SchemaInputType, FieldInfoMap } from "../schema/schema";
4
4
  import { Changeset, Executor } from "../action/action";
5
5
  import { WriteOperation, Builder, Action } from "../action";
6
6
  export interface OrchestratorOptions<TEnt extends Ent, TData extends Data> {
@@ -14,6 +14,7 @@ export interface OrchestratorOptions<TEnt extends Ent, TData extends Data> {
14
14
  schema: SchemaInputType;
15
15
  editedFields(): Map<string, any> | Promise<Map<string, any>>;
16
16
  updateInput?: (data: TData) => void;
17
+ fieldInfo: FieldInfoMap;
17
18
  }
18
19
  interface edgeInputDataOpts {
19
20
  edgeType: string;
@@ -44,6 +45,7 @@ export declare class Orchestrator<TEnt extends Ent, TData extends Data> {
44
45
  private actualOperation;
45
46
  private existingEnt?;
46
47
  private disableTransformations;
48
+ private memoizedGetFields;
47
49
  constructor(options: OrchestratorOptions<TEnt, TData>);
48
50
  private addEdge;
49
51
  setDisableTransformations(val: boolean): void;
@@ -60,12 +62,15 @@ export declare class Orchestrator<TEnt extends Ent, TData extends Data> {
60
62
  private getEntForPrivacyPolicyImpl;
61
63
  private getSQLStatementOperation;
62
64
  private getWriteOpForSQLStamentOp;
63
- getPossibleUnsafeEntForPrivacy(): Promise<TEnt | undefined>;
65
+ getPossibleUnsafeEntForPrivacy(): Promise<TEnt>;
66
+ getEditedData(): Promise<Data>;
64
67
  private getFieldsInfo;
65
68
  private validate;
66
69
  private triggers;
67
70
  private validators;
68
71
  private isBuilder;
72
+ private getInputKey;
73
+ private getStorageKey;
69
74
  private getFieldsWithDefaultValues;
70
75
  private hasData;
71
76
  private transformFieldValue;
@@ -1,13 +1,16 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.EntChangeset = exports.Orchestrator = exports.edgeDirection = void 0;
4
7
  const ent_1 = require("../core/ent");
5
8
  const schema_1 = require("../schema/schema");
6
9
  const action_1 = require("../action");
7
- const camel_case_1 = require("camel-case");
8
10
  const privacy_1 = require("../core/privacy");
9
11
  const executor_1 = require("./executor");
10
12
  const logger_1 = require("../core/logger");
13
+ const memoizee_1 = __importDefault(require("memoizee"));
11
14
  var edgeDirection;
12
15
  (function (edgeDirection) {
13
16
  edgeDirection[edgeDirection["inboundEdge"] = 0] = "inboundEdge";
@@ -63,6 +66,7 @@ class Orchestrator {
63
66
  this.viewer = options.viewer;
64
67
  this.actualOperation = this.options.operation;
65
68
  this.existingEnt = this.options.builder.existingEnt;
69
+ this.memoizedGetFields = (0, memoizee_1.default)(this.getFieldsInfo.bind(this));
66
70
  }
67
71
  addEdge(edge, op) {
68
72
  this.edgeSet.add(edge.edgeType);
@@ -269,9 +273,18 @@ class Orchestrator {
269
273
  if (this.actualOperation !== action_1.WriteOperation.Insert) {
270
274
  return this.existingEnt;
271
275
  }
272
- const { editedData } = await this.getFieldsInfo();
276
+ const { editedData } = await this.memoizedGetFields();
273
277
  return this.getEntForPrivacyPolicyImpl(editedData);
274
278
  }
279
+ // this gets the fields that were explicitly set plus any default or transformed values
280
+ // mainly exists to get default fields e.g. default id to be used in triggers
281
+ // NOTE: this API may change in the future
282
+ // doesn't work to get ids for autoincrement keys
283
+ async getEditedData() {
284
+ const { editedData } = await this.memoizedGetFields();
285
+ return editedData;
286
+ }
287
+ // Note: this is memoized. call memoizedGetFields instead
275
288
  async getFieldsInfo() {
276
289
  const action = this.options.action;
277
290
  const builder = this.options.builder;
@@ -290,7 +303,7 @@ class Orchestrator {
290
303
  throw new Error(`existing ent required with operation ${this.actualOperation}`);
291
304
  }
292
305
  }
293
- const { schemaFields, editedData } = await this.getFieldsInfo();
306
+ const { schemaFields, editedData } = await this.memoizedGetFields();
294
307
  const action = this.options.action;
295
308
  const builder = this.options.builder;
296
309
  // this runs in following phases:
@@ -348,6 +361,12 @@ class Orchestrator {
348
361
  isBuilder(val) {
349
362
  return val.placeholderID !== undefined;
350
363
  }
364
+ getInputKey(k) {
365
+ return this.options.fieldInfo[k].inputKey;
366
+ }
367
+ getStorageKey(k) {
368
+ return this.options.fieldInfo[k].dbCol;
369
+ }
351
370
  async getFieldsWithDefaultValues(builder, schemaFields, editedFields, action) {
352
371
  let data = {};
353
372
  let defaultData = {};
@@ -386,9 +405,8 @@ class Orchestrator {
386
405
  if (field.format) {
387
406
  val = field.format(transformed.data[k]);
388
407
  }
389
- let dbKey = (0, schema_1.getStorageKey)(field, k);
390
- data[dbKey] = val;
391
- this.defaultFieldsByTSName[(0, camel_case_1.camelCase)(k)] = val;
408
+ data[this.getStorageKey(k)] = val;
409
+ this.defaultFieldsByTSName[this.getInputKey(k)] = val;
392
410
  // hmm do we need this?
393
411
  // TODO how to do this for local tests?
394
412
  // this.defaultFieldsByFieldName[k] = val;
@@ -404,7 +422,7 @@ class Orchestrator {
404
422
  for (const [fieldName, field] of schemaFields) {
405
423
  let value = editedFields.get(fieldName);
406
424
  let defaultValue = undefined;
407
- let dbKey = (0, schema_1.getStorageKey)(field, fieldName);
425
+ let dbKey = this.getStorageKey(fieldName);
408
426
  if (value === undefined) {
409
427
  if (this.actualOperation === action_1.WriteOperation.Insert) {
410
428
  if (field.defaultToViewerOnCreate && field.defaultValueOnCreate) {
@@ -432,8 +450,7 @@ class Orchestrator {
432
450
  updateInput = true;
433
451
  defaultData[dbKey] = defaultValue;
434
452
  this.defaultFieldsByFieldName[fieldName] = defaultValue;
435
- // TODO related to #510. we need this logic to be consistent so do this all in TypeScript or get it from go somehow
436
- this.defaultFieldsByTSName[(0, camel_case_1.camelCase)(fieldName)] = defaultValue;
453
+ this.defaultFieldsByTSName[this.getInputKey(fieldName)] = defaultValue;
437
454
  }
438
455
  }
439
456
  // if there's data changing, add data
@@ -494,8 +511,7 @@ class Orchestrator {
494
511
  }
495
512
  }
496
513
  if (field.format) {
497
- // TODO this could be async e.g. password. handle this better
498
- value = await Promise.resolve(field.format(value));
514
+ value = await field.format(value);
499
515
  }
500
516
  }
501
517
  return value;
@@ -514,7 +530,7 @@ class Orchestrator {
514
530
  // null allowed
515
531
  value = this.defaultFieldsByFieldName[fieldName];
516
532
  }
517
- let dbKey = (0, schema_1.getStorageKey)(field, fieldName);
533
+ let dbKey = this.getStorageKey(fieldName);
518
534
  value = await this.transformFieldValue(fieldName, field, dbKey, value);
519
535
  if (value !== undefined) {
520
536
  data[dbKey] = value;
@@ -527,7 +543,7 @@ class Orchestrator {
527
543
  for (const fieldName in this.defaultFieldsByFieldName) {
528
544
  const defaultValue = this.defaultFieldsByFieldName[fieldName];
529
545
  let field = schemaFields.get(fieldName);
530
- let dbKey = (0, schema_1.getStorageKey)(field, fieldName);
546
+ let dbKey = this.getStorageKey(fieldName);
531
547
  // no value, let's just default
532
548
  if (data[dbKey] === undefined) {
533
549
  const value = await this.transformFieldValue(fieldName, field, dbKey, defaultValue);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@snowtop/ent",
3
- "version": "0.1.0-alpha10",
3
+ "version": "0.1.0-alpha12",
4
4
  "description": "snowtop ent framework",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -4,6 +4,13 @@ import { Clause } from "../core/clause";
4
4
  export declare type FieldMap = {
5
5
  [key: string]: Field;
6
6
  };
7
+ interface FieldInfo {
8
+ dbCol: string;
9
+ inputKey: string;
10
+ }
11
+ export declare type FieldInfoMap = {
12
+ [key: string]: FieldInfo;
13
+ };
7
14
  export default interface Schema {
8
15
  fields: FieldMap | Field[];
9
16
  tableName?: string;
@@ -185,8 +192,11 @@ export interface SchemaConstructor {
185
192
  export declare type SchemaInputType = Schema | SchemaConstructor;
186
193
  export declare function getSchema(value: SchemaInputType): Schema;
187
194
  export declare function getFields(value: SchemaInputType): Map<string, Field>;
195
+ /**
196
+ * @deprecated should only be used by tests
197
+ */
188
198
  export declare function getStorageKey(field: Field, fieldName: string): string;
189
- export declare function getFieldsWithPrivacy(value: SchemaInputType): Map<string, PrivacyPolicy>;
199
+ export declare function getFieldsWithPrivacy(value: SchemaInputType, fieldMap: FieldInfoMap): Map<string, PrivacyPolicy>;
190
200
  export declare function getTransformedReadClause(value: SchemaInputType): Clause | undefined;
191
201
  interface objectLoaderOptions {
192
202
  clause?: () => Clause | undefined;
package/schema/schema.js CHANGED
@@ -86,12 +86,15 @@ function getFields(value) {
86
86
  return m;
87
87
  }
88
88
  exports.getFields = getFields;
89
+ /**
90
+ * @deprecated should only be used by tests
91
+ */
89
92
  function getStorageKey(field, fieldName) {
90
93
  return field.storageKey || (0, snake_case_1.snakeCase)(fieldName);
91
94
  }
92
95
  exports.getStorageKey = getStorageKey;
93
96
  // returns a mapping of storage key to field privacy
94
- function getFieldsWithPrivacy(value) {
97
+ function getFieldsWithPrivacy(value, fieldMap) {
95
98
  const schema = getSchema(value);
96
99
  function addFields(fields) {
97
100
  if (Array.isArray(fields)) {
@@ -111,7 +114,11 @@ function getFieldsWithPrivacy(value) {
111
114
  else {
112
115
  privacyPolicy = field.privacyPolicy;
113
116
  }
114
- m.set(getStorageKey(field, name), privacyPolicy);
117
+ const info = fieldMap[name];
118
+ if (!info) {
119
+ throw new Error(`field with name ${name} not passed in fieldMap`);
120
+ }
121
+ m.set(info.dbCol, privacyPolicy);
115
122
  }
116
123
  }
117
124
  }
@@ -128,7 +135,11 @@ function getFieldsWithPrivacy(value) {
128
135
  else {
129
136
  privacyPolicy = field.privacyPolicy;
130
137
  }
131
- m.set(getStorageKey(field, name), privacyPolicy);
138
+ const info = fieldMap[name];
139
+ if (!info) {
140
+ throw new Error(`field with name ${name} not passed in fieldMap`);
141
+ }
142
+ m.set(info.dbCol, privacyPolicy);
132
143
  }
133
144
  }
134
145
  }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,142 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
21
+ var __importDefault = (this && this.__importDefault) || function (mod) {
22
+ return (mod && mod.__esModule) ? mod : { "default": mod };
23
+ };
24
+ Object.defineProperty(exports, "__esModule", { value: true });
25
+ const glob_1 = require("glob");
26
+ const path = __importStar(require("path"));
27
+ const fs = __importStar(require("fs"));
28
+ const compilerOptions_1 = require("../tsc/compilerOptions");
29
+ const typescript_1 = __importDefault(require("typescript"));
30
+ const ast_1 = require("../tsc/ast");
31
+ const child_process_1 = require("child_process");
32
+ // src/ent/generated and src/graphql/generated
33
+ function transformPath(old) {
34
+ const parts = old.split(path.sep);
35
+ if (parts.length < 3) {
36
+ return;
37
+ }
38
+ const changedParts = parts
39
+ .slice(0, 2)
40
+ .concat("generated")
41
+ .concat(parts.slice(2).filter((v) => v !== "generated"));
42
+ const newFile = changedParts.join(path.sep);
43
+ return { changedParts, newFile };
44
+ }
45
+ function moveFiles(files) {
46
+ files.forEach((file) => {
47
+ const conv = transformPath(file);
48
+ if (!conv) {
49
+ return;
50
+ }
51
+ const { changedParts, newFile } = conv;
52
+ if (file === newFile) {
53
+ return;
54
+ }
55
+ // check if directory exists, if not, create recursive dir
56
+ const p = changedParts.slice(0, changedParts.length - 1).join(path.sep);
57
+ const statInfo = fs.statSync(p, { throwIfNoEntry: false });
58
+ if (!statInfo) {
59
+ fs.mkdirSync(p, {
60
+ recursive: true,
61
+ });
62
+ }
63
+ // move file to new location
64
+ fs.renameSync(file, newFile);
65
+ });
66
+ }
67
+ function updateImports(files, target, cwd) {
68
+ files.forEach((file) => {
69
+ let { contents, sourceFile } = (0, compilerOptions_1.createSourceFile)(target, file);
70
+ let nodes = [];
71
+ let updated = false;
72
+ typescript_1.default.forEachChild(sourceFile, function (node) {
73
+ let dirPath = path.join(cwd, file, "..");
74
+ if (typescript_1.default.isImportDeclaration(node)) {
75
+ const conv = isGeneratedPath(node, sourceFile, dirPath);
76
+ if (!conv) {
77
+ nodes.push({ node });
78
+ return;
79
+ }
80
+ updated = true;
81
+ const newImportPath = path.relative(dirPath, conv.newFile);
82
+ const v = (0, ast_1.updateImportPath)(contents, node, sourceFile, newImportPath);
83
+ nodes.push({ rawString: v });
84
+ }
85
+ else {
86
+ nodes.push({ node });
87
+ }
88
+ });
89
+ let newContents = "";
90
+ for (const node of nodes) {
91
+ if (node.node) {
92
+ newContents += node.node.getFullText(sourceFile);
93
+ }
94
+ else if (node.rawString) {
95
+ newContents += node.rawString;
96
+ }
97
+ else {
98
+ throw new Error(`malformed node with no node or rawString`);
99
+ }
100
+ }
101
+ if (updated) {
102
+ fs.writeFileSync(file, newContents);
103
+ }
104
+ });
105
+ }
106
+ function main() {
107
+ const entFiles = glob_1.glob.sync("src/ent/**/generated/**/**.ts");
108
+ const graphqlFiles = glob_1.glob.sync("src/graphql/**/generated/**/**.ts");
109
+ moveFiles(entFiles);
110
+ moveFiles(graphqlFiles);
111
+ const target = (0, compilerOptions_1.getTargetFromCurrentDir)();
112
+ const entImportFiles = glob_1.glob.sync("src/ent/**/*.ts", {
113
+ ignore: ["**/generated/**", "node_modules/**"],
114
+ });
115
+ const graphqlImportFiles = glob_1.glob.sync("src/graphql/**/*.ts", {
116
+ ignore: ["**/generated/**", "node_modules/**"],
117
+ });
118
+ const cwd = process.cwd();
119
+ updateImports(entImportFiles, target, cwd);
120
+ updateImports(graphqlImportFiles, target, cwd);
121
+ (0, child_process_1.execSync)("prettier src/ent/*.ts --write");
122
+ (0, child_process_1.execSync)("prettier src/graphql/*.ts --write");
123
+ }
124
+ function isGeneratedPath(node, sourceFile, dirPath) {
125
+ const text = node.moduleSpecifier.getText(sourceFile).slice(1, -1);
126
+ // it's relative and has generated in there, continue
127
+ if (!((text.startsWith("..") || text.startsWith("./")) &&
128
+ text.indexOf("/generated") !== -1)) {
129
+ return;
130
+ }
131
+ const oldPath = path.join(dirPath, text);
132
+ const relFromRoot = path.relative(".", oldPath);
133
+ const conv = transformPath(relFromRoot);
134
+ if (!conv) {
135
+ return;
136
+ }
137
+ if (relFromRoot === conv.newFile) {
138
+ return;
139
+ }
140
+ return conv;
141
+ }
142
+ main();
@@ -29,9 +29,8 @@ const ast_1 = require("../tsc/ast");
29
29
  const child_process_1 = require("child_process");
30
30
  const fs = __importStar(require("fs"));
31
31
  async function main() {
32
- const options = (0, compilerOptions_1.readCompilerOptions)(".");
33
32
  let files = glob_1.glob.sync("src/ent/*.ts");
34
- const target = (0, compilerOptions_1.getTarget)(options.target?.toString());
33
+ const target = (0, compilerOptions_1.getTargetFromCurrentDir)();
35
34
  files.forEach((file) => {
36
35
  let { contents, sourceFile } = (0, compilerOptions_1.createSourceFile)(target, file);
37
36
  let traversed = false;
@@ -30,10 +30,8 @@ const child_process_1 = require("child_process");
30
30
  const path_1 = __importDefault(require("path"));
31
31
  const ast_1 = require("../tsc/ast");
32
32
  async function main() {
33
- // this assumes this is being run from root of directory
34
- const options = (0, compilerOptions_1.readCompilerOptions)(".");
35
33
  let files = glob_1.glob.sync("src/schema/*.ts");
36
- const target = (0, compilerOptions_1.getTarget)(options.target?.toString());
34
+ const target = (0, compilerOptions_1.getTargetFromCurrentDir)();
37
35
  // filter to only event.ts e.g. for comments and whitespace...
38
36
  // files = files.filter((f) => f.endsWith("event.ts"));
39
37
  files.forEach((file) => {
@@ -3,6 +3,7 @@ import { Orchestrator } from "../action/orchestrator";
3
3
  import { Action, Builder, Changeset, WriteOperation, Validator, Trigger, Observer } from "../action";
4
4
  import { FieldMap, Schema } from "../schema";
5
5
  import { SchemaConfig } from "../schema/base_schema";
6
+ import { FieldInfoMap } from "../schema/schema";
6
7
  export declare class User implements Ent {
7
8
  viewer: Viewer;
8
9
  data: Data;
@@ -66,6 +67,7 @@ export declare function getBuilderSchemaFromFields<T extends Ent>(fields: FieldM
66
67
  export declare function getBuilderSchemaTZFromFields<T extends Ent>(fields: FieldMap, ent: EntConstructor<T>): BuilderSchema<T>;
67
68
  export declare function getSchemaName(value: BuilderSchema<Ent>): string;
68
69
  export declare function getTableName(value: BuilderSchema<Ent>): string;
70
+ export declare function getFieldInfo(value: BuilderSchema<Ent>): FieldInfoMap;
69
71
  export declare class SimpleBuilder<T extends Ent> implements Builder<T> {
70
72
  viewer: Viewer;
71
73
  private schema;
@@ -77,6 +79,7 @@ export declare class SimpleBuilder<T extends Ent> implements Builder<T> {
77
79
  fields: Map<string, any>;
78
80
  nodeType: string;
79
81
  constructor(viewer: Viewer, schema: BuilderSchema<T>, fields: Map<string, any>, operation?: WriteOperation, existingEnt?: T | undefined, action?: Action<T, SimpleBuilder<T>, Data> | undefined);
82
+ updateInput(input: Data): void;
80
83
  build(): Promise<Changeset<T>>;
81
84
  editedEnt(): Promise<T | null>;
82
85
  editedEntX(): Promise<T>;
@@ -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,6 +131,18 @@ 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
148
  constructor(viewer, schema, fields, operation = action_1.WriteOperation.Insert, existingEnt = undefined, action) {
@@ -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,25 @@ class SimpleBuilder {
189
204
  }
190
205
  return m;
191
206
  },
192
- updateInput: (input) => {
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
+ updateInput(input) {
211
+ const knownFields = (0, schema_1.getFields)(this.schema);
212
+ for (const k in input) {
213
+ if (knownFields.has(k)) {
214
+ this.fields.set(k, input[k]);
215
+ }
216
+ else {
217
+ // related to #510. we do camelCase to pass fields in here but fields may be snakeCase and we want that to pass in tests
218
+ // we do camelCase in
219
+ const sc = (0, snake_case_1.snakeCase)(k);
220
+ if (knownFields.has(sc)) {
221
+ this.fields.set(sc, input[k]);
222
+ }
223
+ }
224
+ }
225
+ }
210
226
  build() {
211
227
  return this.orchestrator.build();
212
228
  }
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;
@@ -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.ES3 | ts.ScriptTarget.ES5 | ts.ScriptTarget.ES2015 | ts.ScriptTarget.ES2016 | ts.ScriptTarget.ES2017 | ts.ScriptTarget.ES2018 | ts.ScriptTarget.ES2019 | ts.ScriptTarget.ES2020 | ts.ScriptTarget.ES2021 | ts.ScriptTarget.ESNext;
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;
@@ -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