@snowtop/ent 0.1.0-alpha6 → 0.1.0-alpha60

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.
Files changed (111) hide show
  1. package/action/action.d.ts +28 -24
  2. package/action/executor.d.ts +4 -4
  3. package/action/executor.js +2 -2
  4. package/action/experimental_action.d.ts +29 -22
  5. package/action/experimental_action.js +29 -6
  6. package/action/orchestrator.d.ts +44 -16
  7. package/action/orchestrator.js +287 -73
  8. package/action/privacy.d.ts +2 -2
  9. package/core/base.d.ts +26 -22
  10. package/core/base.js +16 -0
  11. package/core/clause.d.ts +53 -3
  12. package/core/clause.js +347 -5
  13. package/core/config.d.ts +26 -0
  14. package/core/config.js +17 -0
  15. package/core/context.d.ts +2 -2
  16. package/core/context.js +2 -2
  17. package/core/convert.d.ts +1 -1
  18. package/core/db.d.ts +3 -4
  19. package/core/db.js +2 -0
  20. package/core/ent.d.ts +35 -24
  21. package/core/ent.js +223 -60
  22. package/core/loaders/assoc_count_loader.d.ts +2 -2
  23. package/core/loaders/assoc_count_loader.js +6 -1
  24. package/core/loaders/assoc_edge_loader.d.ts +3 -3
  25. package/core/loaders/assoc_edge_loader.js +5 -4
  26. package/core/loaders/index_loader.js +1 -0
  27. package/core/loaders/loader.js +5 -5
  28. package/core/loaders/object_loader.d.ts +10 -5
  29. package/core/loaders/object_loader.js +58 -4
  30. package/core/loaders/query_loader.d.ts +2 -2
  31. package/core/loaders/raw_count_loader.d.ts +2 -2
  32. package/core/logger.d.ts +1 -1
  33. package/core/logger.js +1 -0
  34. package/core/privacy.d.ts +25 -25
  35. package/core/privacy.js +3 -0
  36. package/core/query/assoc_query.d.ts +6 -6
  37. package/core/query/custom_query.d.ts +5 -5
  38. package/core/query/query.d.ts +1 -1
  39. package/core/query/shared_assoc_test.d.ts +1 -1
  40. package/core/query/shared_assoc_test.js +17 -5
  41. package/core/query/shared_test.d.ts +3 -0
  42. package/core/query/shared_test.js +95 -17
  43. package/core/viewer.d.ts +4 -3
  44. package/core/viewer.js +4 -0
  45. package/graphql/builtins/connection.js +3 -3
  46. package/graphql/builtins/edge.js +2 -2
  47. package/graphql/builtins/node.js +1 -1
  48. package/graphql/graphql.d.ts +3 -2
  49. package/graphql/graphql.js +30 -23
  50. package/graphql/node_resolver.d.ts +0 -1
  51. package/graphql/query/connection_type.js +6 -6
  52. package/graphql/query/edge_connection.d.ts +9 -9
  53. package/graphql/query/page_info.d.ts +1 -1
  54. package/graphql/query/page_info.js +4 -4
  55. package/graphql/query/shared_assoc_test.js +2 -2
  56. package/graphql/scalars/time.d.ts +1 -1
  57. package/index.d.ts +16 -1
  58. package/index.js +19 -5
  59. package/package.json +3 -3
  60. package/parse_schema/parse.d.ts +24 -5
  61. package/parse_schema/parse.js +90 -8
  62. package/schema/base_schema.d.ts +36 -1
  63. package/schema/base_schema.js +51 -2
  64. package/schema/field.d.ts +34 -6
  65. package/schema/field.js +68 -3
  66. package/schema/index.d.ts +2 -2
  67. package/schema/index.js +8 -1
  68. package/schema/schema.d.ts +87 -2
  69. package/schema/schema.js +127 -5
  70. package/scripts/custom_graphql.js +127 -16
  71. package/scripts/{transform_schema.d.ts → migrate_v0.1.d.ts} +0 -0
  72. package/scripts/migrate_v0.1.js +36 -0
  73. package/scripts/read_schema.js +25 -2
  74. package/testutils/builder.d.ts +36 -22
  75. package/testutils/builder.js +110 -13
  76. package/testutils/context/test_context.d.ts +2 -2
  77. package/testutils/context/test_context.js +7 -1
  78. package/testutils/db/{test_db.d.ts → temp_db.d.ts} +17 -4
  79. package/testutils/db/{test_db.js → temp_db.js} +75 -19
  80. package/testutils/ent-graphql-tests/index.d.ts +2 -0
  81. package/testutils/ent-graphql-tests/index.js +26 -17
  82. package/testutils/fake_data/fake_contact.d.ts +5 -9
  83. package/testutils/fake_data/fake_contact.js +17 -21
  84. package/testutils/fake_data/fake_event.d.ts +5 -9
  85. package/testutils/fake_data/fake_event.js +24 -28
  86. package/testutils/fake_data/fake_user.d.ts +6 -10
  87. package/testutils/fake_data/fake_user.js +25 -29
  88. package/testutils/fake_data/test_helpers.d.ts +2 -2
  89. package/testutils/fake_data/test_helpers.js +6 -6
  90. package/testutils/fake_data/user_query.d.ts +2 -2
  91. package/testutils/fake_log.d.ts +3 -3
  92. package/testutils/parse_sql.js +4 -0
  93. package/testutils/test_edge_global_schema.d.ts +15 -0
  94. package/testutils/test_edge_global_schema.js +58 -0
  95. package/testutils/write.d.ts +2 -2
  96. package/testutils/write.js +3 -3
  97. package/tsc/ast.d.ts +44 -0
  98. package/tsc/ast.js +267 -0
  99. package/tsc/compilerOptions.d.ts +6 -0
  100. package/tsc/compilerOptions.js +40 -1
  101. package/tsc/move_generated.d.ts +1 -0
  102. package/tsc/move_generated.js +160 -0
  103. package/tsc/transform.d.ts +21 -0
  104. package/tsc/transform.js +167 -0
  105. package/tsc/transform_action.d.ts +22 -0
  106. package/tsc/transform_action.js +179 -0
  107. package/tsc/transform_ent.d.ts +17 -0
  108. package/tsc/transform_ent.js +59 -0
  109. package/tsc/transform_schema.d.ts +27 -0
  110. package/tsc/transform_schema.js +379 -0
  111. package/scripts/transform_schema.js +0 -288
@@ -1,8 +1,23 @@
1
- import { Data, Ent, LoaderInfo } from "../core/base";
1
+ import { Data, Ent, LoaderInfo, PrivacyPolicy, Viewer } from "../core/base";
2
2
  import { Builder } from "../action/action";
3
+ import { Clause } from "../core/clause";
4
+ import { AssocEdgeInput } from "../core/ent";
3
5
  export declare type FieldMap = {
4
6
  [key: string]: Field;
5
7
  };
8
+ interface FieldInfo {
9
+ dbCol: string;
10
+ inputKey: string;
11
+ }
12
+ export declare type FieldInfoMap = {
13
+ [key: string]: FieldInfo;
14
+ };
15
+ export interface GlobalSchema {
16
+ edges?: Edge[];
17
+ extraEdgeFields?: FieldMap;
18
+ transformEdgeRead?: () => Clause;
19
+ transformEdgeWrite?: (stmt: EdgeUpdateOperation) => TransformedEdgeUpdateOperation | null;
20
+ }
6
21
  export default interface Schema {
7
22
  fields: FieldMap | Field[];
8
23
  tableName?: string;
@@ -61,7 +76,37 @@ export declare type Edge = AssocEdge;
61
76
  export interface Pattern {
62
77
  name: string;
63
78
  fields: FieldMap | Field[];
79
+ disableMixin?: boolean;
64
80
  edges?: Edge[];
81
+ transformRead?: () => Clause;
82
+ transformWrite?: <T extends Ent>(stmt: UpdateOperation<T>) => TransformedUpdateOperation<T> | null;
83
+ transformsDelete?: boolean;
84
+ transformsInsert?: boolean;
85
+ transformsUpdate?: boolean;
86
+ }
87
+ export declare enum SQLStatementOperation {
88
+ Insert = "insert",
89
+ Update = "update",
90
+ Delete = "delete"
91
+ }
92
+ export interface EdgeUpdateOperation {
93
+ op: SQLStatementOperation;
94
+ edge: AssocEdgeInput;
95
+ }
96
+ export interface TransformedEdgeUpdateOperation {
97
+ op: SQLStatementOperation;
98
+ data?: Data;
99
+ }
100
+ export interface UpdateOperation<TEnt extends Ent<TViewer>, TViewer extends Viewer = Viewer> {
101
+ op: SQLStatementOperation;
102
+ builder: Builder<TEnt, TViewer>;
103
+ input: Data;
104
+ data?: Map<string, any>;
105
+ }
106
+ export interface TransformedUpdateOperation<T extends Ent> {
107
+ op: SQLStatementOperation;
108
+ data?: Data;
109
+ existingEnt?: T | null;
65
110
  }
66
111
  export declare enum DBType {
67
112
  UUID = "UUID",
@@ -77,6 +122,7 @@ export declare enum DBType {
77
122
  JSONB = "JSONB",
78
123
  Enum = "Enum",
79
124
  StringEnum = "StringEnum",
125
+ IntEnum = "IntEnum",
80
126
  Date = "Date",
81
127
  Time = "Time",
82
128
  Timetz = "Timetz",
@@ -85,10 +131,14 @@ export declare enum DBType {
85
131
  export interface ImportType {
86
132
  path: string;
87
133
  type: string;
134
+ [x: string]: any;
88
135
  }
89
136
  declare type EnumMap = {
90
137
  [key: string]: string;
91
138
  };
139
+ declare type IntEnumMap = {
140
+ [key: string]: number;
141
+ };
92
142
  export interface Type {
93
143
  dbType: DBType;
94
144
  listElemType?: Type;
@@ -96,6 +146,8 @@ export interface Type {
96
146
  graphQLType?: string;
97
147
  values?: string[];
98
148
  enumMap?: EnumMap;
149
+ intEnumMap?: IntEnumMap;
150
+ deprecatedIntEnumMap?: IntEnumMap;
99
151
  importType?: ImportType;
100
152
  subFields?: FieldMap;
101
153
  unionFields?: FieldMap;
@@ -121,13 +173,16 @@ export interface FieldEdge {
121
173
  getLoaderInfoFromSchema?: getLoaderInfoFn;
122
174
  disableBuilderType?: boolean;
123
175
  }
176
+ interface PrivateOptions {
177
+ exposeToActions?: boolean;
178
+ }
124
179
  export interface FieldOptions {
125
180
  nullable?: boolean;
126
181
  storageKey?: string;
127
182
  serverDefault?: any;
128
183
  unique?: boolean;
129
184
  hideFromGraphQL?: boolean;
130
- private?: boolean;
185
+ private?: boolean | PrivateOptions;
131
186
  sensitive?: boolean;
132
187
  graphqlName?: string;
133
188
  index?: boolean;
@@ -135,11 +190,13 @@ export interface FieldOptions {
135
190
  fieldEdge?: FieldEdge;
136
191
  primaryKey?: boolean;
137
192
  disableUserEditable?: boolean;
193
+ disableUserGraphQLEditable?: boolean;
138
194
  defaultValueOnCreate?(builder: Builder<Ent>, input: Data): any;
139
195
  defaultToViewerOnCreate?: boolean;
140
196
  defaultValueOnEdit?(builder: Builder<Ent>, input: Data): any;
141
197
  derivedWhenEmbedded?: boolean;
142
198
  polymorphic?: boolean | PolymorphicOptions;
199
+ privacyPolicy?: PrivacyPolicy | (() => PrivacyPolicy);
143
200
  getDerivedFields?(name: string): FieldMap;
144
201
  [x: string]: any;
145
202
  }
@@ -158,7 +215,20 @@ export interface SchemaConstructor {
158
215
  new (): Schema;
159
216
  }
160
217
  export declare type SchemaInputType = Schema | SchemaConstructor;
218
+ export declare function getSchema(value: SchemaInputType): Schema;
161
219
  export declare function getFields(value: SchemaInputType): Map<string, Field>;
220
+ /**
221
+ * @deprecated should only be used by tests
222
+ */
223
+ export declare function getStorageKey(field: Field, fieldName: string): string;
224
+ export declare function getFieldsWithPrivacy(value: SchemaInputType, fieldMap: FieldInfoMap): Map<string, PrivacyPolicy>;
225
+ export declare function getTransformedReadClause(value: SchemaInputType): Clause | undefined;
226
+ interface objectLoaderOptions {
227
+ clause?: () => Clause | undefined;
228
+ instanceKey?: string;
229
+ }
230
+ export declare function getObjectLoaderProperties(value: SchemaInputType, tableName: string): objectLoaderOptions | undefined;
231
+ export declare function getTransformedUpdateOp<TEnt extends Ent<TViewer>, TViewer extends Viewer>(value: SchemaInputType, stmt: UpdateOperation<TEnt, TViewer>): TransformedUpdateOperation<TEnt> | null;
162
232
  export declare enum ActionOperation {
163
233
  Create = 1,
164
234
  Edit = 2,
@@ -201,10 +271,25 @@ export interface Constraint {
201
271
  fkey?: ForeignKeyInfo;
202
272
  condition?: string;
203
273
  }
274
+ export interface FullTextWeight {
275
+ A?: string[];
276
+ B?: string[];
277
+ C?: string[];
278
+ D?: string[];
279
+ }
280
+ export interface FullText {
281
+ generatedColumnName?: string;
282
+ language?: "english" | "french" | "german" | "simple";
283
+ languageColumn?: string;
284
+ indexType?: "gin" | "gist";
285
+ weights?: FullTextWeight;
286
+ }
204
287
  export interface Index {
205
288
  name: string;
206
289
  columns: string[];
207
290
  unique?: boolean;
291
+ fulltext?: FullText;
292
+ indexType?: "gin" | "btree";
208
293
  }
209
294
  export interface ForeignKeyInfo {
210
295
  tableName: string;
package/schema/schema.js CHANGED
@@ -1,6 +1,21 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ConstraintType = exports.optionalField = exports.requiredField = exports.NoFields = exports.ActionOperation = exports.getFields = exports.DBType = void 0;
3
+ exports.ConstraintType = exports.optionalField = exports.requiredField = exports.NoFields = exports.ActionOperation = exports.getTransformedUpdateOp = exports.getObjectLoaderProperties = exports.getTransformedReadClause = exports.getFieldsWithPrivacy = exports.getStorageKey = exports.getFields = exports.getSchema = exports.DBType = exports.SQLStatementOperation = void 0;
4
+ const snake_case_1 = require("snake-case");
5
+ // we also want this transformation to exist on a per-action basis
6
+ // if it exists on an action, we don't do the global schema transformation
7
+ var SQLStatementOperation;
8
+ (function (SQLStatementOperation) {
9
+ // transform insert e.g. to an update based on whatever logic
10
+ SQLStatementOperation["Insert"] = "insert";
11
+ // // transform select e.g. deleted_at. can't change from select to different query type
12
+ // // but can change the query
13
+ // Select = "select",
14
+ // e.g. change updated value
15
+ SQLStatementOperation["Update"] = "update";
16
+ // delete -> update theoretically e.g. deleted_at
17
+ SQLStatementOperation["Delete"] = "delete";
18
+ })(SQLStatementOperation = exports.SQLStatementOperation || (exports.SQLStatementOperation = {}));
4
19
  // we want --strictNullChecks flag so nullable is used to type graphql, ts, db
5
20
  // should eventually generate (boolean | null) etc
6
21
  // supported db types
@@ -20,6 +35,7 @@ var DBType;
20
35
  DBType["JSONB"] = "JSONB";
21
36
  DBType["Enum"] = "Enum";
22
37
  DBType["StringEnum"] = "StringEnum";
38
+ DBType["IntEnum"] = "IntEnum";
23
39
  DBType["Date"] = "Date";
24
40
  DBType["Time"] = "Time";
25
41
  DBType["Timetz"] = "Timetz";
@@ -28,14 +44,17 @@ var DBType;
28
44
  function isSchema(value) {
29
45
  return value.fields !== undefined;
30
46
  }
31
- function getFields(value) {
32
- let schema;
47
+ function getSchema(value) {
33
48
  if (isSchema(value)) {
34
- schema = value;
49
+ return value;
35
50
  }
36
51
  else {
37
- schema = new value();
52
+ return new value();
38
53
  }
54
+ }
55
+ exports.getSchema = getSchema;
56
+ function getFields(value) {
57
+ const schema = getSchema(value);
39
58
  function addFields(fields) {
40
59
  if (Array.isArray(fields)) {
41
60
  for (const field of fields) {
@@ -68,6 +87,109 @@ function getFields(value) {
68
87
  return m;
69
88
  }
70
89
  exports.getFields = getFields;
90
+ /**
91
+ * @deprecated should only be used by tests
92
+ */
93
+ function getStorageKey(field, fieldName) {
94
+ return field.storageKey || (0, snake_case_1.snakeCase)(fieldName);
95
+ }
96
+ exports.getStorageKey = getStorageKey;
97
+ // returns a mapping of storage key to field privacy
98
+ function getFieldsWithPrivacy(value, fieldMap) {
99
+ const schema = getSchema(value);
100
+ function addFields(fields) {
101
+ if (Array.isArray(fields)) {
102
+ for (const field of fields) {
103
+ const name = field.name;
104
+ if (!field.name) {
105
+ throw new Error(`name required`);
106
+ }
107
+ if (field.getDerivedFields !== undefined) {
108
+ addFields(field.getDerivedFields(name));
109
+ }
110
+ if (field.privacyPolicy) {
111
+ let privacyPolicy;
112
+ if (typeof field.privacyPolicy === "function") {
113
+ privacyPolicy = field.privacyPolicy();
114
+ }
115
+ else {
116
+ privacyPolicy = field.privacyPolicy;
117
+ }
118
+ const info = fieldMap[name];
119
+ if (!info) {
120
+ throw new Error(`field with name ${name} not passed in fieldMap`);
121
+ }
122
+ m.set(info.dbCol, privacyPolicy);
123
+ }
124
+ }
125
+ return;
126
+ }
127
+ for (const name in fields) {
128
+ const field = fields[name];
129
+ if (field.getDerivedFields !== undefined) {
130
+ addFields(field.getDerivedFields(name));
131
+ }
132
+ if (field.privacyPolicy) {
133
+ let privacyPolicy;
134
+ if (typeof field.privacyPolicy === "function") {
135
+ privacyPolicy = field.privacyPolicy();
136
+ }
137
+ else {
138
+ privacyPolicy = field.privacyPolicy;
139
+ }
140
+ const info = fieldMap[name];
141
+ if (!info) {
142
+ throw new Error(`field with name ${name} not passed in fieldMap`);
143
+ }
144
+ m.set(info.dbCol, privacyPolicy);
145
+ }
146
+ }
147
+ }
148
+ let m = new Map();
149
+ if (schema.patterns) {
150
+ for (const pattern of schema.patterns) {
151
+ addFields(pattern.fields);
152
+ }
153
+ }
154
+ addFields(schema.fields);
155
+ return m;
156
+ }
157
+ exports.getFieldsWithPrivacy = getFieldsWithPrivacy;
158
+ function getTransformedReadClause(value) {
159
+ const schema = getSchema(value);
160
+ if (!schema.patterns) {
161
+ return;
162
+ }
163
+ for (const p of schema.patterns) {
164
+ // e.g. discarded_at, deleted_at, etc
165
+ if (p.transformRead) {
166
+ // return clause.Eq('deleted_at', null);
167
+ return p.transformRead();
168
+ }
169
+ }
170
+ return;
171
+ }
172
+ exports.getTransformedReadClause = getTransformedReadClause;
173
+ function getObjectLoaderProperties(value, tableName) {
174
+ return {
175
+ clause: () => getTransformedReadClause(value),
176
+ instanceKey: `${tableName}:transformedReadClause`,
177
+ };
178
+ }
179
+ exports.getObjectLoaderProperties = getObjectLoaderProperties;
180
+ function getTransformedUpdateOp(value, stmt) {
181
+ const schema = getSchema(value);
182
+ if (!schema.patterns) {
183
+ return null;
184
+ }
185
+ for (const p of schema.patterns) {
186
+ if (p.transformWrite) {
187
+ return p.transformWrite(stmt);
188
+ }
189
+ }
190
+ return null;
191
+ }
192
+ exports.getTransformedUpdateOp = getTransformedUpdateOp;
71
193
  // this maps to ActionOperation in ent/action.go
72
194
  var ActionOperation;
73
195
  (function (ActionOperation) {
@@ -24,6 +24,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  const glob_1 = __importDefault(require("glob"));
27
+ const json5_1 = __importDefault(require("json5"));
27
28
  const minimist_1 = __importDefault(require("minimist"));
28
29
  const graphql_1 = require("../graphql/graphql");
29
30
  const readline = __importStar(require("readline"));
@@ -53,7 +54,103 @@ async function readInputs() {
53
54
  });
54
55
  });
55
56
  }
56
- async function captureCustom(filePath, filesCsv) {
57
+ function processCustomObjects(l, gqlCapture, input) {
58
+ let m;
59
+ if (input) {
60
+ m = gqlCapture.getCustomInputObjects();
61
+ }
62
+ else {
63
+ m = gqlCapture.getCustomObjects();
64
+ }
65
+ for (const input of l) {
66
+ m.set(input.name, {
67
+ nodeName: input.graphQLName || input.name,
68
+ className: input.name,
69
+ });
70
+ if (input.fields) {
71
+ processCustomFields(input.fields, gqlCapture, input.name);
72
+ }
73
+ }
74
+ }
75
+ function transformArgs(f) {
76
+ return (f.args || []).map((v) => {
77
+ const ret = {
78
+ ...v,
79
+ };
80
+ // duplicated from getType in graphql.ts
81
+ if ((0, graphql_1.isCustomType)(ret.type)) {
82
+ ret.type = v.type.type;
83
+ (0, graphql_1.addCustomType)(v.type);
84
+ }
85
+ // scalar types not supported for now
86
+ ret.tsType = graphql_1.knownAllowedNames.get(v.type);
87
+ return ret;
88
+ });
89
+ }
90
+ function transformResultType(f) {
91
+ return f.resultType
92
+ ? [
93
+ {
94
+ name: "",
95
+ type: f.resultType,
96
+ tsType: graphql_1.knownAllowedNames.get(f.resultType),
97
+ list: f.list,
98
+ nullable: f.nullable,
99
+ },
100
+ ]
101
+ : [];
102
+ }
103
+ function processTopLevel(l, l2) {
104
+ for (const custom of l) {
105
+ l2.push({
106
+ nodeName: custom.class,
107
+ functionName: custom.functionName || custom.name,
108
+ gqlName: custom.graphQLName || custom.name,
109
+ fieldType: custom.fieldType,
110
+ args: transformArgs(custom),
111
+ results: transformResultType(custom),
112
+ });
113
+ }
114
+ }
115
+ function processCustomFields(fields, gqlCapture, nodeName) {
116
+ const m = gqlCapture.getCustomFields();
117
+ let results = [];
118
+ for (const f of fields) {
119
+ results.push({
120
+ nodeName: nodeName,
121
+ gqlName: f.graphQLName || f.name,
122
+ functionName: f.functionName || f.name,
123
+ fieldType: f.fieldType,
124
+ args: transformArgs(f),
125
+ results: transformResultType(f),
126
+ });
127
+ }
128
+ m.set(nodeName, results);
129
+ }
130
+ async function captureCustom(filePath, filesCsv, jsonPath, gqlCapture) {
131
+ if (jsonPath !== undefined) {
132
+ let json = json5_1.default.parse(fs.readFileSync(jsonPath, {
133
+ encoding: "utf8",
134
+ }));
135
+ if (json.fields) {
136
+ for (const k in json.fields) {
137
+ processCustomFields(json.fields[k], gqlCapture, k);
138
+ }
139
+ }
140
+ if (json.inputs) {
141
+ processCustomObjects(json.inputs, gqlCapture, true);
142
+ }
143
+ if (json.objects) {
144
+ processCustomObjects(json.objects, gqlCapture);
145
+ }
146
+ if (json.queries) {
147
+ processTopLevel(json.queries, gqlCapture.getCustomQueries());
148
+ }
149
+ if (json.mutations) {
150
+ processTopLevel(json.mutations, gqlCapture.getCustomMutations());
151
+ }
152
+ return;
153
+ }
57
154
  if (filesCsv !== undefined) {
58
155
  let files = filesCsv.split(",");
59
156
  for (let i = 0; i < files.length; i++) {
@@ -138,7 +235,11 @@ async function main() {
138
235
  // if this list grows too long, need to build this into golang types and passed here
139
236
  // TODO foreign non-scalars eventually
140
237
  (0, graphql_1.addCustomType)({
141
- importPath: "../graphql/scalars/time",
238
+ importPath: MODULE_PATH,
239
+ // for go tests...
240
+ // TODO need a flag that only does this for go tests
241
+ // breaks when running locally sometimes...
242
+ secondaryImportPath: "../graphql/scalars/time",
142
243
  type: "GraphQLTime",
143
244
  });
144
245
  (0, graphql_1.addCustomType)({
@@ -153,15 +254,25 @@ async function main() {
153
254
  if (!gqlPath) {
154
255
  throw new Error("could not find graphql path");
155
256
  }
156
- const r = require(gqlPath);
157
- if (!r.GQLCapture) {
158
- throw new Error("could not find GQLCapture in module");
257
+ // use different variable so that we use the correct GQLCapture as needed
258
+ // for local dev, get the one from the file system. otherwise, get the one
259
+ // from node_modules
260
+ let gqlCapture;
261
+ if (process.env.LOCAL_SCRIPT_PATH) {
262
+ const r = require("../graphql/graphql");
263
+ gqlCapture = r.GQLCapture;
264
+ }
265
+ else {
266
+ const r = require(gqlPath);
267
+ if (!r.GQLCapture) {
268
+ throw new Error("could not find GQLCapture in module");
269
+ }
270
+ gqlCapture = r.GQLCapture;
271
+ gqlCapture.enable(true);
159
272
  }
160
- const GQLCapture = r.GQLCapture;
161
- GQLCapture.enable(true);
162
273
  const [inputsRead, _, imports] = await Promise.all([
163
274
  readInputs(),
164
- captureCustom(options.path, options.files),
275
+ captureCustom(options.path, options.files, options.json_path, gqlCapture),
165
276
  parseImports(options.path),
166
277
  ]);
167
278
  const { nodes, nodesMap } = inputsRead;
@@ -172,14 +283,14 @@ async function main() {
172
283
  }
173
284
  return result;
174
285
  }
175
- GQLCapture.resolve(nodes);
176
- let args = fromMap(GQLCapture.getCustomArgs());
177
- let inputs = fromMap(GQLCapture.getCustomInputObjects());
178
- let fields = GQLCapture.getProcessedCustomFields();
179
- let queries = GQLCapture.getProcessedCustomQueries();
180
- let mutations = GQLCapture.getProcessedCustomMutations();
181
- let objects = fromMap(GQLCapture.getCustomObjects());
182
- let customTypes = fromMap(GQLCapture.getCustomTypes());
286
+ gqlCapture.resolve(nodes);
287
+ let args = fromMap(gqlCapture.getCustomArgs());
288
+ let inputs = fromMap(gqlCapture.getCustomInputObjects());
289
+ let fields = gqlCapture.getProcessedCustomFields();
290
+ let queries = gqlCapture.getProcessedCustomQueries();
291
+ let mutations = gqlCapture.getProcessedCustomMutations();
292
+ let objects = fromMap(gqlCapture.getCustomObjects());
293
+ let customTypes = fromMap(gqlCapture.getCustomTypes());
183
294
  let classes = {};
184
295
  let allFiles = {};
185
296
  const buildClasses2 = (args) => {
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const transform_1 = require("../tsc/transform");
7
+ const transform_schema_1 = require("../tsc/transform_schema");
8
+ const transform_ent_1 = require("../tsc/transform_ent");
9
+ const move_generated_1 = require("../tsc/move_generated");
10
+ const transform_action_1 = require("../tsc/transform_action");
11
+ const minimist_1 = __importDefault(require("minimist"));
12
+ const ast_1 = require("../tsc/ast");
13
+ // todo-sqlite
14
+ // ts-node-script --swc --project ./tsconfig.json -r tsconfig-paths/register ../../ts/src/scripts/migrate_v0.1.ts --transform_schema --old_base_class BaseEntTodoSchema --new_schema_class TodoEntSchema --transform_path src/schema/patterns/base
15
+ function main() {
16
+ const customInfo = (0, ast_1.getCustomInfo)();
17
+ const options = (0, minimist_1.default)(process.argv.slice(2));
18
+ // install 0.1.x dependencies
19
+ // maybe provide options to make this easier if someone wants to do this in steps to see what's happening
20
+ if (options.move_generated) {
21
+ (0, move_generated_1.moveGenerated)(customInfo.relativeImports);
22
+ }
23
+ // codegen write-all --disable-custom-graphql
24
+ if (options.transform_schema) {
25
+ (0, transform_1.transform)(new transform_schema_1.TransformSchema(customInfo.relativeImports, options.old_base_class, options.new_schema_class, options.transform_path));
26
+ }
27
+ // codegen write-all --disable-custom-graphql
28
+ if (options.transform_ent) {
29
+ (0, transform_1.transform)(new transform_ent_1.TransformEnt());
30
+ }
31
+ if (options.transform_action) {
32
+ (0, transform_1.transform)(new transform_action_1.TransformAction(customInfo));
33
+ }
34
+ // codegen write-all
35
+ }
36
+ main();
@@ -28,26 +28,49 @@ const pascal_case_1 = require("pascal-case");
28
28
  const minimist_1 = __importDefault(require("minimist"));
29
29
  const process_1 = require("process");
30
30
  const parse_1 = require("../parse_schema/parse");
31
+ const ast_1 = require("../tsc/ast");
31
32
  function main() {
32
33
  const options = (0, minimist_1.default)(process.argv.slice(2));
33
34
  if (!options.path) {
34
35
  throw new Error("path required");
35
36
  }
37
+ const customInfo = (0, ast_1.getCustomInfo)();
38
+ const globalSchemaPath = customInfo.globalSchemaPath || "__global__schema.ts";
39
+ let globalSchema;
36
40
  const r = /(\w+).ts/;
41
+ // do we still even need this...
37
42
  const paths = glob_1.default.sync(path.join(options.path, "*.ts"), {
38
43
  ignore: [`\d+_read_schema.ts`],
39
44
  });
40
45
  let potentialSchemas = {};
41
46
  for (const p of paths) {
42
47
  const basename = path.basename(p);
48
+ if (basename === globalSchemaPath) {
49
+ globalSchema = require(p).default;
50
+ continue;
51
+ }
43
52
  const match = r.exec(basename);
44
53
  if (!match) {
45
54
  throw new Error(`non-typescript file ${p} returned by glob`);
46
55
  }
47
- potentialSchemas[(0, pascal_case_1.pascalCase)(match[1])] = require(p).default;
56
+ let schema = match[1];
57
+ // convert foo_schema.ts -> foo
58
+ if (schema.endsWith("_schema")) {
59
+ schema = schema.slice(0, -7);
60
+ }
61
+ let relativePath;
62
+ const index = p.indexOf("src/schema");
63
+ if (index !== -1) {
64
+ relativePath = p.substring(index);
65
+ }
66
+ const s = require(p).default;
67
+ if (relativePath !== undefined) {
68
+ s.schemaPath = relativePath;
69
+ }
70
+ potentialSchemas[(0, pascal_case_1.pascalCase)(schema)] = s;
48
71
  }
49
72
  // console.log(potentialSchemas);
50
- const result = (0, parse_1.parseSchema)(potentialSchemas);
73
+ const result = (0, parse_1.parseSchema)(potentialSchemas, globalSchema);
51
74
  console.log(JSON.stringify(result));
52
75
  }
53
76
  try {