@snowtop/ent 0.1.0-alpha124 → 0.1.0-alpha126

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,46 +1,94 @@
1
1
  "use strict";
2
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
- return c > 3 && r && Object.defineProperty(target, key, r), r;
2
+ var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
3
+ var useValue = arguments.length > 2;
4
+ for (var i = 0; i < initializers.length; i++) {
5
+ value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
6
+ }
7
+ return useValue ? value : void 0;
7
8
  };
8
- var __metadata = (this && this.__metadata) || function (k, v) {
9
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
10
+ function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
11
+ var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
12
+ var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
13
+ var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
14
+ var _, done = false;
15
+ for (var i = decorators.length - 1; i >= 0; i--) {
16
+ var context = {};
17
+ for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
18
+ for (var p in contextIn.access) context.access[p] = contextIn.access[p];
19
+ context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
20
+ var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
21
+ if (kind === "accessor") {
22
+ if (result === void 0) continue;
23
+ if (result === null || typeof result !== "object") throw new TypeError("Object expected");
24
+ if (_ = accept(result.get)) descriptor.get = _;
25
+ if (_ = accept(result.set)) descriptor.set = _;
26
+ if (_ = accept(result.init)) initializers.push(_);
27
+ }
28
+ else if (_ = accept(result)) {
29
+ if (kind === "field") initializers.push(_);
30
+ else descriptor[key] = _;
31
+ }
32
+ }
33
+ if (target) Object.defineProperty(target, contextIn.name, descriptor);
34
+ done = true;
10
35
  };
11
- var __param = (this && this.__param) || function (paramIndex, decorator) {
12
- return function (target, key) { decorator(target, key, paramIndex); }
36
+ var __setFunctionName = (this && this.__setFunctionName) || function (f, name, prefix) {
37
+ if (typeof name === "symbol") name = name.description ? "[".concat(name.description, "]") : "";
38
+ return Object.defineProperty(f, "name", { configurable: true, value: prefix ? "".concat(prefix, " ", name) : name });
13
39
  };
14
40
  Object.defineProperty(exports, "__esModule", { value: true });
15
41
  const graphql_1 = require("../../../graphql/graphql");
16
42
  const graphql_2 = require("graphql");
17
- let ViewerType = class ViewerType {
18
- constructor(viewer) {
19
- this.viewer = viewer;
20
- }
21
- get viewerID() {
22
- return this.viewer.viewerID;
23
- }
24
- };
25
- __decorate([
26
- (0, graphql_1.gqlField)({ type: graphql_2.GraphQLID, nullable: true }),
27
- __metadata("design:type", Object),
28
- __metadata("design:paramtypes", [])
29
- ], ViewerType.prototype, "viewerID", null);
30
- ViewerType = __decorate([
31
- (0, graphql_1.gqlObjectType)({ name: "Viewer" }),
32
- __metadata("design:paramtypes", [Object])
33
- ], ViewerType);
34
- class ViewerResolver {
35
- viewer(context) {
36
- return new ViewerType(context.getViewer());
37
- }
38
- }
39
- __decorate([
40
- (0, graphql_1.gqlQuery)({ name: "viewer", type: ViewerType }),
41
- __param(0, (0, graphql_1.gqlContextType)()),
42
- __metadata("design:type", Function),
43
- __metadata("design:paramtypes", [Object]),
44
- __metadata("design:returntype", ViewerType)
45
- ], ViewerResolver.prototype, "viewer", null);
46
- exports.default = ViewerResolver;
43
+ let ViewerType = (() => {
44
+ let _classDecorators = [(0, graphql_1.gqlObjectType)({ name: "Viewer" })];
45
+ let _classDescriptor;
46
+ let _classExtraInitializers = [];
47
+ let _classThis;
48
+ let _instanceExtraInitializers = [];
49
+ let _get_viewerID_decorators;
50
+ var ViewerType = _classThis = class {
51
+ constructor(viewer) {
52
+ this.viewer = (__runInitializers(this, _instanceExtraInitializers), viewer);
53
+ }
54
+ get viewerID() {
55
+ return this.viewer.viewerID;
56
+ }
57
+ };
58
+ __setFunctionName(_classThis, "ViewerType");
59
+ (() => {
60
+ _get_viewerID_decorators = [(0, graphql_1.gqlField)({
61
+ nodeName: "ViewerType",
62
+ type: graphql_2.GraphQLID,
63
+ nullable: true,
64
+ })];
65
+ __esDecorate(_classThis, null, _get_viewerID_decorators, { kind: "getter", name: "viewerID", static: false, private: false, access: { has: obj => "viewerID" in obj, get: obj => obj.viewerID } }, null, _instanceExtraInitializers);
66
+ __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name }, null, _classExtraInitializers);
67
+ ViewerType = _classThis = _classDescriptor.value;
68
+ __runInitializers(_classThis, _classExtraInitializers);
69
+ })();
70
+ return ViewerType = _classThis;
71
+ })();
72
+ exports.default = (() => {
73
+ var _a;
74
+ let _instanceExtraInitializers_1 = [];
75
+ let _viewer_decorators;
76
+ return _a = class ViewerResolver {
77
+ viewer(context) {
78
+ return new ViewerType(context.getViewer());
79
+ }
80
+ constructor() {
81
+ __runInitializers(this, _instanceExtraInitializers_1);
82
+ }
83
+ },
84
+ (() => {
85
+ _viewer_decorators = [(0, graphql_1.gqlQuery)({
86
+ nodeName: "ViewerResolver",
87
+ name: "viewer",
88
+ type: ViewerType,
89
+ args: [(0, graphql_1.gqlContextType)()],
90
+ })];
91
+ __esDecorate(_a, null, _viewer_decorators, { kind: "method", name: "viewer", static: false, private: false, access: { has: obj => "viewer" in obj, get: obj => obj.viewer } }, null, _instanceExtraInitializers_1);
92
+ })(),
93
+ _a;
94
+ })();
package/index.d.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  export * from "./core/base";
2
- export { loadEnt, loadCustomData, loadCustomEnts, loadCustomCount, loadEntX, loadEnts, CustomQuery, loadDerivedEnt, loadDerivedEntX, loadEntViaKey, loadEntXViaKey, performRawQuery, loadRowX, loadRow, loadRows, DataOperation, EditNodeOptions, EditNodeOperation, RawQueryOperation, EdgeOperation, DeleteNodeOperation, AssocEdge, AssocEdgeInputOptions, AssocEdgeInput, AssocEdgeData, loadEdgeData, loadEdgeDatas, loadEdges, loadUniqueEdge, loadUniqueNode, loadRawEdgeCountX, loadEdgeForID2, loadNodesByEdge, getEdgeTypeInGroup, } from "./core/ent";
3
- export { setGlobalSchema } from "./core/global_schema";
2
+ export { loadEnt, loadCustomData, loadCustomEnts, loadCustomCount, loadEntX, loadEnts, CustomQuery, loadDerivedEnt, loadDerivedEntX, loadEntViaKey, loadEntXViaKey, performRawQuery, loadRowX, loadRow, loadRows, DataOperation, EditNodeOptions, EditNodeOperation, RawQueryOperation, EdgeOperation, DeleteNodeOperation, AssocEdge, AssocEdgeInputOptions, AssocEdgeInput, AssocEdgeData, loadEdgeData, loadEdgeDatas, loadEdges, loadUniqueEdge, loadUniqueNode, loadRawEdgeCountX, loadEdgeForID2, loadNodesByEdge, getEdgeTypeInGroup, setGlobalSchema, } from "./core/ent";
4
3
  import DB from "./core/db";
5
4
  export * from "./core/loaders";
6
5
  export { DB };
package/index.js CHANGED
@@ -63,8 +63,7 @@ Object.defineProperty(exports, "loadRawEdgeCountX", { enumerable: true, get: fun
63
63
  Object.defineProperty(exports, "loadEdgeForID2", { enumerable: true, get: function () { return ent_1.loadEdgeForID2; } });
64
64
  Object.defineProperty(exports, "loadNodesByEdge", { enumerable: true, get: function () { return ent_1.loadNodesByEdge; } });
65
65
  Object.defineProperty(exports, "getEdgeTypeInGroup", { enumerable: true, get: function () { return ent_1.getEdgeTypeInGroup; } });
66
- var global_schema_1 = require("./core/global_schema");
67
- Object.defineProperty(exports, "setGlobalSchema", { enumerable: true, get: function () { return global_schema_1.setGlobalSchema; } });
66
+ Object.defineProperty(exports, "setGlobalSchema", { enumerable: true, get: function () { return ent_1.setGlobalSchema; } });
68
67
  const db_1 = __importDefault(require("./core/db"));
69
68
  exports.DB = db_1.default;
70
69
  __exportStar(require("./core/loaders"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@snowtop/ent",
3
- "version": "0.1.0-alpha124",
3
+ "version": "0.1.0-alpha126",
4
4
  "description": "snowtop ent framework",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -22,12 +22,11 @@
22
22
  "pascal-case": "^3.1.2",
23
23
  "pg": "^8.8.0",
24
24
  "prettier": "^2.8.1",
25
- "reflect-metadata": "^0.1.13",
26
25
  "snake-case": "^3.0.4",
27
26
  "ts-node": "^10.9.1",
28
- "tsconfig-paths": "^4.1.1",
29
- "tslib": "^2.4.1",
30
- "typescript": "^4.9.4",
27
+ "tsconfig-paths": "^4.2.0",
28
+ "tslib": "^2.5.0",
29
+ "typescript": "^5.0.4",
31
30
  "uuid": "^9.0.0"
32
31
  },
33
32
  "peerDependencies": {
@@ -83,7 +83,6 @@ interface RomeConfig {
83
83
  interface ProcessedGlobalSchema {
84
84
  globalEdges: ProcessedAssocEdge[];
85
85
  extraEdgeFields: ProcessedField[];
86
- init?: boolean;
87
- globalFields?: ProcessedField[];
86
+ initForEdges?: boolean;
88
87
  }
89
88
  export {};
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseSchema = void 0;
4
4
  const cosmiconfig_1 = require("cosmiconfig");
5
5
  const const_1 = require("../core/const");
6
- const global_schema_1 = require("../core/global_schema");
7
6
  async function processFields(src, patternName) {
8
7
  const ret = [];
9
8
  let m = {};
@@ -237,9 +236,6 @@ async function parseSchema(potentialSchemas, globalSchema) {
237
236
  let parsedGlobalSchema;
238
237
  if (globalSchema) {
239
238
  parsedGlobalSchema = await parseGlobalSchema(globalSchema);
240
- // set this so that we can use it, if we're trying to process server default or anything
241
- // that ends up parsing,validating and formatting fields
242
- (0, global_schema_1.setGlobalSchema)(globalSchema);
243
239
  }
244
240
  for (const key in potentialSchemas) {
245
241
  const value = potentialSchemas[key];
@@ -358,10 +354,9 @@ async function parseGlobalSchema(s) {
358
354
  const ret = {
359
355
  globalEdges: [],
360
356
  extraEdgeFields: [],
361
- init: !!s.extraEdgeFields ||
357
+ initForEdges: !!s.extraEdgeFields ||
362
358
  s.transformEdgeRead !== undefined ||
363
- s.transformEdgeWrite !== undefined ||
364
- s.fields !== undefined,
359
+ s.transformEdgeWrite !== undefined,
365
360
  };
366
361
  if (s.extraEdgeFields) {
367
362
  ret.extraEdgeFields = await processFields(s.extraEdgeFields);
@@ -369,8 +364,5 @@ async function parseGlobalSchema(s) {
369
364
  if (s.edges) {
370
365
  ret.globalEdges = processEdges(s.edges);
371
366
  }
372
- if (s.fields) {
373
- ret.globalFields = await processFields(s.fields);
374
- }
375
367
  return ret;
376
368
  }
package/schema/field.d.ts CHANGED
@@ -149,7 +149,6 @@ export interface EnumOptions extends FieldOptions {
149
149
  graphQLType?: string;
150
150
  createEnumType?: boolean;
151
151
  disableUnknownType?: boolean;
152
- globalType?: string;
153
152
  }
154
153
  /**
155
154
  * @deprecated Use StringEnumField
@@ -159,7 +158,7 @@ export declare class EnumField extends BaseField implements Field {
159
158
  private values?;
160
159
  private map?;
161
160
  constructor(options: StringEnumOptions);
162
- valid(val: any): Promise<boolean>;
161
+ valid(val: any): boolean;
163
162
  format(val: any): any;
164
163
  }
165
164
  export declare class StringEnumField extends EnumField {
@@ -174,18 +173,17 @@ declare type IntEnumMap = {
174
173
  [key: string]: number;
175
174
  };
176
175
  export interface IntegerEnumOptions extends FieldOptions {
177
- map?: IntEnumMap;
176
+ map: IntEnumMap;
178
177
  deprecated?: IntEnumMap;
179
178
  tsType?: string;
180
179
  graphQLType?: string;
181
180
  disableUnknownType?: boolean;
182
- globalType?: string;
183
181
  }
184
182
  export declare class IntegerEnumField extends BaseField implements Field {
185
183
  type: Type;
186
184
  private map;
187
185
  constructor(options: IntegerEnumOptions);
188
- valid(val: any): Promise<boolean>;
186
+ valid(val: any): boolean;
189
187
  format(val: any): any;
190
188
  }
191
189
  export declare function IntegerEnumType(options: IntegerEnumOptions): IntegerEnumField;
package/schema/field.js CHANGED
@@ -31,8 +31,6 @@ const uuid_1 = require("uuid");
31
31
  const base_1 = require("../core/base");
32
32
  const db_1 = __importStar(require("../core/db"));
33
33
  const schema_1 = require("./schema");
34
- const global_schema_1 = require("../core/global_schema");
35
- const logger_1 = require("../core/logger");
36
34
  class BaseField {
37
35
  logValue(val) {
38
36
  if (this.sensitive) {
@@ -527,11 +525,10 @@ class EnumField extends BaseField {
527
525
  type: options.tsType,
528
526
  graphQLType: options.graphQLType,
529
527
  disableUnknownType: options.disableUnknownType,
530
- globalType: options.globalType,
531
528
  };
532
529
  if (!options.foreignKey) {
533
- if (!options.values && !options.map && !options.globalType) {
534
- throw new Error("values, map or globalType required if not look up table enum. Look-up table enum indicated by foreignKey field");
530
+ if (!options.values && !options.map) {
531
+ throw new Error("values or map required if not look up table enum. Look-up table enum indicated by foreignKey field");
535
532
  }
536
533
  if (options.values) {
537
534
  if (!options.values.length) {
@@ -550,8 +547,8 @@ class EnumField extends BaseField {
550
547
  }
551
548
  }
552
549
  else {
553
- if (options.values || options.map || options.globalType) {
554
- throw new Error("cannot specify values, map or globalType and foreign key for lookup table enum type");
550
+ if (options.values || options.map) {
551
+ throw new Error("cannot specify values or map and foreign key for lookup table enum type");
555
552
  }
556
553
  if (options.createEnumType) {
557
554
  throw new Error("cannot specify createEnumType without specifying values");
@@ -566,20 +563,7 @@ class EnumField extends BaseField {
566
563
  this.values = options.values;
567
564
  this.map = options.map;
568
565
  }
569
- async valid(val) {
570
- if (this.type.globalType) {
571
- const f = (0, global_schema_1.__getGlobalSchemaField)(this.type.globalType);
572
- if (f) {
573
- if (f.valid) {
574
- return f.valid(val);
575
- }
576
- return true;
577
- }
578
- else {
579
- (0, logger_1.log)("error", `globalType ${this.type.globalType} not found in global schema`);
580
- return false;
581
- }
582
- }
566
+ valid(val) {
583
567
  // lookup table enum and indicated via presence of foreignKey
584
568
  if (!this.values && !this.map) {
585
569
  return true;
@@ -597,13 +581,6 @@ class EnumField extends BaseField {
597
581
  return false;
598
582
  }
599
583
  format(val) {
600
- if (this.type.globalType) {
601
- const f = (0, global_schema_1.__getGlobalSchemaField)(this.type.globalType);
602
- if (f && f.format) {
603
- return f.format(val);
604
- }
605
- return val;
606
- }
607
584
  return val;
608
585
  }
609
586
  }
@@ -626,46 +603,21 @@ class IntegerEnumField extends BaseField {
626
603
  graphQLType: options.graphQLType,
627
604
  deprecatedIntEnumMap: options.deprecated,
628
605
  disableUnknownType: options.disableUnknownType,
629
- globalType: options.globalType,
630
606
  };
631
- if (options.foreignKey) {
632
- throw new Error(`foreignKey on intEnum not supported`);
607
+ let count = 0;
608
+ for (const _ in options.map) {
609
+ count++;
610
+ break;
633
611
  }
634
- if (options.globalType) {
635
- if (options.map) {
636
- throw new Error(`cannot specify map and globalType`);
637
- }
638
- this.map = {};
612
+ if (!count) {
613
+ throw new Error("need at least one entry in enum map");
639
614
  }
640
- else {
641
- let count = 0;
642
- for (const _ in options.map) {
643
- count++;
644
- break;
645
- }
646
- if (!count) {
647
- throw new Error("need at least one entry in enum map");
648
- }
649
- if (!options.map) {
650
- throw new Error("map required if not globalType");
651
- }
652
- this.map = options.map;
615
+ if (options.foreignKey) {
616
+ throw new Error(`foreignKey on intEnum not supported`);
653
617
  }
618
+ this.map = options.map;
654
619
  }
655
- async valid(val) {
656
- if (this.type?.globalType) {
657
- const f = (0, global_schema_1.__getGlobalSchemaField)(this.type.globalType);
658
- if (f) {
659
- if (f.valid) {
660
- return f.valid(val);
661
- }
662
- return true;
663
- }
664
- else {
665
- (0, logger_1.log)("error", `globalType ${this.type.globalType} not found in global schema`);
666
- return false;
667
- }
668
- }
620
+ valid(val) {
669
621
  // lookup table enum and indicated via presence of foreignKey
670
622
  for (const k in this.map) {
671
623
  const v = this.map[k];
@@ -676,12 +628,6 @@ class IntegerEnumField extends BaseField {
676
628
  return false;
677
629
  }
678
630
  format(val) {
679
- if (this.type.globalType) {
680
- const f = (0, global_schema_1.__getGlobalSchemaField)(this.type.globalType);
681
- if (f && f.format) {
682
- return f.format(val);
683
- }
684
- }
685
631
  return parseInt(val);
686
632
  }
687
633
  }
@@ -17,7 +17,6 @@ export interface GlobalSchema {
17
17
  extraEdgeFields?: FieldMap;
18
18
  transformEdgeRead?: () => Clause;
19
19
  transformEdgeWrite?: (stmt: EdgeUpdateOperation) => TransformedEdgeUpdateOperation | null;
20
- fields?: FieldMap;
21
20
  }
22
21
  type FieldOverride = Pick<FieldOptions, "nullable" | "storageKey" | "serverDefault" | "unique" | "hideFromGraphQL" | "graphqlName" | "index">;
23
22
  export type FieldOverrideMap = {
@@ -172,7 +171,6 @@ export interface Type {
172
171
  intEnumMap?: IntEnumMap;
173
172
  deprecatedIntEnumMap?: IntEnumMap;
174
173
  disableUnknownType?: boolean;
175
- globalType?: string;
176
174
  importType?: DeprecatedImportType;
177
175
  subFields?: FieldMap;
178
176
  unionFields?: FieldMap;
@@ -1,22 +1,20 @@
1
1
  import { BaseField, ListField } from "./field";
2
2
  import { FieldOptions, Field, Type, FieldMap } from "./schema";
3
- interface structFieldOptions extends FieldOptions {
3
+ export interface StructOptions extends FieldOptions {
4
4
  tsType: string;
5
5
  fields: FieldMap;
6
6
  graphQLType?: string;
7
7
  jsonNotJSONB?: boolean;
8
8
  }
9
- interface GlobalStructOptions extends FieldOptions {
10
- globalType: string;
9
+ interface allStructOptions extends StructOptions {
10
+ jsonAsList?: boolean;
11
11
  }
12
- export type StructOptions = structFieldOptions | GlobalStructOptions;
13
12
  export declare class StructField extends BaseField implements Field {
14
13
  private options;
15
- private jsonAsList?;
16
14
  type: Type;
17
- constructor(options: StructOptions, jsonAsList?: boolean | undefined);
15
+ constructor(options: allStructOptions);
18
16
  formatImpl(obj: any, nested?: boolean): string | Object;
19
- format(obj: any, nested?: boolean): any;
17
+ format(obj: any, nested?: boolean): string | Object;
20
18
  private validImpl;
21
19
  valid(obj: any): Promise<boolean>;
22
20
  }
@@ -25,5 +23,5 @@ export declare function StructType(options: StructOptions): StructField & Struct
25
23
  * @deprecated use StructTypeAsList
26
24
  */
27
25
  export declare function StructListType(options: StructOptions): ListField;
28
- export declare function StructTypeAsList(options: StructOptions): StructField & StructOptions;
26
+ export declare function StructTypeAsList(options: allStructOptions): StructField & allStructOptions;
29
27
  export {};
@@ -4,24 +4,20 @@ exports.StructTypeAsList = exports.StructListType = exports.StructType = exports
4
4
  const camel_case_1 = require("camel-case");
5
5
  const field_1 = require("./field");
6
6
  const schema_1 = require("./schema");
7
- const global_schema_1 = require("../core/global_schema");
8
- const logger_1 = require("../core/logger");
9
7
  class StructField extends field_1.BaseField {
10
- constructor(options, jsonAsList) {
8
+ constructor(options) {
11
9
  super();
12
10
  this.options = options;
13
- this.jsonAsList = jsonAsList;
14
11
  this.type = {
15
12
  dbType: schema_1.DBType.JSONB,
16
13
  };
17
14
  this.type.subFields = options.fields;
18
15
  this.type.type = options.tsType;
19
16
  this.type.graphQLType = options.graphQLType || options.tsType;
20
- this.type.globalType = this.options.globalType;
21
17
  if (options.jsonNotJSONB) {
22
18
  this.type.dbType = schema_1.DBType.JSON;
23
19
  }
24
- if (jsonAsList) {
20
+ if (options?.jsonAsList) {
25
21
  this.type.listElemType = {
26
22
  dbType: schema_1.DBType.JSONB,
27
23
  };
@@ -61,37 +57,7 @@ class StructField extends field_1.BaseField {
61
57
  return JSON.stringify(ret);
62
58
  }
63
59
  format(obj, nested) {
64
- if (this.type.globalType) {
65
- const f = (0, global_schema_1.__getGlobalSchemaField)(this.type.globalType);
66
- if (f && f.format) {
67
- if (JSON.stringify(this.type.listElemType) !==
68
- JSON.stringify(f?.type.listElemType)) {
69
- if (this.jsonAsList) {
70
- // handle as nested
71
- // @ts-ignore
72
- const formatted = obj.map((v) => f.format(v, true));
73
- if (nested) {
74
- return formatted;
75
- }
76
- else {
77
- return JSON.stringify(formatted);
78
- }
79
- }
80
- else {
81
- const formatted = f.format([obj], true);
82
- if (nested) {
83
- return formatted[0];
84
- }
85
- else {
86
- return JSON.stringify(formatted[0]);
87
- }
88
- }
89
- }
90
- // TODO handle format code
91
- return f.format(obj);
92
- }
93
- }
94
- if (Array.isArray(obj) && this.jsonAsList) {
60
+ if (Array.isArray(obj) && this.options.jsonAsList) {
95
61
  const ret = obj.map((v) => this.formatImpl(v, true));
96
62
  if (nested) {
97
63
  return ret;
@@ -136,35 +102,7 @@ class StructField extends field_1.BaseField {
136
102
  return ret.every((v) => v);
137
103
  }
138
104
  async valid(obj) {
139
- if (this.type.globalType) {
140
- const f = (0, global_schema_1.__getGlobalSchemaField)(this.type.globalType);
141
- // list and global type is not valid.
142
- if (f) {
143
- if (f.valid) {
144
- if (JSON.stringify(this.type.listElemType) !==
145
- JSON.stringify(f?.type.listElemType)) {
146
- if (this.jsonAsList) {
147
- if (!Array.isArray(obj)) {
148
- return false;
149
- }
150
- // @ts-ignore
151
- const valid = await Promise.all(obj.map((v) => f.valid(v)));
152
- return valid.every((b) => b);
153
- }
154
- else {
155
- return f.valid([obj]);
156
- }
157
- }
158
- return f.valid(obj);
159
- }
160
- return true;
161
- }
162
- else {
163
- (0, logger_1.log)("error", `globalType ${this.type.globalType} not found in global schema`);
164
- return false;
165
- }
166
- }
167
- if (this.jsonAsList) {
105
+ if (this.options.jsonAsList) {
168
106
  if (!Array.isArray(obj)) {
169
107
  return false;
170
108
  }
@@ -191,7 +129,10 @@ function StructListType(options) {
191
129
  }
192
130
  exports.StructListType = StructListType;
193
131
  function StructTypeAsList(options) {
194
- let result = new StructField(options, true);
132
+ let result = new StructField({
133
+ ...options,
134
+ jsonAsList: true,
135
+ });
195
136
  return Object.assign(result, options);
196
137
  }
197
138
  exports.StructTypeAsList = StructTypeAsList;
@@ -15,7 +15,7 @@ export declare class UnionField extends BaseField implements FieldOptions {
15
15
  type: Type;
16
16
  m: Map<Object, string>;
17
17
  constructor(options: UnionOptions);
18
- format(obj: any): any;
18
+ format(obj: any): string | Object;
19
19
  private validField;
20
20
  valid(obj: any): Promise<boolean>;
21
21
  }
@@ -229,7 +229,7 @@ class Compiler {
229
229
  let relPath = checkPath(paths, text);
230
230
  if (relPath) {
231
231
  // update the node...
232
- return typescript_1.default.factory.updateImportDeclaration(importNode, importNode.decorators, importNode.modifiers, importNode.importClause, typescript_1.default.factory.createStringLiteral(relPath), importNode.assertClause);
232
+ return typescript_1.default.factory.updateImportDeclaration(importNode, importNode.modifiers, importNode.importClause, typescript_1.default.factory.createStringLiteral(relPath), importNode.assertClause);
233
233
  }
234
234
  }
235
235
  if (node.kind === typescript_1.default.SyntaxKind.ExportDeclaration) {
@@ -239,7 +239,7 @@ class Compiler {
239
239
  let relPath = checkPath(paths, text);
240
240
  if (relPath) {
241
241
  // update the node...
242
- return typescript_1.default.updateExportDeclaration(exportNode, exportNode.decorators, exportNode.modifiers, exportNode.exportClause, typescript_1.default.factory.createStringLiteral(relPath), exportNode.isTypeOnly);
242
+ return typescript_1.default.factory.updateExportDeclaration(exportNode, exportNode.modifiers, exportNode.isTypeOnly, exportNode.exportClause, typescript_1.default.factory.createStringLiteral(relPath), exportNode.assertClause);
243
243
  }
244
244
  }
245
245
  }
@@ -36,7 +36,10 @@ class GatherExportsInGeneratedTypes {
36
36
  this.names = [];
37
37
  }
38
38
  traverseChild(sourceFile, contents, file, node) {
39
- const exported = node.modifiers?.filter((mod) => mod.getText(sourceFile) === "export");
39
+ const modifiers = typescript_1.default.canHaveModifiers(node)
40
+ ? typescript_1.default.getModifiers(node)
41
+ : undefined;
42
+ const exported = modifiers?.filter((mod) => mod.getText(sourceFile) === "export");
40
43
  if (exported?.length) {
41
44
  if (typescript_1.default.isEnumDeclaration(node) ||
42
45
  typescript_1.default.isInterfaceDeclaration(node) ||
@@ -263,10 +263,10 @@ class QueryRecorder {
263
263
  });
264
264
  }
265
265
  }
266
- exports.QueryRecorder = QueryRecorder;
267
266
  QueryRecorder.queries = [];
268
267
  QueryRecorder.ids = [];
269
268
  // we need pkeys when storing...
270
269
  QueryRecorder.data = new Map();
270
+ exports.QueryRecorder = QueryRecorder;
271
271
  // TODO
272
272
  process.env.DB_CONNECTION_STRING = "INVALID DATABASE";
@@ -32,5 +32,5 @@ class FakeComms {
32
32
  this.sent = [];
33
33
  }
34
34
  }
35
- exports.FakeComms = FakeComms;
36
35
  FakeComms.sent = [];
36
+ exports.FakeComms = FakeComms;
@@ -21,12 +21,12 @@ class FakeLogger {
21
21
  this.logs = [];
22
22
  }
23
23
  }
24
- exports.FakeLogger = FakeLogger;
25
24
  // todo this is quick and ideal.
26
25
  // more ideal is capturing all console.logs
27
26
  // we do it in golang for example
28
27
  // and will need this for production launch anyways
29
28
  FakeLogger.logs = [];
29
+ exports.FakeLogger = FakeLogger;
30
30
  // TODO instead of needing to add this manually
31
31
  // we need to build a way to add global observers (and maybe triggers)
32
32
  // to be run on every action/mutation