@snowtop/ent 0.0.35 → 0.0.38

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/core/config.d.ts CHANGED
@@ -1,6 +1,14 @@
1
1
  /// <reference types="node" />
2
2
  import { Database, DBDict } from "./db";
3
3
  declare type logType = "query" | "warn" | "info" | "error" | "debug";
4
+ declare enum graphqlMutationName {
5
+ NOUN_VERB = "NounVerb",
6
+ VERB_NOUN = "VerbNoun"
7
+ }
8
+ declare enum graphQLFieldFormat {
9
+ LOWER_CAMEL = "lowerCamel",
10
+ SNAKE_CASE = "snake_case"
11
+ }
4
12
  export interface Config {
5
13
  dbConnectionString?: string;
6
14
  dbFile?: string;
@@ -17,6 +25,8 @@ interface CodegenConfig {
17
25
  generatedHeader?: string;
18
26
  disableBase64Encoding?: boolean;
19
27
  generateRootResolvers?: boolean;
28
+ defaultGraphQLMutationName?: graphqlMutationName;
29
+ defaultGraphQLFieldFormat?: graphQLFieldFormat;
20
30
  }
21
31
  interface PrettierConfig {
22
32
  custom?: boolean;
package/core/config.js CHANGED
@@ -28,6 +28,18 @@ const js_yaml_1 = require("js-yaml");
28
28
  const db_1 = __importDefault(require("./db"));
29
29
  const path = __importStar(require("path"));
30
30
  const logger_1 = require("./logger");
31
+ // ent.config.ts eventually. for now ent.yml
32
+ // or ent.yml?
33
+ var graphqlMutationName;
34
+ (function (graphqlMutationName) {
35
+ graphqlMutationName["NOUN_VERB"] = "NounVerb";
36
+ graphqlMutationName["VERB_NOUN"] = "VerbNoun";
37
+ })(graphqlMutationName || (graphqlMutationName = {}));
38
+ var graphQLFieldFormat;
39
+ (function (graphQLFieldFormat) {
40
+ graphQLFieldFormat["LOWER_CAMEL"] = "lowerCamel";
41
+ graphQLFieldFormat["SNAKE_CASE"] = "snake_case";
42
+ })(graphQLFieldFormat || (graphQLFieldFormat = {}));
31
43
  function setConfig(cfg) {
32
44
  if (cfg.log) {
33
45
  (0, logger_1.setLogLevels)(cfg.log);
@@ -32,7 +32,7 @@ export declare class AssocEdgeLoaderFactory<T extends AssocEdge> implements Load
32
32
  name: string;
33
33
  constructor(edgeType: string, edgeCtr: AssocEdgeConstructor<T> | (() => AssocEdgeConstructor<T>));
34
34
  createLoader(context?: Context): AssocLoader<T>;
35
- private isFunction;
35
+ private isConstructor;
36
36
  createConfigurableLoader(options: EdgeQueryableDataOptions, context?: Context): AssocLoader<T>;
37
37
  }
38
38
  export {};
@@ -161,16 +161,17 @@ class AssocEdgeLoaderFactory {
161
161
  createLoader(context) {
162
162
  return this.createConfigurableLoader({}, context);
163
163
  }
164
- isFunction(edgeCtr) {
165
- // not constructor
166
- return !(edgeCtr.prototype && edgeCtr.prototype.constructor === edgeCtr);
164
+ isConstructor(edgeCtr) {
165
+ return (edgeCtr.prototype &&
166
+ edgeCtr.prototype.constructor &&
167
+ edgeCtr.prototype.constructor.name.length > 0);
167
168
  }
168
169
  createConfigurableLoader(options, context) {
169
170
  let edgeCtr = this.edgeCtr;
170
171
  // in generated code, the edge is not necessarily defined at the time of loading
171
172
  // so we call this as follows:
172
173
  // const loader = new AssocEdgeLoaderFactory(EdgeType.Foo, ()=>DerivedEdgeClass);
173
- if (this.isFunction(edgeCtr)) {
174
+ if (!this.isConstructor(edgeCtr)) {
174
175
  edgeCtr = edgeCtr();
175
176
  }
176
177
  // rename to make TS happy
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@snowtop/ent",
3
- "version": "0.0.35",
3
+ "version": "0.0.38",
4
4
  "description": "snowtop ent framework",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -17,7 +17,7 @@
17
17
  "json5": "^2.1.3",
18
18
  "luxon": "^1.25.0",
19
19
  "memoizee": "^0.4.15",
20
- "minimist": "^1.2.5",
20
+ "minimist": "^1.2.6",
21
21
  "pascal-case": "^3.1.2",
22
22
  "pg": "^8.0.3",
23
23
  "prettier": "^2.3.2",
@@ -31,10 +31,29 @@ function processFields(src, patternName) {
31
31
  if (patternName) {
32
32
  f.patternName = patternName;
33
33
  }
34
+ transformType(field.type);
34
35
  ret.push(f);
35
36
  }
36
37
  return ret;
37
38
  }
39
+ function transformImportType(typ) {
40
+ if (!typ.importType) {
41
+ return;
42
+ }
43
+ typ.importType = {
44
+ ...typ.importType,
45
+ // these 2 needed for forwards compatibility with new go schema
46
+ importPath: typ.importType.path,
47
+ import: typ.importType.type,
48
+ };
49
+ }
50
+ function transformType(typ) {
51
+ if (!typ) {
52
+ return;
53
+ }
54
+ transformImportType(typ);
55
+ transformType(typ.listElemType);
56
+ }
38
57
  function processEdges(src, patternName) {
39
58
  const ret = [];
40
59
  for (const edge of src) {
@@ -82,6 +82,7 @@ export declare enum DBType {
82
82
  export interface ImportType {
83
83
  path: string;
84
84
  type: string;
85
+ [x: string]: any;
85
86
  }
86
87
  declare type EnumMap = {
87
88
  [key: string]: string;
@@ -131,6 +132,7 @@ export interface FieldOptions {
131
132
  fieldEdge?: FieldEdge;
132
133
  primaryKey?: boolean;
133
134
  disableUserEditable?: boolean;
135
+ disableUserGraphQLEditable?: boolean;
134
136
  defaultValueOnCreate?(builder: Builder<Ent>, input: Data): any;
135
137
  defaultToViewerOnCreate?: boolean;
136
138
  defaultValueOnEdit?(builder: Builder<Ent>, input: Data): any;
@@ -16,6 +16,8 @@ interface queryConfig {
16
16
  callback?: (res: supertest.Response) => void;
17
17
  inlineFragmentRoot?: string;
18
18
  customHandlers?: RequestHandler[];
19
+ server?: any;
20
+ graphQLPath?: string;
19
21
  }
20
22
  export interface queryRootConfig extends queryConfig {
21
23
  root: string;
@@ -56,7 +56,7 @@ function server(config) {
56
56
  };
57
57
  return doWork();
58
58
  }));
59
- app.use("/graphql", ...handlers);
59
+ app.use(config.graphQLPath || "/graphql", ...handlers);
60
60
  return app;
61
61
  }
62
62
  function getInnerType(typ, list) {
@@ -72,14 +72,14 @@ function makeGraphQLRequest(config, query, fieldArgs) {
72
72
  let test;
73
73
  if (config.test) {
74
74
  if (typeof config.test === "function") {
75
- test = config.test(server(config));
75
+ test = config.test(config.server ? config.server : server(config));
76
76
  }
77
77
  else {
78
78
  test = config.test;
79
79
  }
80
80
  }
81
81
  else {
82
- test = (0, supertest_1.default)(server(config));
82
+ test = (0, supertest_1.default)(config.server ? config.server : server(config));
83
83
  }
84
84
  let files = new Map();
85
85
  // handle files
@@ -104,7 +104,9 @@ function makeGraphQLRequest(config, query, fieldArgs) {
104
104
  }
105
105
  });
106
106
  if (files.size) {
107
- let ret = test.post("/graphql").set(config.headers || {});
107
+ let ret = test
108
+ .post(config.graphQLPath || "/graphql")
109
+ .set(config.headers || {});
108
110
  ret.field("operations", JSON.stringify({
109
111
  query: query,
110
112
  variables: config.args,
@@ -130,7 +132,7 @@ function makeGraphQLRequest(config, query, fieldArgs) {
130
132
  return [
131
133
  test,
132
134
  test
133
- .post("/graphql")
135
+ .post(config.graphQLPath || "/graphql")
134
136
  .set(config.headers || {})
135
137
  .send({
136
138
  query: query,