@snowtop/ent 0.1.0-alpha153 → 0.1.0-alpha155

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.
@@ -15,7 +15,7 @@ export declare class ListBasedExecutor<T extends Ent> implements Executor {
15
15
  constructor(viewer: Viewer, placeholderID: ID, operations: DataOperation<T>[], options?: OrchestratorOptions<T, Data, Viewer<Ent<any> | null, ID | null>, T | null> | undefined, complexOptions?: ComplexExecutorOptions | undefined);
16
16
  private lastOp;
17
17
  private createdEnt;
18
- private updatedOps;
18
+ private changedOps;
19
19
  resolveValue(val: ID): Ent | null;
20
20
  builderOpChanged(builder: Builder<any>): boolean;
21
21
  [Symbol.iterator](): this;
@@ -38,7 +38,7 @@ export declare class ComplexExecutor<T extends Ent> implements Executor {
38
38
  private lastOp;
39
39
  private allOperations;
40
40
  private executors;
41
- private updatedOps;
41
+ private changedOps;
42
42
  builder?: Builder<Ent> | undefined;
43
43
  constructor(viewer: Viewer, placeholderID: ID, operations: DataOperation[], dependencies: Map<ID, Builder<T>>, changesets: Changeset[], options?: OrchestratorOptions<T, Data, Viewer>, complexOptions?: ComplexExecutorOptions | undefined);
44
44
  [Symbol.iterator](): this;
@@ -19,7 +19,7 @@ class ListBasedExecutor {
19
19
  this.complexOptions = complexOptions;
20
20
  this.idx = 0;
21
21
  this.createdEnt = null;
22
- this.updatedOps = new Map();
22
+ this.changedOps = new Map();
23
23
  this.builder = options?.builder;
24
24
  }
25
25
  resolveValue(val) {
@@ -29,7 +29,7 @@ class ListBasedExecutor {
29
29
  return null;
30
30
  }
31
31
  builderOpChanged(builder) {
32
- const v = this.updatedOps.get(builder.placeholderID);
32
+ const v = this.changedOps.get(builder.placeholderID);
33
33
  return v !== undefined && v !== builder.operation;
34
34
  }
35
35
  [Symbol.iterator]() {
@@ -41,19 +41,19 @@ class ListBasedExecutor {
41
41
  if (createdEnt) {
42
42
  this.createdEnt = createdEnt;
43
43
  }
44
- maybeUpdateOperationForOp(this.lastOp, this.updatedOps);
45
- const done = this.idx === this.operations.length;
46
- const op = changeOp(this.operations[this.idx], this.complexOptions);
44
+ maybeFlagOpOperationAsChanged(this.lastOp, this.changedOps);
45
+ const done = this.idx >= this.operations.length;
46
+ const op = maybeChangeOp(this.operations[this.idx], this.complexOptions);
47
47
  this.idx++;
48
48
  this.lastOp = op;
49
- // reset since this could be called multiple times. not needed if we have getSortedOps or something like that
50
- if (done) {
51
- // TODO need to figure this out
52
- // this.idx = 0;
49
+ if (done || op === undefined) {
50
+ return {
51
+ value: op,
52
+ done: true,
53
+ };
53
54
  }
54
55
  return {
55
56
  value: op,
56
- done: done,
57
57
  };
58
58
  }
59
59
  async executeObservers() {
@@ -101,7 +101,7 @@ function getCreatedEnt(viewer, op) {
101
101
  }
102
102
  return null;
103
103
  }
104
- function maybeUpdateOperationForOp(op, updatedOps) {
104
+ function maybeFlagOpOperationAsChanged(op, changedOps) {
105
105
  if (!op || !op.updatedOperation) {
106
106
  return;
107
107
  }
@@ -109,8 +109,7 @@ function maybeUpdateOperationForOp(op, updatedOps) {
109
109
  if (!r || r.builder.operation === r.operation) {
110
110
  return;
111
111
  }
112
- updatedOps.set(r.builder.placeholderID, r.operation);
113
- // console.debug(updatedOps);
112
+ changedOps.set(r.builder.placeholderID, r.operation);
114
113
  }
115
114
  class ComplexExecutor {
116
115
  constructor(viewer, placeholderID, operations, dependencies, changesets, options, complexOptions) {
@@ -121,7 +120,7 @@ class ComplexExecutor {
121
120
  this.mapper = new Map();
122
121
  this.allOperations = [];
123
122
  this.executors = [];
124
- this.updatedOps = new Map();
123
+ this.changedOps = new Map();
125
124
  this.builder = options?.builder;
126
125
  let graph = (0, graph_data_structure_1.Graph)();
127
126
  const changesetMap = new Map();
@@ -171,11 +170,6 @@ class ComplexExecutor {
171
170
  // get ordered list of ops
172
171
  let executor = c.executor();
173
172
  for (let op of executor) {
174
- if (!op) {
175
- // TODO what is happening...
176
- // change in behavior in next() leading to needing to do this
177
- break;
178
- }
179
173
  if (op.createdEnt) {
180
174
  nodeOps.add(op);
181
175
  }
@@ -212,17 +206,18 @@ class ComplexExecutor {
212
206
  }
213
207
  next() {
214
208
  this.handleCreatedEnt();
215
- maybeUpdateOperationForOp(this.lastOp, this.updatedOps);
216
- const done = this.idx === this.allOperations.length;
217
- const op = changeOp(this.allOperations[this.idx], this.complexOptions);
209
+ maybeFlagOpOperationAsChanged(this.lastOp, this.changedOps);
210
+ const done = this.idx >= this.allOperations.length;
211
+ const op = maybeChangeOp(this.allOperations[this.idx], this.complexOptions);
218
212
  this.idx++;
219
213
  this.lastOp = op;
220
- // reset since this could be called multiple times. not needed if we have getSortedOps or something like that
221
- if (done) {
222
- // TODO need to figure this out
223
- // this.idx = 0;
214
+ if (done || op === undefined) {
215
+ return {
216
+ value: op,
217
+ done: true,
218
+ };
224
219
  }
225
- return { value: op, done };
220
+ return { value: op };
226
221
  }
227
222
  resolveValue(val) {
228
223
  let ent = this.mapper.get(val);
@@ -238,8 +233,7 @@ class ComplexExecutor {
238
233
  return null;
239
234
  }
240
235
  builderOpChanged(builder) {
241
- const v = this.updatedOps.get(builder.placeholderID);
242
- // console.debug(this.updatedOps, builder.placeholderID, v, builder.operation);
236
+ const v = this.changedOps.get(builder.placeholderID);
243
237
  return v !== undefined && v !== builder.operation;
244
238
  }
245
239
  async executeObservers() {
@@ -345,7 +339,7 @@ async function executeOperations(executor, context, trackOps) {
345
339
  return operations;
346
340
  }
347
341
  exports.executeOperations = executeOperations;
348
- function changeOp(op, complexOptions) {
342
+ function maybeChangeOp(op, complexOptions) {
349
343
  if (!op ||
350
344
  !complexOptions?.conditionalOverride ||
351
345
  op instanceof operations_1.ConditionalNodeOperation) {
@@ -740,7 +740,10 @@ class Orchestrator {
740
740
  }
741
741
  else if (this.isBuilder(value)) {
742
742
  if (field.valid) {
743
- const valid = await field.valid(value);
743
+ let valid = field.valid(value);
744
+ if (util_1.types.isPromise(valid)) {
745
+ valid = await valid;
746
+ }
744
747
  if (!valid) {
745
748
  return new Error(`invalid field ${fieldName} with value ${value}`);
746
749
  }
@@ -752,8 +755,10 @@ class Orchestrator {
752
755
  }
753
756
  else {
754
757
  if (field.valid) {
755
- // TODO this could be async. handle this better
756
- const valid = await field.valid(value);
758
+ let valid = field.valid(value);
759
+ if (util_1.types.isPromise(valid)) {
760
+ valid = await valid;
761
+ }
757
762
  if (!valid) {
758
763
  return new Error(`invalid field ${fieldName} with value ${value}`);
759
764
  }
package/core/config.d.ts CHANGED
@@ -44,6 +44,7 @@ interface CodegenConfig {
44
44
  templatizedViewer?: importedObject;
45
45
  customAssocEdgePath?: importedObject;
46
46
  globalImportPath?: string;
47
+ userOveriddenFiles?: string[];
47
48
  }
48
49
  interface PrettierConfig {
49
50
  custom?: boolean;
package/core/ent.js CHANGED
@@ -34,32 +34,7 @@ const logger_1 = require("./logger");
34
34
  const dataloader_1 = __importDefault(require("dataloader"));
35
35
  const global_schema_1 = require("./global_schema");
36
36
  const query_impl_1 = require("./query_impl");
37
- // TODO kill this and createDataLoader
38
- class cacheMap {
39
- constructor(options) {
40
- this.options = options;
41
- this.m = new Map();
42
- }
43
- get(key) {
44
- const ret = this.m.get(key);
45
- if (ret) {
46
- (0, logger_1.log)("cache", {
47
- "dataloader-cache-hit": key,
48
- "tableName": this.options.tableName,
49
- });
50
- }
51
- return ret;
52
- }
53
- set(key, value) {
54
- return this.m.set(key, value);
55
- }
56
- delete(key) {
57
- return this.m.delete(key);
58
- }
59
- clear() {
60
- return this.m.clear();
61
- }
62
- }
37
+ const loader_1 = require("./loaders/loader");
63
38
  class entCacheMap {
64
39
  constructor(viewer, options) {
65
40
  this.viewer = viewer;
@@ -88,11 +63,11 @@ class entCacheMap {
88
63
  return this.m.clear();
89
64
  }
90
65
  }
91
- function createDataLoader(options) {
66
+ function createAssocEdgeConfigLoader(options) {
92
67
  const loaderOptions = {};
93
68
  // if query logging is enabled, we should log what's happening with loader
94
69
  if ((0, logger_1.logEnabled)("query")) {
95
- loaderOptions.cacheMap = new cacheMap(options);
70
+ loaderOptions.cacheMap = new loader_1.CacheMap(options);
96
71
  }
97
72
  // something here brokwn with strict:true
98
73
  return new dataloader_1.default(async (ids) => {
@@ -918,10 +893,11 @@ const assocEdgeFields = [
918
893
  "inverse_edge_type",
919
894
  "edge_table",
920
895
  ];
921
- exports.assocEdgeLoader = createDataLoader({
896
+ exports.assocEdgeLoader = createAssocEdgeConfigLoader({
922
897
  tableName: "assoc_edge_config",
923
898
  fields: assocEdgeFields,
924
899
  key: "edge_type",
900
+ keyType: "uuid",
925
901
  });
926
902
  // we don't expect assoc_edge_config information to change
927
903
  // so not using ContextCache but just caching it as needed once per server
@@ -36,7 +36,7 @@ const memoizee_1 = __importDefault(require("memoizee"));
36
36
  function createLoader(options, edgeType, edgeCtr, edgeData) {
37
37
  const loaderOptions = {};
38
38
  if ((0, logger_1.logEnabled)("query")) {
39
- loaderOptions.cacheMap = new loader_1.cacheMap({
39
+ loaderOptions.cacheMap = new loader_1.CacheMap({
40
40
  tableName: edgeData.edgeTable,
41
41
  });
42
42
  }
@@ -145,7 +145,6 @@ class AssocDirectEdgeLoader {
145
145
  ctr: this.edgeCtr,
146
146
  });
147
147
  }
148
- // TODO should this have a disableTransformations flag to get these rows
149
148
  async loadEdgeForID2(id, id2) {
150
149
  return (0, ent_1.loadEdgeForID2)({
151
150
  id1: id,
@@ -2,5 +2,4 @@ export { ObjectLoader, ObjectLoaderFactory } from "./object_loader";
2
2
  export { RawCountLoader, RawCountLoaderFactory } from "./raw_count_loader";
3
3
  export { AssocEdgeCountLoader, AssocEdgeCountLoaderFactory, } from "./assoc_count_loader";
4
4
  export { AssocDirectEdgeLoader, AssocEdgeLoader, AssocEdgeLoaderFactory, } from "./assoc_edge_loader";
5
- export { IndexLoaderFactory } from "./index_loader";
6
5
  export { QueryLoaderFactory } from "./query_loader";
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.QueryLoaderFactory = exports.IndexLoaderFactory = exports.AssocEdgeLoaderFactory = exports.AssocEdgeLoader = exports.AssocDirectEdgeLoader = exports.AssocEdgeCountLoaderFactory = exports.AssocEdgeCountLoader = exports.RawCountLoaderFactory = exports.RawCountLoader = exports.ObjectLoaderFactory = exports.ObjectLoader = void 0;
3
+ exports.QueryLoaderFactory = exports.AssocEdgeLoaderFactory = exports.AssocEdgeLoader = exports.AssocDirectEdgeLoader = exports.AssocEdgeCountLoaderFactory = exports.AssocEdgeCountLoader = exports.RawCountLoaderFactory = exports.RawCountLoader = exports.ObjectLoaderFactory = exports.ObjectLoader = void 0;
4
4
  var object_loader_1 = require("./object_loader");
5
5
  Object.defineProperty(exports, "ObjectLoader", { enumerable: true, get: function () { return object_loader_1.ObjectLoader; } });
6
6
  Object.defineProperty(exports, "ObjectLoaderFactory", { enumerable: true, get: function () { return object_loader_1.ObjectLoaderFactory; } });
@@ -14,7 +14,5 @@ var assoc_edge_loader_1 = require("./assoc_edge_loader");
14
14
  Object.defineProperty(exports, "AssocDirectEdgeLoader", { enumerable: true, get: function () { return assoc_edge_loader_1.AssocDirectEdgeLoader; } });
15
15
  Object.defineProperty(exports, "AssocEdgeLoader", { enumerable: true, get: function () { return assoc_edge_loader_1.AssocEdgeLoader; } });
16
16
  Object.defineProperty(exports, "AssocEdgeLoaderFactory", { enumerable: true, get: function () { return assoc_edge_loader_1.AssocEdgeLoaderFactory; } });
17
- var index_loader_1 = require("./index_loader");
18
- Object.defineProperty(exports, "IndexLoaderFactory", { enumerable: true, get: function () { return index_loader_1.IndexLoaderFactory; } });
19
17
  var query_loader_1 = require("./query_loader");
20
18
  Object.defineProperty(exports, "QueryLoaderFactory", { enumerable: true, get: function () { return query_loader_1.QueryLoaderFactory; } });
@@ -1,7 +1,7 @@
1
1
  import { Loader, LoaderFactory, Context, DataOptions } from "../base";
2
2
  export declare function getLoader<K, V>(factory: LoaderFactory<K, V>, create: () => Loader<K, V>, context?: Context): Loader<K, V>;
3
3
  export declare function getCustomLoader<K, V>(key: string, create: () => Loader<K, V>, context?: Context): Loader<K, V>;
4
- export declare class cacheMap {
4
+ export declare class CacheMap {
5
5
  private options;
6
6
  private m;
7
7
  constructor(options: DataOptions);
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.cacheMap = exports.getCustomLoader = exports.getLoader = void 0;
3
+ exports.CacheMap = exports.getCustomLoader = exports.getLoader = void 0;
4
4
  const logger_1 = require("../logger");
5
5
  // this is like factory factory FML
6
6
  // helper function to handle context vs not
@@ -25,7 +25,7 @@ function getCustomLoader(key, create, context) {
25
25
  return context.cache.getLoader(key, create);
26
26
  }
27
27
  exports.getCustomLoader = getCustomLoader;
28
- class cacheMap {
28
+ class CacheMap {
29
29
  constructor(options) {
30
30
  this.options = options;
31
31
  this.m = new Map();
@@ -41,34 +41,17 @@ class cacheMap {
41
41
  "dataloader-cache-hit": key,
42
42
  "tableName": this.options.tableName,
43
43
  });
44
- // } else {
45
- // log("cache", {
46
- // "dataloader-cache-miss": key,
47
- // "tableName": options.tableName,
48
- // });
49
44
  }
50
45
  return ret;
51
46
  }
52
47
  set(key, value) {
53
- // log("cache", {
54
- // "dataloader-cache-set": key,
55
- // "tableName": options.tableName,
56
- // });
57
48
  return this.m.set(key, value);
58
49
  }
59
50
  delete(key) {
60
- // log("cache", {
61
- // "dataloader-cache-delete": key,
62
- // "tableName": options.tableName,
63
- // });
64
51
  return this.m.delete(key);
65
52
  }
66
53
  clear() {
67
- // log("cache", {
68
- // "dataloader-cache-clear": true,
69
- // "tableName": options.tableName,
70
- // });
71
54
  return this.m.clear();
72
55
  }
73
56
  }
74
- exports.cacheMap = cacheMap;
57
+ exports.CacheMap = CacheMap;
@@ -93,7 +93,7 @@ function createDataLoader(options) {
93
93
  const loaderOptions = {};
94
94
  // if query logging is enabled, we should log what's happening with loader
95
95
  if ((0, logger_1.logEnabled)("query")) {
96
- loaderOptions.cacheMap = new loader_1.cacheMap(options);
96
+ loaderOptions.cacheMap = new loader_1.CacheMap(options);
97
97
  }
98
98
  return new dataloader_1.default(async (ids) => {
99
99
  if (!ids.length) {
@@ -70,7 +70,7 @@ function createLoader(options, queryOptions) {
70
70
  const loaderOptions = {};
71
71
  // if query logging is enabled, we should log what's happening with loader
72
72
  if ((0, logger_1.logEnabled)("query")) {
73
- loaderOptions.cacheMap = new loader_1.cacheMap(options);
73
+ loaderOptions.cacheMap = new loader_1.CacheMap(options);
74
74
  }
75
75
  return new dataloader_1.default(async (keys) => {
76
76
  if (!keys.length) {
@@ -59,7 +59,7 @@ function createCountDataLoader(options) {
59
59
  const loaderOptions = {};
60
60
  // if query logging is enabled, we should log what's happening with loader
61
61
  if ((0, logger_1.logEnabled)("query")) {
62
- loaderOptions.cacheMap = new loader_1.cacheMap(options);
62
+ loaderOptions.cacheMap = new loader_1.CacheMap(options);
63
63
  }
64
64
  return new dataloader_1.default(async (keys) => {
65
65
  if (!keys.length) {
@@ -130,7 +130,6 @@ class FirstFilter {
130
130
  return this.pageMap.get(id);
131
131
  }
132
132
  }
133
- // TODO need some last tests to test all these cases. clearly don't have the tests
134
133
  class LastFilter {
135
134
  constructor(options) {
136
135
  this.options = options;
@@ -172,8 +171,6 @@ class LastFilter {
172
171
  async query(options) {
173
172
  const orderby = (0, query_impl_1.reverseOrderBy)(this.options.orderby);
174
173
  const greater = orderby[0].direction === "ASC";
175
- // TODO verify that this greater still makes sense. tests pass
176
- // but wanna confirm
177
174
  options.limit = this.options.limit + 1; // fetch an extra so we know if previous pag
178
175
  if (this.options.cursorCol !== this.sortCol) {
179
176
  const res = this.edgeQuery.getTableName();
@@ -1,20 +1,26 @@
1
1
  import { GraphQLScalarType } from "graphql";
2
+ import { FieldMap } from "src/schema";
3
+ import { ProcessedField as ParsedProcessedField } from "../parse_schema/parse";
2
4
  interface ClassType<T = any> {
3
5
  new (...args: any[]): T;
4
6
  }
5
7
  declare type StringToStringMap = {
6
8
  [key: string]: string;
7
9
  };
8
- export interface CustomType {
10
+ export interface CustomTypeInput {
9
11
  type: string;
10
12
  importPath: string;
11
13
  tsType?: string;
12
14
  tsImportPath?: string;
13
15
  enumMap?: StringToStringMap;
16
+ structFields?: FieldMap;
14
17
  inputType?: boolean;
15
18
  [x: string]: any;
16
19
  }
17
- type Type = GraphQLScalarType | ClassType | string | CustomType;
20
+ export type CustomType = Omit<CustomTypeInput, "structFields"> & {
21
+ structFields?: ParsedProcessedField[];
22
+ };
23
+ type Type = GraphQLScalarType | ClassType | string | CustomTypeInput;
18
24
  export type GraphQLConnection<T> = {
19
25
  node: T;
20
26
  };
@@ -113,8 +119,8 @@ declare enum NullableResult {
113
119
  export declare const knownAllowedNames: Map<string, string>;
114
120
  export declare const knownDisAllowedNames: Map<string, boolean>;
115
121
  export declare const knownInterfaces: Map<string, boolean>;
116
- export declare const isCustomType: (type: Type) => type is CustomType;
117
- export declare const addCustomType: (type: CustomType, gqlCapture: typeof GQLCapture) => void;
122
+ export declare const isCustomType: (type: Type) => type is CustomTypeInput;
123
+ export declare const addCustomType: (type: CustomTypeInput, gqlCapture: typeof GQLCapture) => Promise<void>;
118
124
  export declare class GQLCapture {
119
125
  private static enabled;
120
126
  static enable(enabled: boolean): void;
@@ -168,5 +174,5 @@ export declare const gqlQuery: typeof GQLCapture.gqlQuery;
168
174
  export declare const gqlMutation: typeof GQLCapture.gqlMutation;
169
175
  export declare const gqlContextType: typeof GQLCapture.gqlContextType;
170
176
  export declare const gqlConnection: typeof GQLCapture.gqlConnection;
171
- declare const gqlFileUpload: CustomType;
177
+ declare const gqlFileUpload: CustomTypeInput;
172
178
  export { gqlFileUpload };
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.gqlFileUpload = exports.gqlConnection = exports.gqlContextType = exports.gqlMutation = exports.gqlQuery = exports.gqlUnionType = exports.gqlInterfaceType = exports.gqlObjectType = exports.gqlInputObjectType = exports.gqlArgType = exports.gqlField = exports.GQLCapture = exports.addCustomType = exports.isCustomType = exports.knownInterfaces = exports.knownDisAllowedNames = exports.knownAllowedNames = exports.CustomFieldType = void 0;
4
+ const parse_1 = require("../parse_schema/parse");
4
5
  var CustomFieldType;
5
6
  (function (CustomFieldType) {
6
7
  CustomFieldType["Accessor"] = "ACCESSOR";
@@ -62,16 +63,23 @@ exports.isCustomType = isCustomType;
62
63
  const isGraphQLScalarType = (type) => {
63
64
  return type.serialize !== undefined;
64
65
  };
65
- const addCustomType = (type, gqlCapture) => {
66
+ const addCustomType = async (type, gqlCapture) => {
66
67
  // TODO these should return ReadOnly objects...
67
68
  const customTypes = gqlCapture.getCustomTypes();
68
69
  const customType = customTypes.get(type.type);
69
70
  if (customType && customType === type) {
70
71
  return;
71
72
  }
72
- if (type.enumMap) {
73
- customTypes.set(type.type, type);
74
- return;
73
+ const addType = async (type) => {
74
+ // @ts-expect-error
75
+ const typ2 = { ...type };
76
+ if (type.structFields) {
77
+ typ2.structFields = await (0, parse_1.processFields)(type.structFields);
78
+ }
79
+ customTypes.set(type.type, typ2);
80
+ };
81
+ if (type.enumMap || type.structFields) {
82
+ await addType(type);
75
83
  }
76
84
  try {
77
85
  const r = require(type.importPath);
@@ -102,7 +110,7 @@ const addCustomType = (type, gqlCapture) => {
102
110
  }
103
111
  return;
104
112
  }
105
- customTypes.set(type.type, type);
113
+ await addType(type);
106
114
  };
107
115
  exports.addCustomType = addCustomType;
108
116
  const getType = (typ, result) => {
@@ -1,4 +1,4 @@
1
- import { CustomField, Field, CustomObject, CustomMutation, CustomQuery, CustomType } from "./graphql";
1
+ import { CustomField, Field, CustomObject, CustomMutation, CustomQuery, CustomTypeInput } from "./graphql";
2
2
  export declare function validateOneCustomField(expected: CustomField): void;
3
3
  export declare function validateCustomFields(expected: CustomField[]): void;
4
4
  export declare function validateCustomMutations(expected: CustomMutation[]): void;
@@ -30,4 +30,4 @@ export declare enum CustomObjectTypes {
30
30
  Union = 256
31
31
  }
32
32
  export declare function validateNoCustom(...exceptions: number[]): void;
33
- export declare function validateCustomTypes(expected: CustomType[]): void;
33
+ export declare function validateCustomTypes(expected: CustomTypeInput[]): void;
@@ -153,7 +153,7 @@ var CustomObjectTypes;
153
153
  CustomObjectTypes[CustomObjectTypes["Interface"] = 128] = "Interface";
154
154
  CustomObjectTypes[CustomObjectTypes["Union"] = 256] = "Union";
155
155
  })(CustomObjectTypes = exports.CustomObjectTypes || (exports.CustomObjectTypes = {}));
156
- // TODO what's a good name for this instead
156
+ // what's a good name for this instead?
157
157
  function validateNoCustom(...exceptions) {
158
158
  let bit = 0;
159
159
  exceptions.forEach((exp) => (bit = bit | exp));
package/index.d.ts CHANGED
@@ -7,6 +7,7 @@ export * from "./core/loaders";
7
7
  export { DB };
8
8
  export { EntPrivacyError, AlwaysAllowRule, AlwaysDenyRule, DenyIfLoggedInRule, DenyIfLoggedOutRule, AllowIfHasIdentity, AllowIfViewerRule, AllowIfFuncRule, AllowIfViewerIsRule, AllowIfViewerIsEntPropertyRule, AllowIfEntPropertyIsRule, DenyIfEntPropertyIsRule, AllowIfViewerEqualsRule, DenyIfViewerEqualsRule, AllowIfEdgeExistsRule, AllowIfViewerInboundEdgeExistsRule, AllowIfViewerOutboundEdgeExistsRule, DenyIfEdgeExistsRule, DenyIfViewerInboundEdgeExistsRule, DenyIfViewerOutboundEdgeExistsRule, DenyIfEdgeDoesNotExistRule, DenyIfViewerInboundEdgeDoesNotExistRule, DenyIfViewerOutboundEdgeDoesNotExistRule, AllowIfEntIsVisibleRule, AllowIfEntIsNotVisibleRule, DenyIfEntIsVisibleRule, DenyIfEntIsNotVisibleRule, AllowIfEntIsVisiblePolicy, DenyIfEntIsVisiblePolicy, DelayedResultRule, applyPrivacyPolicy, applyPrivacyPolicyX, AlwaysAllowPrivacyPolicy, AlwaysDenyPrivacyPolicy, AllowIfConditionAppliesRule, AllowIfSubPolicyAllowsRule, AllowIfViewerPrivacyPolicy, AllowIfViewerHasIdentityPrivacyPolicy, } from "./core/privacy";
9
9
  export * from "./core/query";
10
+ export * from "./core/query_impl";
10
11
  export * from "./schema/";
11
12
  import * as q from "./core/clause";
12
13
  export { Clause } from "./core/clause";
package/index.js CHANGED
@@ -111,6 +111,7 @@ Object.defineProperty(exports, "AllowIfSubPolicyAllowsRule", { enumerable: true,
111
111
  Object.defineProperty(exports, "AllowIfViewerPrivacyPolicy", { enumerable: true, get: function () { return privacy_1.AllowIfViewerPrivacyPolicy; } });
112
112
  Object.defineProperty(exports, "AllowIfViewerHasIdentityPrivacyPolicy", { enumerable: true, get: function () { return privacy_1.AllowIfViewerHasIdentityPrivacyPolicy; } });
113
113
  __exportStar(require("./core/query"), exports);
114
+ __exportStar(require("./core/query_impl"), exports);
114
115
  __exportStar(require("./schema/"), exports);
115
116
  const q = __importStar(require("./core/clause"));
116
117
  const query = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@snowtop/ent",
3
- "version": "0.1.0-alpha153",
3
+ "version": "0.1.0-alpha155",
4
4
  "description": "snowtop ent framework",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -1,5 +1,6 @@
1
1
  import { Schema, Field, AssocEdge, AssocEdgeGroup, Action } from "../schema";
2
- import { ActionField, Type, GlobalSchema, TransformReadBetaResult, CanViewerDo } from "../schema/schema";
2
+ import { ActionField, Type, FieldMap, GlobalSchema, TransformReadBetaResult, CanViewerDo } from "../schema/schema";
3
+ export declare function processFields(src: FieldMap | Field[], patternName?: string): Promise<ProcessedField[]>;
3
4
  declare enum NullableResult {
4
5
  CONTENTS = "contents",
5
6
  CONTENTS_AND_LIST = "contentsAndList",
@@ -48,7 +49,7 @@ type ProcessedType = Omit<Type, "subFields" | "listElemType" | "unionFields"> &
48
49
  listElemType?: ProcessedType;
49
50
  unionFields?: ProcessedField[];
50
51
  };
51
- type ProcessedField = Omit<Field, "defaultValueOnEdit" | "defaultValueOnCreate" | "privacyPolicy" | "type" | "serverDefault"> & {
52
+ export type ProcessedField = Omit<Field, "defaultValueOnEdit" | "defaultValueOnCreate" | "privacyPolicy" | "type" | "serverDefault"> & {
52
53
  name: string;
53
54
  hasDefaultValueOnCreate?: boolean;
54
55
  hasDefaultValueOnEdit?: boolean;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseSchema = void 0;
3
+ exports.parseSchema = exports.processFields = void 0;
4
4
  const cosmiconfig_1 = require("cosmiconfig");
5
5
  const const_1 = require("../core/const");
6
6
  const global_schema_1 = require("../core/global_schema");
@@ -87,6 +87,7 @@ async function processFields(src, patternName) {
87
87
  }
88
88
  return ret;
89
89
  }
90
+ exports.processFields = processFields;
90
91
  async function transformServerDefault(name, f, value) {
91
92
  if (f.valid) {
92
93
  if (!(await f.valid(value))) {
@@ -182,51 +182,39 @@ async function captureDynamic(filePath, gqlCapture) {
182
182
  return;
183
183
  }
184
184
  let json = json5_1.default.parse(datas.join(""));
185
- for (const k in json) {
186
- const v = json[k];
187
- switch (k) {
188
- case "queries":
189
- processTopLevel(v, gqlCapture.getCustomQueries(), gqlCapture);
190
- break;
191
- case "mutations":
192
- processTopLevel(v, gqlCapture.getCustomMutations(), gqlCapture);
193
- break;
194
- case "customTypes":
195
- processCustomTypes(v, gqlCapture);
196
- break;
197
- default:
198
- reject(new Error(`key ${k} is unsupported in dynamic custom graphql. only queries and mutations are supported`));
199
- }
200
- }
185
+ processJSON(gqlCapture, json);
201
186
  resolve(undefined);
202
187
  });
203
188
  });
204
189
  }
190
+ async function processJSON(gqlCapture, json) {
191
+ if (json.fields) {
192
+ for (const k in json.fields) {
193
+ processCustomFields(json.fields[k], gqlCapture, k);
194
+ }
195
+ }
196
+ if (json.inputs) {
197
+ processCustomObjects(json.inputs, gqlCapture, true);
198
+ }
199
+ if (json.objects) {
200
+ processCustomObjects(json.objects, gqlCapture);
201
+ }
202
+ if (json.queries) {
203
+ processTopLevel(json.queries, gqlCapture.getCustomQueries(), gqlCapture);
204
+ }
205
+ if (json.mutations) {
206
+ processTopLevel(json.mutations, gqlCapture.getCustomMutations(), gqlCapture);
207
+ }
208
+ if (json.customTypes) {
209
+ processCustomTypes(json.customTypes, gqlCapture);
210
+ }
211
+ }
205
212
  async function captureCustom(filePath, filesCsv, jsonPath, gqlCapture) {
206
213
  if (jsonPath !== undefined) {
207
214
  let json = json5_1.default.parse(fs.readFileSync(jsonPath, {
208
215
  encoding: "utf8",
209
216
  }));
210
- if (json.fields) {
211
- for (const k in json.fields) {
212
- processCustomFields(json.fields[k], gqlCapture, k);
213
- }
214
- }
215
- if (json.inputs) {
216
- processCustomObjects(json.inputs, gqlCapture, true);
217
- }
218
- if (json.objects) {
219
- processCustomObjects(json.objects, gqlCapture);
220
- }
221
- if (json.queries) {
222
- processTopLevel(json.queries, gqlCapture.getCustomQueries(), gqlCapture);
223
- }
224
- if (json.mutations) {
225
- processTopLevel(json.mutations, gqlCapture.getCustomMutations(), gqlCapture);
226
- }
227
- if (json.customTypes) {
228
- processCustomTypes(json.customTypes, gqlCapture);
229
- }
217
+ processJSON(gqlCapture, json);
230
218
  return;
231
219
  }
232
220
  if (filesCsv !== undefined) {
@@ -431,9 +419,13 @@ async function main() {
431
419
  const buildClasses = (fields) => {
432
420
  fields.forEach((field) => {
433
421
  if (field.nodeName && !nodesMap.has(field.nodeName)) {
434
- let info = imports.getInfoForClass(field.nodeName);
435
- classes[field.nodeName] = { ...info.class, path: info.file.path };
436
- buildFiles(info.file);
422
+ // TODO don't necessarily wanna do this
423
+ try {
424
+ let info = imports.getInfoForClass(field.nodeName);
425
+ classes[field.nodeName] = { ...info.class, path: info.file.path };
426
+ buildFiles(info.file);
427
+ }
428
+ catch (err) { }
437
429
  }
438
430
  buildClasses2(field.args);
439
431
  buildClasses2(field.results);
@@ -1,15 +0,0 @@
1
- import { ID, SelectBaseDataOptions, Context, Data, LoaderFactory, EdgeQueryableDataOptions, Loader } from "../base";
2
- import * as clause from "../clause";
3
- import { OrderBy } from "../query_impl";
4
- import { ObjectLoaderFactory } from "./object_loader";
5
- export declare class IndexLoaderFactory implements LoaderFactory<ID, Data[]> {
6
- name: string;
7
- private factory;
8
- constructor(options: SelectBaseDataOptions, col: string, opts?: {
9
- extraClause?: clause.Clause;
10
- orderby?: OrderBy;
11
- toPrime?: ObjectLoaderFactory<Data>[];
12
- });
13
- createLoader(context?: Context): any;
14
- createConfigurableLoader(options: EdgeQueryableDataOptions, context?: Context): Loader<ID, Data[]>;
15
- }
@@ -1,27 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.IndexLoaderFactory = void 0;
4
- const query_loader_1 = require("./query_loader");
5
- // we're keeping this for legacy reasons so as to not break existing callers
6
- // and to decouple the change here but all callers can safely be changed here to use QueryLoaderFactory
7
- // @deprecated use QueryLoaderFactory
8
- class IndexLoaderFactory {
9
- constructor(options, col, opts) {
10
- this.factory = new query_loader_1.QueryLoaderFactory({
11
- fields: options.fields,
12
- tableName: options.tableName,
13
- groupCol: col,
14
- clause: opts?.extraClause,
15
- orderby: opts?.orderby,
16
- toPrime: opts?.toPrime,
17
- });
18
- this.name = `indexLoader:${options.tableName}:${col}`;
19
- }
20
- createLoader(context) {
21
- return this.factory.createLoader(context);
22
- }
23
- createConfigurableLoader(options, context) {
24
- return this.factory.createConfigurableLoader(options, context);
25
- }
26
- }
27
- exports.IndexLoaderFactory = IndexLoaderFactory;