@snowtop/ent 0.1.0-alpha1 → 0.1.0-alpha10

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 (78) hide show
  1. package/action/action.d.ts +2 -0
  2. package/action/executor.d.ts +1 -1
  3. package/action/orchestrator.d.ts +10 -2
  4. package/action/orchestrator.js +128 -34
  5. package/core/base.d.ts +6 -2
  6. package/core/base.js +16 -0
  7. package/core/clause.d.ts +24 -3
  8. package/core/clause.js +246 -5
  9. package/core/config.d.ts +18 -0
  10. package/core/config.js +17 -0
  11. package/core/db.d.ts +3 -3
  12. package/core/db.js +2 -0
  13. package/core/ent.d.ts +2 -4
  14. package/core/ent.js +72 -25
  15. package/core/loaders/assoc_edge_loader.d.ts +1 -1
  16. package/core/loaders/assoc_edge_loader.js +5 -4
  17. package/core/loaders/index_loader.js +1 -0
  18. package/core/loaders/object_loader.d.ts +7 -2
  19. package/core/loaders/object_loader.js +59 -4
  20. package/core/privacy.d.ts +1 -1
  21. package/core/privacy.js +3 -0
  22. package/core/viewer.d.ts +1 -0
  23. package/core/viewer.js +4 -0
  24. package/graphql/builtins/connection.js +3 -3
  25. package/graphql/builtins/edge.js +2 -2
  26. package/graphql/builtins/node.js +1 -1
  27. package/graphql/graphql.d.ts +3 -2
  28. package/graphql/graphql.js +24 -23
  29. package/graphql/index.d.ts +1 -0
  30. package/graphql/index.js +3 -1
  31. package/graphql/mutations/union.d.ts +2 -0
  32. package/graphql/mutations/union.js +35 -0
  33. package/graphql/node_resolver.d.ts +0 -1
  34. package/graphql/query/connection_type.js +6 -6
  35. package/graphql/query/page_info.js +4 -4
  36. package/graphql/query/shared_assoc_test.js +2 -2
  37. package/graphql/scalars/time.d.ts +1 -1
  38. package/index.d.ts +16 -1
  39. package/index.js +18 -5
  40. package/package.json +3 -3
  41. package/parse_schema/parse.d.ts +21 -4
  42. package/parse_schema/parse.js +79 -8
  43. package/schema/base_schema.d.ts +36 -1
  44. package/schema/base_schema.js +48 -2
  45. package/schema/field.d.ts +1 -1
  46. package/schema/field.js +11 -3
  47. package/schema/index.d.ts +4 -2
  48. package/schema/index.js +10 -1
  49. package/schema/schema.d.ts +56 -4
  50. package/schema/schema.js +126 -5
  51. package/schema/struct_field.d.ts +17 -0
  52. package/schema/struct_field.js +102 -0
  53. package/schema/union_field.d.ts +23 -0
  54. package/schema/union_field.js +79 -0
  55. package/scripts/custom_graphql.js +122 -15
  56. package/scripts/read_schema.js +15 -1
  57. package/scripts/transform_code.d.ts +1 -0
  58. package/scripts/transform_code.js +114 -0
  59. package/scripts/transform_schema.js +190 -121
  60. package/testutils/builder.d.ts +13 -9
  61. package/testutils/builder.js +64 -8
  62. package/testutils/context/test_context.d.ts +2 -2
  63. package/testutils/context/test_context.js +7 -1
  64. package/testutils/db/test_db.d.ts +2 -1
  65. package/testutils/db/test_db.js +13 -4
  66. package/testutils/ent-graphql-tests/index.d.ts +2 -0
  67. package/testutils/ent-graphql-tests/index.js +26 -17
  68. package/testutils/fake_data/fake_contact.d.ts +3 -7
  69. package/testutils/fake_data/fake_contact.js +14 -19
  70. package/testutils/fake_data/fake_event.d.ts +3 -7
  71. package/testutils/fake_data/fake_event.js +20 -25
  72. package/testutils/fake_data/fake_user.d.ts +3 -7
  73. package/testutils/fake_data/fake_user.js +22 -27
  74. package/testutils/fake_data/test_helpers.js +1 -1
  75. package/tsc/ast.d.ts +20 -0
  76. package/tsc/ast.js +131 -0
  77. package/tsc/compilerOptions.d.ts +5 -0
  78. package/tsc/compilerOptions.js +35 -1
@@ -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,11 @@
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
  };
6
7
  export default interface Schema {
7
- fields: FieldMap;
8
+ fields: FieldMap | Field[];
8
9
  tableName?: string;
9
10
  patterns?: Pattern[];
10
11
  edges?: Edge[];
@@ -60,8 +61,29 @@ export interface AssocEdgeGroup {
60
61
  export declare type Edge = AssocEdge;
61
62
  export interface Pattern {
62
63
  name: string;
63
- fields: FieldMap;
64
+ fields: FieldMap | Field[];
64
65
  edges?: Edge[];
66
+ transformRead?: () => Clause;
67
+ transformWrite?: <T extends Ent>(stmt: UpdateOperation<T>) => TransformedUpdateOperation<T> | undefined;
68
+ transformsDelete?: boolean;
69
+ transformsInsert?: boolean;
70
+ transformsUpdate?: boolean;
71
+ }
72
+ export declare enum SQLStatementOperation {
73
+ Insert = "insert",
74
+ Update = "update",
75
+ Delete = "delete"
76
+ }
77
+ export interface UpdateOperation<T extends Ent> {
78
+ op: SQLStatementOperation;
79
+ existingEnt?: T;
80
+ viewer: Viewer;
81
+ data?: Map<string, any>;
82
+ }
83
+ export interface TransformedUpdateOperation<T extends Ent> {
84
+ op: SQLStatementOperation;
85
+ data?: Data;
86
+ existingEnt?: T;
65
87
  }
66
88
  export declare enum DBType {
67
89
  UUID = "UUID",
@@ -85,6 +107,7 @@ export declare enum DBType {
85
107
  export interface ImportType {
86
108
  path: string;
87
109
  type: string;
110
+ [x: string]: any;
88
111
  }
89
112
  declare type EnumMap = {
90
113
  [key: string]: string;
@@ -97,6 +120,8 @@ export interface Type {
97
120
  values?: string[];
98
121
  enumMap?: EnumMap;
99
122
  importType?: ImportType;
123
+ subFields?: FieldMap;
124
+ unionFields?: FieldMap;
100
125
  }
101
126
  export interface ForeignKey {
102
127
  schema: string;
@@ -133,12 +158,15 @@ export interface FieldOptions {
133
158
  fieldEdge?: FieldEdge;
134
159
  primaryKey?: boolean;
135
160
  disableUserEditable?: boolean;
161
+ disableUserGraphQLEditable?: boolean;
136
162
  defaultValueOnCreate?(builder: Builder<Ent>, input: Data): any;
137
163
  defaultToViewerOnCreate?: boolean;
138
164
  defaultValueOnEdit?(builder: Builder<Ent>, input: Data): any;
139
165
  derivedWhenEmbedded?: boolean;
140
166
  polymorphic?: boolean | PolymorphicOptions;
167
+ privacyPolicy?: PrivacyPolicy | (() => PrivacyPolicy);
141
168
  getDerivedFields?(name: string): FieldMap;
169
+ [x: string]: any;
142
170
  }
143
171
  export interface PolymorphicOptions {
144
172
  types?: string[];
@@ -148,14 +176,24 @@ export interface PolymorphicOptions {
148
176
  export interface Field extends FieldOptions {
149
177
  type: Type;
150
178
  valid?(val: any): Promise<boolean> | boolean;
151
- format?(val: any): any;
179
+ format?(val: any, nested?: boolean): any;
152
180
  logValue(val: any): any;
153
181
  }
154
182
  export interface SchemaConstructor {
155
183
  new (): Schema;
156
184
  }
157
185
  export declare type SchemaInputType = Schema | SchemaConstructor;
186
+ export declare function getSchema(value: SchemaInputType): Schema;
158
187
  export declare function getFields(value: SchemaInputType): Map<string, Field>;
188
+ export declare function getStorageKey(field: Field, fieldName: string): string;
189
+ export declare function getFieldsWithPrivacy(value: SchemaInputType): Map<string, PrivacyPolicy>;
190
+ export declare function getTransformedReadClause(value: SchemaInputType): Clause | undefined;
191
+ interface objectLoaderOptions {
192
+ clause?: () => Clause | undefined;
193
+ instanceKey?: string;
194
+ }
195
+ export declare function getObjectLoaderProperties(value: SchemaInputType, tableName: string): objectLoaderOptions | undefined;
196
+ export declare function getTransformedUpdateOp<T extends Ent>(value: SchemaInputType, stmt: UpdateOperation<T>): TransformedUpdateOperation<T> | undefined;
159
197
  export declare enum ActionOperation {
160
198
  Create = 1,
161
199
  Edit = 2,
@@ -198,10 +236,24 @@ export interface Constraint {
198
236
  fkey?: ForeignKeyInfo;
199
237
  condition?: string;
200
238
  }
239
+ export interface FullTextWeight {
240
+ A?: string[];
241
+ B?: string[];
242
+ C?: string[];
243
+ D?: string[];
244
+ }
245
+ export interface FullText {
246
+ generatedColumnName?: string;
247
+ language?: "english" | "french" | "german" | "simple";
248
+ languageColumn?: string;
249
+ indexType?: "gin" | "gist";
250
+ weights?: FullTextWeight;
251
+ }
201
252
  export interface Index {
202
253
  name: string;
203
254
  columns: string[];
204
255
  unique?: boolean;
256
+ fulltext?: FullText;
205
257
  }
206
258
  export interface ForeignKeyInfo {
207
259
  tableName: string;