@snowtop/ent 0.1.5 → 0.1.7-test8

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/clause.d.ts CHANGED
@@ -115,6 +115,7 @@ export declare function JSONObjectFieldKeyASJSON<T extends Data, K = keyof T>(co
115
115
  export declare function JSONObjectFieldKeyAsText<T extends Data, K = keyof T>(col: K, field: string): keyof T;
116
116
  type predicate = "==" | ">" | "<" | "!=" | ">=" | "<=";
117
117
  export declare function JSONPathValuePredicate<T extends Data, K = keyof T>(dbCol: K, path: string, val: any, pred: predicate): Clause<T, K>;
118
+ export declare function JSONKeyExists<T extends Data, K = keyof T>(dbCol: K, val: any): Clause<T, K>;
118
119
  export declare function PaginationMultipleColsSubQuery<T extends Data, K = keyof T>(col: K, op: string, tableName: string, uniqueCol: K, val: any): Clause<T, K>;
119
120
  export declare function Add<T extends Data, K = keyof T>(col: K, value: any): Clause<T, K>;
120
121
  export declare function Subtract<T extends Data, K = keyof T>(col: K, value: any): Clause<T, K>;
package/core/clause.js CHANGED
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.getCombinedClause = exports.Modulo = exports.Divide = exports.Multiply = exports.Subtract = exports.Add = exports.PaginationMultipleColsSubQuery = exports.JSONPathValuePredicate = exports.JSONObjectFieldKeyAsText = exports.JSONObjectFieldKeyASJSON = exports.sensitiveValue = exports.TsVectorWebsearchToTsQuery = exports.TsVectorPhraseToTsQuery = exports.TsVectorPlainToTsQuery = exports.TsVectorColTsQuery = exports.WebsearchToTsQuery = exports.PhraseToTsQuery = exports.PlainToTsQuery = exports.TsQuery = exports.DBTypeNotIn = exports.TextNotIn = exports.IntegerNotIn = exports.UuidNotIn = exports.DBTypeIn = exports.TextIn = exports.IntegerIn = exports.UuidIn = exports.In = exports.OrOptional = exports.Or = exports.AndOptional = exports.And = exports.LessEq = exports.GreaterEq = exports.Less = exports.Greater = exports.NotEq = exports.Eq = exports.ArrayNotEq = exports.ArrayEq = exports.PostgresArrayNotOverlaps = exports.PostgresArrayOverlaps = exports.PostgresArrayNotContains = exports.PostgresArrayNotContainsValue = exports.PostgresArrayContains = exports.PostgresArrayContainsValue = exports.notInClause = exports.inClause = void 0;
26
+ exports.getCombinedClause = exports.Modulo = exports.Divide = exports.Multiply = exports.Subtract = exports.Add = exports.PaginationMultipleColsSubQuery = exports.JSONKeyExists = exports.JSONPathValuePredicate = exports.JSONObjectFieldKeyAsText = exports.JSONObjectFieldKeyASJSON = exports.sensitiveValue = exports.TsVectorWebsearchToTsQuery = exports.TsVectorPhraseToTsQuery = exports.TsVectorPlainToTsQuery = exports.TsVectorColTsQuery = exports.WebsearchToTsQuery = exports.PhraseToTsQuery = exports.PlainToTsQuery = exports.TsQuery = exports.DBTypeNotIn = exports.TextNotIn = exports.IntegerNotIn = exports.UuidNotIn = exports.DBTypeIn = exports.TextIn = exports.IntegerIn = exports.UuidIn = exports.In = exports.OrOptional = exports.Or = exports.AndOptional = exports.And = exports.LessEq = exports.GreaterEq = exports.Less = exports.Greater = exports.NotEq = exports.Eq = exports.ArrayNotEq = exports.ArrayEq = exports.PostgresArrayNotOverlaps = exports.PostgresArrayOverlaps = exports.PostgresArrayNotContains = exports.PostgresArrayNotContainsValue = exports.PostgresArrayContains = exports.PostgresArrayContainsValue = exports.notInClause = exports.inClause = void 0;
27
27
  const db_1 = __importStar(require("./db"));
28
28
  function isSensitive(val) {
29
29
  return (val !== null &&
@@ -725,6 +725,10 @@ function JSONPathValuePredicate(dbCol, path, val, pred) {
725
725
  return new jSONPathValuePredicateClause(dbCol, path, val, pred);
726
726
  }
727
727
  exports.JSONPathValuePredicate = JSONPathValuePredicate;
728
+ function JSONKeyExists(dbCol, val) {
729
+ return new simpleClause(dbCol, val, "?", new isNullClause(dbCol));
730
+ }
731
+ exports.JSONKeyExists = JSONKeyExists;
728
732
  // TODO need a better name for this lol
729
733
  // this assumes we're doing the same direction twice which isn't necessarily accurate in the future...
730
734
  class paginationMultipleColumnsSubQueryClause {
@@ -1,4 +1,4 @@
1
- import { GraphQLScalarType } from "graphql";
1
+ import { GraphQLEnumType, GraphQLScalarType } from "graphql";
2
2
  import type { FieldMap } from "../schema";
3
3
  import { ProcessedField as ParsedProcessedField } from "../parse_schema/parse";
4
4
  import { ImportPath } from "../schema/schema";
@@ -66,7 +66,7 @@ export interface CustomTypeInput {
66
66
  export type CustomType = Omit<CustomTypeInput, "structFields"> & {
67
67
  structFields?: ParsedProcessedField[];
68
68
  };
69
- type Type = GraphQLScalarType | ClassType | string | CustomTypeInput;
69
+ type Type = GraphQLScalarType | GraphQLEnumType | ClassType | string | CustomTypeInput;
70
70
  export type GraphQLConnection<T> = {
71
71
  node: T;
72
72
  };
@@ -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 graphql_1 = require("graphql");
4
5
  const parse_1 = require("../parse_schema/parse");
5
6
  var CustomFieldType;
6
7
  (function (CustomFieldType) {
@@ -61,7 +62,10 @@ const isCustomType = (type) => {
61
62
  };
62
63
  exports.isCustomType = isCustomType;
63
64
  const isGraphQLScalarType = (type) => {
64
- return type.serialize !== undefined;
65
+ return (0, graphql_1.isScalarType)(type);
66
+ };
67
+ const isGraphQLEnumType = (type) => {
68
+ return (0, graphql_1.isEnumType)(type);
65
69
  };
66
70
  const addCustomType = async (type, gqlCapture) => {
67
71
  // TODO these should return ReadOnly objects...
@@ -81,28 +85,30 @@ const addCustomType = async (type, gqlCapture) => {
81
85
  if (type.enumMap || type.structFields) {
82
86
  await addType(type);
83
87
  }
84
- try {
85
- const r = require(type.importPath);
86
- const ct = r[type.type];
87
- // this gets us the information needed for scalars
88
- if (ct && isGraphQLScalarType(ct)) {
89
- type.scalarInfo = {
90
- description: ct.description,
91
- name: ct.name,
92
- };
93
- if (ct.specifiedByURL) {
94
- type.scalarInfo.specifiedByUrl = ct.specifiedByURL;
88
+ if (type.importPath) {
89
+ try {
90
+ const r = require(type.importPath);
91
+ const ct = r[type.type];
92
+ // this gets us the information needed for scalars
93
+ if (ct && isGraphQLScalarType(ct)) {
94
+ type.scalarInfo = {
95
+ description: ct.description,
96
+ name: ct.name,
97
+ };
98
+ if (ct.specifiedByURL) {
99
+ type.scalarInfo.specifiedByUrl = ct.specifiedByURL;
100
+ }
95
101
  }
96
102
  }
97
- }
98
- catch (e) {
99
- if (type.secondaryImportPath) {
100
- (0, exports.addCustomType)({
101
- ...type,
102
- importPath: type.secondaryImportPath,
103
- }, gqlCapture);
103
+ catch (e) {
104
+ if (type.secondaryImportPath) {
105
+ await (0, exports.addCustomType)({
106
+ ...type,
107
+ importPath: type.secondaryImportPath,
108
+ }, gqlCapture);
109
+ }
110
+ return;
104
111
  }
105
- return;
106
112
  }
107
113
  if (customType) {
108
114
  if (JSON.stringify(customType) !== JSON.stringify(type)) {
@@ -138,8 +144,9 @@ const getType = (typ, result) => {
138
144
  (0, exports.addCustomType)(typ, GQLCapture);
139
145
  return;
140
146
  }
141
- // GraphQLScalarType or ClassType
147
+ // GraphQLScalarType or GraphQLEnumType or ClassType
142
148
  result.scalarType = isGraphQLScalarType(typ);
149
+ result.enumType = isGraphQLEnumType(typ);
143
150
  result.type = typ.name;
144
151
  return;
145
152
  };
@@ -193,6 +200,10 @@ class GQLCapture {
193
200
  if (fd.nullable === undefined) {
194
201
  return res;
195
202
  }
203
+ if (fd.nullable === false) {
204
+ delete res.nullable;
205
+ return res;
206
+ }
196
207
  if (fd.nullable === "contents") {
197
208
  res.nullable = NullableResult.CONTENTS;
198
209
  }
@@ -234,11 +245,13 @@ class GQLCapture {
234
245
  let scalarType = false;
235
246
  let connection;
236
247
  let type = "";
248
+ let enumType = false;
237
249
  if (field?.type) {
238
250
  let r = { type: "" };
239
251
  getType(field.type, r);
240
252
  list = r.list;
241
253
  scalarType = r.scalarType || false;
254
+ enumType = r.enumType || false;
242
255
  connection = r.connection;
243
256
  type = r.type;
244
257
  }
@@ -260,9 +273,14 @@ class GQLCapture {
260
273
  };
261
274
  // unknown type. we need to flag that this field needs to eventually be resolved
262
275
  if (!exports.knownAllowedNames.has(type)) {
276
+ // we do this so that we know how to import them later
277
+ // would be nice not to need that. seems like we should be able to do it by checking the imports for the page
263
278
  if (scalarType) {
264
279
  throw new Error(`custom scalar type ${type} is not supported this way. use CustomType syntax. see \`gqlFileUpload\` as an example`);
265
280
  }
281
+ if (enumType) {
282
+ throw new Error(`custom enum type ${type} is not supported this way. use CustomType syntax. see \`gqlFileUpload\` as an example`);
283
+ }
266
284
  result.needsResolving = true;
267
285
  }
268
286
  return result;
@@ -478,13 +496,12 @@ class GQLCapture {
478
496
  }
479
497
  });
480
498
  });
481
- // TODO this should be aware of knownCustomTypes
482
499
  const resolveFields = (fields) => {
483
500
  fields.forEach((field) => {
484
501
  // we have a check earlier that *should* make this path impossible
485
502
  field.args.forEach((arg) => {
486
503
  if (arg.needsResolving) {
487
- if (baseArgs.has(arg.type)) {
504
+ if (baseArgs.has(arg.type) || this.customTypes.has(arg.type)) {
488
505
  arg.needsResolving = false;
489
506
  }
490
507
  else {
@@ -501,7 +518,8 @@ class GQLCapture {
501
518
  if (result.needsResolving) {
502
519
  if (baseObjects.has(result.type) ||
503
520
  this.customUnions.has(result.type) ||
504
- this.customInterfaces.has(result.type)) {
521
+ this.customInterfaces.has(result.type) ||
522
+ this.customTypes.has(result.type)) {
505
523
  result.needsResolving = false;
506
524
  }
507
525
  else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@snowtop/ent",
3
- "version": "0.1.5",
3
+ "version": "0.1.7-test8",
4
4
  "description": "snowtop ent framework",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",