@snowtop/ent 0.1.0-alpha1 → 0.1.0-alpha13

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 (83) hide show
  1. package/action/action.d.ts +17 -13
  2. package/action/executor.d.ts +2 -2
  3. package/action/experimental_action.d.ts +4 -4
  4. package/action/experimental_action.js +1 -1
  5. package/action/orchestrator.d.ts +24 -9
  6. package/action/orchestrator.js +150 -39
  7. package/action/privacy.d.ts +2 -2
  8. package/core/base.d.ts +6 -2
  9. package/core/base.js +16 -0
  10. package/core/clause.d.ts +24 -3
  11. package/core/clause.js +246 -5
  12. package/core/config.d.ts +18 -0
  13. package/core/config.js +17 -0
  14. package/core/db.d.ts +3 -3
  15. package/core/db.js +2 -0
  16. package/core/ent.d.ts +2 -4
  17. package/core/ent.js +72 -25
  18. package/core/loaders/assoc_edge_loader.d.ts +1 -1
  19. package/core/loaders/assoc_edge_loader.js +5 -4
  20. package/core/loaders/index_loader.js +1 -0
  21. package/core/loaders/object_loader.d.ts +7 -2
  22. package/core/loaders/object_loader.js +59 -4
  23. package/core/privacy.d.ts +1 -1
  24. package/core/privacy.js +3 -0
  25. package/core/viewer.d.ts +1 -0
  26. package/core/viewer.js +4 -0
  27. package/graphql/builtins/connection.js +3 -3
  28. package/graphql/builtins/edge.js +2 -2
  29. package/graphql/builtins/node.js +1 -1
  30. package/graphql/graphql.d.ts +3 -2
  31. package/graphql/graphql.js +24 -23
  32. package/graphql/index.d.ts +1 -0
  33. package/graphql/index.js +3 -1
  34. package/graphql/mutations/union.d.ts +2 -0
  35. package/graphql/mutations/union.js +35 -0
  36. package/graphql/node_resolver.d.ts +0 -1
  37. package/graphql/query/connection_type.js +6 -6
  38. package/graphql/query/page_info.js +4 -4
  39. package/graphql/query/shared_assoc_test.js +2 -2
  40. package/graphql/scalars/time.d.ts +1 -1
  41. package/index.d.ts +16 -1
  42. package/index.js +18 -5
  43. package/package.json +3 -3
  44. package/parse_schema/parse.d.ts +21 -4
  45. package/parse_schema/parse.js +79 -8
  46. package/schema/base_schema.d.ts +36 -1
  47. package/schema/base_schema.js +48 -2
  48. package/schema/field.d.ts +1 -1
  49. package/schema/field.js +11 -3
  50. package/schema/index.d.ts +4 -2
  51. package/schema/index.js +10 -1
  52. package/schema/schema.d.ts +66 -4
  53. package/schema/schema.js +138 -5
  54. package/schema/struct_field.d.ts +17 -0
  55. package/schema/struct_field.js +102 -0
  56. package/schema/union_field.d.ts +23 -0
  57. package/schema/union_field.js +79 -0
  58. package/scripts/custom_graphql.js +122 -15
  59. package/scripts/move_generated.d.ts +1 -0
  60. package/scripts/move_generated.js +142 -0
  61. package/scripts/read_schema.js +15 -1
  62. package/scripts/transform_code.d.ts +1 -0
  63. package/scripts/transform_code.js +113 -0
  64. package/scripts/transform_schema.js +190 -123
  65. package/testutils/builder.d.ts +27 -18
  66. package/testutils/builder.js +82 -10
  67. package/testutils/context/test_context.d.ts +2 -2
  68. package/testutils/context/test_context.js +7 -1
  69. package/testutils/db/test_db.d.ts +2 -1
  70. package/testutils/db/test_db.js +13 -4
  71. package/testutils/ent-graphql-tests/index.d.ts +2 -0
  72. package/testutils/ent-graphql-tests/index.js +26 -17
  73. package/testutils/fake_data/fake_contact.d.ts +4 -8
  74. package/testutils/fake_data/fake_contact.js +15 -19
  75. package/testutils/fake_data/fake_event.d.ts +4 -8
  76. package/testutils/fake_data/fake_event.js +21 -25
  77. package/testutils/fake_data/fake_user.d.ts +5 -9
  78. package/testutils/fake_data/fake_user.js +23 -27
  79. package/testutils/fake_data/test_helpers.js +1 -1
  80. package/tsc/ast.d.ts +21 -0
  81. package/tsc/ast.js +154 -0
  82. package/tsc/compilerOptions.d.ts +6 -0
  83. package/tsc/compilerOptions.js +40 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@snowtop/ent",
3
- "version": "0.1.0-alpha1",
3
+ "version": "0.1.0-alpha13",
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,7 +31,7 @@
31
31
  },
32
32
  "peerDependencies": {
33
33
  "better-sqlite3": "^7.4.1",
34
- "graphql": "^15.5"
34
+ "graphql": "^16.5.0"
35
35
  },
36
36
  "peerDependenciesMeta": {
37
37
  "better-sqlite3": {
@@ -1,5 +1,5 @@
1
1
  import { Schema, Field, AssocEdge, AssocEdgeGroup, Action } from "../schema";
2
- import { ActionField } from "../schema/schema";
2
+ import { ActionField, Type } from "../schema/schema";
3
3
  declare enum NullableResult {
4
4
  CONTENTS = "contents",
5
5
  CONTENTS_AND_LIST = "contentsAndList",
@@ -12,11 +12,18 @@ declare type ProcessedAssocEdge = Omit<AssocEdge, "actionOnlyFields" | "edgeActi
12
12
  patternName?: string;
13
13
  edgeActions?: OutputAction[];
14
14
  };
15
- declare type ProcessedSchema = Omit<Schema, "edges" | "actions" | "edgeGroups" | "fields"> & {
15
+ interface TransformFlags {
16
+ transformsSelect?: boolean;
17
+ transformsDelete?: boolean;
18
+ transformsInsert?: boolean;
19
+ transformsUpdate?: boolean;
20
+ }
21
+ declare type ProcessedSchema = Omit<Schema, "edges" | "actions" | "edgeGroups" | "fields"> & TransformFlags & {
16
22
  actions: OutputAction[];
17
23
  assocEdges: ProcessedAssocEdge[];
18
24
  assocEdgeGroups: ProcessedAssocEdgeGroup[];
19
25
  fields: ProcessedField[];
26
+ schemaPath?: string;
20
27
  };
21
28
  declare type ProcessedAssocEdgeGroup = Omit<AssocEdgeGroup, "edgeAction"> & {
22
29
  edgeAction?: OutputAction;
@@ -32,12 +39,19 @@ interface ProcessedPattern {
32
39
  assocEdges: ProcessedAssocEdge[];
33
40
  fields: ProcessedField[];
34
41
  }
35
- declare type ProcessedField = Omit<Field, "defaultValueOnEdit" | "defaultValueOnCreate"> & {
42
+ declare type ProcessedType = Omit<Type, "subFields" | "listElemType" | "unionFields"> & {
43
+ subFields?: ProcessedField[];
44
+ listElemType?: ProcessedType;
45
+ unionFields?: ProcessedField[];
46
+ };
47
+ declare type ProcessedField = Omit<Field, "defaultValueOnEdit" | "defaultValueOnCreate" | "privacyPolicy" | "type"> & {
36
48
  name: string;
37
49
  hasDefaultValueOnCreate?: boolean;
38
50
  hasDefaultValueOnEdit?: boolean;
39
51
  patternName?: string;
52
+ hasFieldPrivacy?: boolean;
40
53
  derivedFields?: ProcessedField[];
54
+ type: ProcessedType;
41
55
  };
42
56
  interface patternsDict {
43
57
  [key: string]: ProcessedPattern;
@@ -46,5 +60,8 @@ interface Result {
46
60
  schemas: schemasDict;
47
61
  patterns: patternsDict;
48
62
  }
49
- export declare function parseSchema(potentialSchemas: {}): Result;
63
+ declare type PotentialSchemas = {
64
+ [key: string]: any;
65
+ };
66
+ export declare function parseSchema(potentialSchemas: PotentialSchemas): Result;
50
67
  export {};
@@ -3,11 +3,26 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseSchema = void 0;
4
4
  function processFields(src, patternName) {
5
5
  const ret = [];
6
- for (const name in src) {
7
- const field = src[name];
6
+ let m = {};
7
+ if (Array.isArray(src)) {
8
+ for (const field of src) {
9
+ const name = field.name;
10
+ if (!name) {
11
+ throw new Error(`name is required`);
12
+ }
13
+ m[name] = field;
14
+ }
15
+ }
16
+ else {
17
+ m = src;
18
+ }
19
+ for (const name in m) {
20
+ const field = m[name];
21
+ //@ts-ignore type and other changed fields with different type in ProcessedField vs Field
8
22
  let f = { name, ...field };
9
23
  f.hasDefaultValueOnCreate = field.defaultValueOnCreate != undefined;
10
24
  f.hasDefaultValueOnEdit = field.defaultValueOnEdit != undefined;
25
+ f.hasFieldPrivacy = field.privacyPolicy !== undefined;
11
26
  if (field.polymorphic) {
12
27
  // convert boolean into object
13
28
  // we keep boolean as an option to keep API simple
@@ -32,13 +47,44 @@ function processFields(src, patternName) {
32
47
  if (patternName) {
33
48
  f.patternName = patternName;
34
49
  }
50
+ transformType(field.type);
35
51
  if (field.getDerivedFields) {
36
52
  f.derivedFields = processFields(field.getDerivedFields(name));
37
53
  }
54
+ if (field.type.subFields) {
55
+ f.type.subFields = processFields(field.type.subFields);
56
+ }
57
+ if (field.type.unionFields) {
58
+ f.type.unionFields = processFields(field.type.unionFields);
59
+ }
60
+ if (field.type.listElemType &&
61
+ field.type.listElemType.subFields &&
62
+ // check to avoid ts-ignore below. exists just for tsc
63
+ f.type.listElemType) {
64
+ f.type.listElemType.subFields = processFields(field.type.listElemType.subFields);
65
+ }
38
66
  ret.push(f);
39
67
  }
40
68
  return ret;
41
69
  }
70
+ function transformImportType(typ) {
71
+ if (!typ.importType) {
72
+ return;
73
+ }
74
+ typ.importType = {
75
+ ...typ.importType,
76
+ // these 2 needed for forwards compatibility with new go schema
77
+ importPath: typ.importType.path,
78
+ import: typ.importType.type,
79
+ };
80
+ }
81
+ function transformType(typ) {
82
+ if (!typ) {
83
+ return;
84
+ }
85
+ transformImportType(typ);
86
+ transformType(typ.listElemType);
87
+ }
42
88
  function processEdges(src, patternName) {
43
89
  const ret = [];
44
90
  for (const edge of src) {
@@ -63,6 +109,9 @@ function processEdgeGroups(processedSchema, edgeGroups) {
63
109
  }
64
110
  }
65
111
  function processPattern(patterns, pattern, processedSchema) {
112
+ let ret = {
113
+ ...pattern,
114
+ };
66
115
  const name = pattern.name;
67
116
  const fields = processFields(pattern.fields, pattern.name);
68
117
  processedSchema.fields.push(...fields);
@@ -70,6 +119,10 @@ function processPattern(patterns, pattern, processedSchema) {
70
119
  const edges = processEdges(pattern.edges, pattern.name);
71
120
  processedSchema.assocEdges.push(...edges);
72
121
  }
122
+ // flag transformsSelect
123
+ if (pattern.transformRead) {
124
+ ret.transformsSelect = true;
125
+ }
73
126
  if (patterns[name] === undefined) {
74
127
  // intentionally processing separately and not passing pattern.name
75
128
  const edges = processEdges(pattern.edges || []);
@@ -83,6 +136,7 @@ function processPattern(patterns, pattern, processedSchema) {
83
136
  // TODO ideally we want to make sure that different patterns don't have the same name
84
137
  // can't do a deepEqual check because function calls and therefore different instances in fields
85
138
  }
139
+ return ret;
86
140
  }
87
141
  var NullableResult;
88
142
  (function (NullableResult) {
@@ -123,14 +177,19 @@ function parseSchema(potentialSchemas) {
123
177
  for (const key in potentialSchemas) {
124
178
  const value = potentialSchemas[key];
125
179
  let schema;
126
- if (value.constructor == Object) {
127
- schema = value;
128
- }
129
- else {
130
- schema = new value();
180
+ const name = value.constructor.name;
181
+ // named class e.g. new BaseEntSchema
182
+ switch (name) {
183
+ case "Function":
184
+ schema = new value();
185
+ break;
186
+ default:
187
+ // implicit schema or named class
188
+ schema = value;
131
189
  }
132
190
  let processedSchema = {
133
191
  fields: [],
192
+ schemaPath: schema.schemaPath,
134
193
  tableName: schema.tableName,
135
194
  enumTable: schema.enumTable,
136
195
  dbRows: schema.dbRows,
@@ -145,7 +204,19 @@ function parseSchema(potentialSchemas) {
145
204
  // ¯\_(ツ)_/¯
146
205
  if (schema.patterns) {
147
206
  for (const pattern of schema.patterns) {
148
- processPattern(patterns, pattern, processedSchema);
207
+ const ret = processPattern(patterns, pattern, processedSchema);
208
+ if (ret.transformsSelect) {
209
+ if (processedSchema.transformsSelect) {
210
+ throw new Error(`can only have one pattern which transforms default querying behavior`);
211
+ }
212
+ processedSchema.transformsSelect = true;
213
+ }
214
+ if (ret.transformsDelete) {
215
+ if (processedSchema.transformsDelete) {
216
+ throw new Error(`can only have one pattern which transforms default deletion behavior`);
217
+ }
218
+ processedSchema.transformsDelete = true;
219
+ }
149
220
  }
150
221
  }
151
222
  const fields = processFields(schema.fields);
@@ -1,6 +1,41 @@
1
- import { Pattern } from "./schema";
1
+ import { Field, FieldMap, Pattern } from "./schema";
2
+ import { Action, AssocEdgeGroup, Constraint, Edge, Index, Schema } from ".";
2
3
  export declare const Timestamps: Pattern;
3
4
  export declare const Node: Pattern;
5
+ export interface SchemaConfig extends Schema {
6
+ }
7
+ export declare class EntSchema implements Schema {
8
+ fields: FieldMap | Field[];
9
+ tableName: string | undefined;
10
+ patterns: Pattern[];
11
+ edges: Edge[] | undefined;
12
+ edgeGroups: AssocEdgeGroup[] | undefined;
13
+ actions: Action[] | undefined;
14
+ enumTable: boolean | undefined;
15
+ dbRows: {
16
+ [key: string]: any;
17
+ }[] | undefined;
18
+ constraints: Constraint[] | undefined;
19
+ indices: Index[] | undefined;
20
+ hideFromGraphQL?: boolean;
21
+ constructor(cfg: SchemaConfig);
22
+ }
23
+ export declare class EntSchemaWithTZ implements Schema {
24
+ fields: FieldMap | Field[];
25
+ tableName: string | undefined;
26
+ patterns: Pattern[];
27
+ edges: Edge[] | undefined;
28
+ edgeGroups: AssocEdgeGroup[] | undefined;
29
+ actions: Action[] | undefined;
30
+ enumTable: boolean | undefined;
31
+ dbRows: {
32
+ [key: string]: any;
33
+ }[] | undefined;
34
+ constraints: Constraint[] | undefined;
35
+ indices: Index[] | undefined;
36
+ hideFromGraphQL?: boolean;
37
+ constructor(cfg: SchemaConfig);
38
+ }
4
39
  export declare abstract class BaseEntSchema {
5
40
  addPatterns(...patterns: Pattern[]): void;
6
41
  patterns: Pattern[];
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BaseEntSchemaWithTZ = exports.BaseEntSchema = exports.Node = exports.Timestamps = void 0;
3
+ exports.BaseEntSchemaWithTZ = exports.BaseEntSchema = exports.EntSchemaWithTZ = exports.EntSchema = exports.Node = exports.Timestamps = void 0;
4
4
  const uuid_1 = require("uuid");
5
5
  const field_1 = require("./field");
6
6
  let tsFields = {
@@ -67,8 +67,53 @@ exports.Node = {
67
67
  name: "node",
68
68
  fields: nodeFields,
69
69
  };
70
- // Base ent schema. has Node Pattern by default.
70
+ // Ent schema. has Node Pattern by default.
71
71
  // exists just to have less typing and easier for clients to implement
72
+ class EntSchema {
73
+ constructor(cfg) {
74
+ this.patterns = [exports.Node];
75
+ this.fields = cfg.fields;
76
+ this.tableName = cfg.tableName;
77
+ if (cfg.patterns) {
78
+ this.patterns.push(...cfg.patterns);
79
+ }
80
+ this.edges = cfg.edges;
81
+ this.edgeGroups = cfg.edgeGroups;
82
+ this.actions = cfg.actions;
83
+ this.enumTable = cfg.enumTable;
84
+ this.dbRows = cfg.dbRows;
85
+ this.constraints = cfg.constraints;
86
+ this.indices = cfg.indices;
87
+ this.hideFromGraphQL = cfg.hideFromGraphQL;
88
+ }
89
+ }
90
+ exports.EntSchema = EntSchema;
91
+ class EntSchemaWithTZ {
92
+ constructor(cfg) {
93
+ this.patterns = [
94
+ {
95
+ // default schema added
96
+ name: "nodeWithTZ",
97
+ fields: nodeFieldsWithTZ,
98
+ },
99
+ ];
100
+ this.fields = cfg.fields;
101
+ this.tableName = cfg.tableName;
102
+ if (cfg.patterns) {
103
+ this.patterns.push(...cfg.patterns);
104
+ }
105
+ this.edges = cfg.edges;
106
+ this.edgeGroups = cfg.edgeGroups;
107
+ this.actions = cfg.actions;
108
+ this.enumTable = cfg.enumTable;
109
+ this.dbRows = cfg.dbRows;
110
+ this.constraints = cfg.constraints;
111
+ this.indices = cfg.indices;
112
+ this.hideFromGraphQL = cfg.hideFromGraphQL;
113
+ }
114
+ }
115
+ exports.EntSchemaWithTZ = EntSchemaWithTZ;
116
+ // @deprecated use EntSchema
72
117
  class BaseEntSchema {
73
118
  constructor() {
74
119
  this.patterns = [exports.Node];
@@ -78,6 +123,7 @@ class BaseEntSchema {
78
123
  }
79
124
  }
80
125
  exports.BaseEntSchema = BaseEntSchema;
126
+ // @deprecated use EntSchemaWithTZ
81
127
  class BaseEntSchemaWithTZ {
82
128
  constructor() {
83
129
  this.patterns = [
package/schema/field.d.ts CHANGED
@@ -146,7 +146,7 @@ export declare class ListField extends BaseField {
146
146
  validate(validator: (val: any[]) => boolean): this;
147
147
  valid(val: any): Promise<boolean>;
148
148
  private postgresVal;
149
- format(val: any): any;
149
+ format(val: any, nested?: boolean): any;
150
150
  minLen(l: number): this;
151
151
  maxLen(l: number): this;
152
152
  length(l: number): this;
package/schema/field.js CHANGED
@@ -597,13 +597,17 @@ class ListField extends BaseField {
597
597
  }
598
598
  return JSON.stringify(val);
599
599
  }
600
- format(val) {
600
+ format(val, nested) {
601
601
  if (!Array.isArray(val)) {
602
602
  throw new Error(`need an array to format`);
603
603
  }
604
604
  const elemDBType = this.type.listElemType.dbType;
605
605
  const jsonType = elemDBType === "JSON" || elemDBType === "JSONB";
606
- const postgres = db_1.default.getDialect() === db_1.Dialect.Postgres;
606
+ // postgres ish doesn't apply when nested
607
+ const postgres = !nested && db_1.default.getDialect() === db_1.Dialect.Postgres;
608
+ if (nested && !this.field.format) {
609
+ return val;
610
+ }
607
611
  if (!postgres && !this.field.format) {
608
612
  return JSON.stringify(val);
609
613
  }
@@ -612,7 +616,7 @@ class ListField extends BaseField {
612
616
  for (let i = 0; i < val.length; i++) {
613
617
  let formatted = val[i];
614
618
  if (this.field.format) {
615
- formatted = this.field.format(val[i]);
619
+ formatted = this.field.format(val[i], nested);
616
620
  }
617
621
  // postgres supports arrays natively so we
618
622
  // structure it in the expected format
@@ -629,6 +633,10 @@ class ListField extends BaseField {
629
633
  if (postgres) {
630
634
  return postgresRet + "}";
631
635
  }
636
+ // don't JSON.stringify if nested
637
+ if (nested) {
638
+ return ret;
639
+ }
632
640
  return JSON.stringify(ret);
633
641
  }
634
642
  minLen(l) {
package/schema/index.d.ts CHANGED
@@ -1,6 +1,8 @@
1
1
  import Schema from "./schema";
2
2
  export { Schema };
3
- export { Field, AssocEdge, AssocEdgeGroup, InverseAssocEdge, Edge, Pattern, DBType, Type, FieldOptions, SchemaConstructor, SchemaInputType, getFields, ActionOperation, Action, EdgeAction, NoFields, FieldMap, Constraint, Index, ConstraintType, ForeignKeyInfo, requiredField, optionalField, } from "./schema";
4
- export { Timestamps, Node, BaseEntSchema, BaseEntSchemaWithTZ, } from "./base_schema";
3
+ export { Field, AssocEdge, AssocEdgeGroup, InverseAssocEdge, Edge, Pattern, DBType, Type, FieldOptions, SchemaConstructor, SchemaInputType, getFields, getFieldsWithPrivacy, getStorageKey, ActionOperation, Action, EdgeAction, NoFields, FieldMap, Constraint, Index, ConstraintType, ForeignKeyInfo, requiredField, optionalField, UpdateOperation, TransformedUpdateOperation, SQLStatementOperation, getTransformedReadClause, getObjectLoaderProperties, } from "./schema";
4
+ export { Timestamps, Node, BaseEntSchema, BaseEntSchemaWithTZ, EntSchema, EntSchemaWithTZ, } from "./base_schema";
5
5
  export * from "./field";
6
6
  export * from "./json_field";
7
+ export * from "./struct_field";
8
+ export * from "./union_field";
package/schema/index.js CHANGED
@@ -10,19 +10,28 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
10
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
11
  };
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
- exports.BaseEntSchemaWithTZ = exports.BaseEntSchema = exports.Node = exports.Timestamps = exports.optionalField = exports.requiredField = exports.ConstraintType = exports.NoFields = exports.ActionOperation = exports.getFields = exports.DBType = void 0;
13
+ exports.EntSchemaWithTZ = exports.EntSchema = exports.BaseEntSchemaWithTZ = exports.BaseEntSchema = exports.Node = exports.Timestamps = exports.getObjectLoaderProperties = exports.getTransformedReadClause = exports.SQLStatementOperation = exports.optionalField = exports.requiredField = exports.ConstraintType = exports.NoFields = exports.ActionOperation = exports.getStorageKey = exports.getFieldsWithPrivacy = exports.getFields = exports.DBType = void 0;
14
14
  var schema_1 = require("./schema");
15
15
  Object.defineProperty(exports, "DBType", { enumerable: true, get: function () { return schema_1.DBType; } });
16
16
  Object.defineProperty(exports, "getFields", { enumerable: true, get: function () { return schema_1.getFields; } });
17
+ Object.defineProperty(exports, "getFieldsWithPrivacy", { enumerable: true, get: function () { return schema_1.getFieldsWithPrivacy; } });
18
+ Object.defineProperty(exports, "getStorageKey", { enumerable: true, get: function () { return schema_1.getStorageKey; } });
17
19
  Object.defineProperty(exports, "ActionOperation", { enumerable: true, get: function () { return schema_1.ActionOperation; } });
18
20
  Object.defineProperty(exports, "NoFields", { enumerable: true, get: function () { return schema_1.NoFields; } });
19
21
  Object.defineProperty(exports, "ConstraintType", { enumerable: true, get: function () { return schema_1.ConstraintType; } });
20
22
  Object.defineProperty(exports, "requiredField", { enumerable: true, get: function () { return schema_1.requiredField; } });
21
23
  Object.defineProperty(exports, "optionalField", { enumerable: true, get: function () { return schema_1.optionalField; } });
24
+ Object.defineProperty(exports, "SQLStatementOperation", { enumerable: true, get: function () { return schema_1.SQLStatementOperation; } });
25
+ Object.defineProperty(exports, "getTransformedReadClause", { enumerable: true, get: function () { return schema_1.getTransformedReadClause; } });
26
+ Object.defineProperty(exports, "getObjectLoaderProperties", { enumerable: true, get: function () { return schema_1.getObjectLoaderProperties; } });
22
27
  var base_schema_1 = require("./base_schema");
23
28
  Object.defineProperty(exports, "Timestamps", { enumerable: true, get: function () { return base_schema_1.Timestamps; } });
24
29
  Object.defineProperty(exports, "Node", { enumerable: true, get: function () { return base_schema_1.Node; } });
25
30
  Object.defineProperty(exports, "BaseEntSchema", { enumerable: true, get: function () { return base_schema_1.BaseEntSchema; } });
26
31
  Object.defineProperty(exports, "BaseEntSchemaWithTZ", { enumerable: true, get: function () { return base_schema_1.BaseEntSchemaWithTZ; } });
32
+ Object.defineProperty(exports, "EntSchema", { enumerable: true, get: function () { return base_schema_1.EntSchema; } });
33
+ Object.defineProperty(exports, "EntSchemaWithTZ", { enumerable: true, get: function () { return base_schema_1.EntSchemaWithTZ; } });
27
34
  __exportStar(require("./field"), exports);
28
35
  __exportStar(require("./json_field"), exports);
36
+ __exportStar(require("./struct_field"), exports);
37
+ __exportStar(require("./union_field"), exports);
@@ -1,10 +1,18 @@
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";
3
4
  export declare type FieldMap = {
4
5
  [key: string]: Field;
5
6
  };
7
+ interface FieldInfo {
8
+ dbCol: string;
9
+ inputKey: string;
10
+ }
11
+ export declare type FieldInfoMap = {
12
+ [key: string]: FieldInfo;
13
+ };
6
14
  export default interface Schema {
7
- fields: FieldMap;
15
+ fields: FieldMap | Field[];
8
16
  tableName?: string;
9
17
  patterns?: Pattern[];
10
18
  edges?: Edge[];
@@ -60,8 +68,29 @@ export interface AssocEdgeGroup {
60
68
  export declare type Edge = AssocEdge;
61
69
  export interface Pattern {
62
70
  name: string;
63
- fields: FieldMap;
71
+ fields: FieldMap | Field[];
64
72
  edges?: Edge[];
73
+ transformRead?: () => Clause;
74
+ transformWrite?: <T extends Ent>(stmt: UpdateOperation<T>) => TransformedUpdateOperation<T> | null;
75
+ transformsDelete?: boolean;
76
+ transformsInsert?: boolean;
77
+ transformsUpdate?: boolean;
78
+ }
79
+ export declare enum SQLStatementOperation {
80
+ Insert = "insert",
81
+ Update = "update",
82
+ Delete = "delete"
83
+ }
84
+ export interface UpdateOperation<T extends Ent> {
85
+ op: SQLStatementOperation;
86
+ existingEnt: T | null;
87
+ viewer: Viewer;
88
+ data?: Map<string, any>;
89
+ }
90
+ export interface TransformedUpdateOperation<T extends Ent> {
91
+ op: SQLStatementOperation;
92
+ data?: Data;
93
+ existingEnt?: T | null;
65
94
  }
66
95
  export declare enum DBType {
67
96
  UUID = "UUID",
@@ -85,6 +114,7 @@ export declare enum DBType {
85
114
  export interface ImportType {
86
115
  path: string;
87
116
  type: string;
117
+ [x: string]: any;
88
118
  }
89
119
  declare type EnumMap = {
90
120
  [key: string]: string;
@@ -97,6 +127,8 @@ export interface Type {
97
127
  values?: string[];
98
128
  enumMap?: EnumMap;
99
129
  importType?: ImportType;
130
+ subFields?: FieldMap;
131
+ unionFields?: FieldMap;
100
132
  }
101
133
  export interface ForeignKey {
102
134
  schema: string;
@@ -133,12 +165,15 @@ export interface FieldOptions {
133
165
  fieldEdge?: FieldEdge;
134
166
  primaryKey?: boolean;
135
167
  disableUserEditable?: boolean;
168
+ disableUserGraphQLEditable?: boolean;
136
169
  defaultValueOnCreate?(builder: Builder<Ent>, input: Data): any;
137
170
  defaultToViewerOnCreate?: boolean;
138
171
  defaultValueOnEdit?(builder: Builder<Ent>, input: Data): any;
139
172
  derivedWhenEmbedded?: boolean;
140
173
  polymorphic?: boolean | PolymorphicOptions;
174
+ privacyPolicy?: PrivacyPolicy | (() => PrivacyPolicy);
141
175
  getDerivedFields?(name: string): FieldMap;
176
+ [x: string]: any;
142
177
  }
143
178
  export interface PolymorphicOptions {
144
179
  types?: string[];
@@ -148,14 +183,27 @@ export interface PolymorphicOptions {
148
183
  export interface Field extends FieldOptions {
149
184
  type: Type;
150
185
  valid?(val: any): Promise<boolean> | boolean;
151
- format?(val: any): any;
186
+ format?(val: any, nested?: boolean): any;
152
187
  logValue(val: any): any;
153
188
  }
154
189
  export interface SchemaConstructor {
155
190
  new (): Schema;
156
191
  }
157
192
  export declare type SchemaInputType = Schema | SchemaConstructor;
193
+ export declare function getSchema(value: SchemaInputType): Schema;
158
194
  export declare function getFields(value: SchemaInputType): Map<string, Field>;
195
+ /**
196
+ * @deprecated should only be used by tests
197
+ */
198
+ export declare function getStorageKey(field: Field, fieldName: string): string;
199
+ export declare function getFieldsWithPrivacy(value: SchemaInputType, fieldMap: FieldInfoMap): Map<string, PrivacyPolicy>;
200
+ export declare function getTransformedReadClause(value: SchemaInputType): Clause | undefined;
201
+ interface objectLoaderOptions {
202
+ clause?: () => Clause | undefined;
203
+ instanceKey?: string;
204
+ }
205
+ export declare function getObjectLoaderProperties(value: SchemaInputType, tableName: string): objectLoaderOptions | undefined;
206
+ export declare function getTransformedUpdateOp<T extends Ent>(value: SchemaInputType, stmt: UpdateOperation<T>): TransformedUpdateOperation<T> | null;
159
207
  export declare enum ActionOperation {
160
208
  Create = 1,
161
209
  Edit = 2,
@@ -198,10 +246,24 @@ export interface Constraint {
198
246
  fkey?: ForeignKeyInfo;
199
247
  condition?: string;
200
248
  }
249
+ export interface FullTextWeight {
250
+ A?: string[];
251
+ B?: string[];
252
+ C?: string[];
253
+ D?: string[];
254
+ }
255
+ export interface FullText {
256
+ generatedColumnName?: string;
257
+ language?: "english" | "french" | "german" | "simple";
258
+ languageColumn?: string;
259
+ indexType?: "gin" | "gist";
260
+ weights?: FullTextWeight;
261
+ }
201
262
  export interface Index {
202
263
  name: string;
203
264
  columns: string[];
204
265
  unique?: boolean;
266
+ fulltext?: FullText;
205
267
  }
206
268
  export interface ForeignKeyInfo {
207
269
  tableName: string;