@snowtop/ent 0.1.0-alpha92-7ebc5680-4591-11ed-b331-8b0a5597e9d8 → 0.1.0-alpha92

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.
@@ -70,3 +70,4 @@ interface Orchestrator {
70
70
  viewer: Viewer;
71
71
  }
72
72
  export declare function setEdgeTypeInGroup<T extends string>(orchestrator: Orchestrator, inputEnumValue: string, id1: ID, id2: ID, nodeType: string, m: Map<T, string>): Promise<void>;
73
+ export declare function clearEdgeTypeInGroup<T extends string>(orchestrator: Orchestrator, id1: ID, id2: ID, m: Map<T, string>): Promise<void>;
package/action/action.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.setEdgeTypeInGroup = exports.saveBuilderX = exports.saveBuilder = exports.WriteOperation = void 0;
3
+ exports.clearEdgeTypeInGroup = exports.setEdgeTypeInGroup = exports.saveBuilderX = exports.saveBuilder = exports.WriteOperation = void 0;
4
4
  const base_1 = require("../core/base");
5
5
  Object.defineProperty(exports, "WriteOperation", { enumerable: true, get: function () { return base_1.WriteOperation; } });
6
6
  const ent_1 = require("../core/ent");
@@ -84,3 +84,22 @@ async function setEdgeTypeInGroup(orchestrator, inputEnumValue, id1, id2, nodeTy
84
84
  await Promise.all(promises);
85
85
  }
86
86
  exports.setEdgeTypeInGroup = setEdgeTypeInGroup;
87
+ async function clearEdgeTypeInGroup(orchestrator, id1, id2, m) {
88
+ let promises = [];
89
+ for (const [_, edgeType] of m) {
90
+ promises.push((async () => {
91
+ let edge = await (0, ent_1.loadEdgeForID2)({
92
+ id1,
93
+ id2,
94
+ edgeType,
95
+ ctr: ent_1.AssocEdge,
96
+ context: orchestrator.viewer.context,
97
+ });
98
+ if (edge) {
99
+ orchestrator.removeOutboundEdge(id2, edgeType);
100
+ }
101
+ })());
102
+ }
103
+ await Promise.all(promises);
104
+ }
105
+ exports.clearEdgeTypeInGroup = clearEdgeTypeInGroup;
@@ -241,7 +241,7 @@ class Orchestrator {
241
241
  ops.push(edgeOp);
242
242
  const edgeData = edgeDatas.get(edgeType);
243
243
  if (!edgeData) {
244
- throw new Error(`could not load edge data for ${edgeType}`);
244
+ throw new Error(`could not load edge data for '${edgeType}'`);
245
245
  }
246
246
  if (edgeData.symmetricEdge) {
247
247
  ops.push(edgeOp.symmetricEdge());
package/core/config.d.ts CHANGED
@@ -38,6 +38,7 @@ interface CodegenConfig {
38
38
  fieldPrivacyEvaluated?: fieldPrivacyEvaluated;
39
39
  templatizedViewer?: importedObject;
40
40
  customAssocEdgePath?: importedObject;
41
+ globalImportPath?: string;
41
42
  }
42
43
  interface PrettierConfig {
43
44
  custom?: boolean;
package/core/ent.d.ts CHANGED
@@ -213,9 +213,8 @@ interface loadCustomEdgesOptions<T extends AssocEdge> extends loadEdgesOptions {
213
213
  ctr: AssocEdgeConstructor<T>;
214
214
  }
215
215
  export declare const DefaultLimit = 1000;
216
- export declare function defaultEdgeQueryOptions(id1: ID, edgeType: string): EdgeQueryableDataOptions;
217
216
  export declare function loadEdges(options: loadEdgesOptions): Promise<AssocEdge[]>;
218
- export declare function getEdgeClauseAndFields(cls: clause.Clause, options: loadEdgesOptions): {
217
+ export declare function getEdgeClauseAndFields(cls: clause.Clause, options: Pick<loadEdgesOptions, "disableTransformations">): {
219
218
  cls: clause.Clause;
220
219
  fields: string[];
221
220
  };
package/core/ent.js CHANGED
@@ -26,8 +26,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
26
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.loadRawEdgeCountX = exports.loadUniqueNode = exports.loadUniqueEdge = exports.loadCustomEdges = exports.getEdgeClauseAndFields = exports.loadEdges = exports.defaultEdgeQueryOptions = exports.DefaultLimit = exports.loadEdgeDatas = exports.loadEdgeData = exports.assocEdgeLoader = exports.AssocEdgeData = exports.getCursor = exports.AssocEdge = exports.DeleteNodeOperation = exports.deleteRowsSync = exports.deleteRows = exports.editRowSync = exports.editRow = exports.buildUpdateQuery = exports.createRowSync = exports.createRow = exports.buildInsertQuery = exports.EdgeOperation = exports.__hasGlobalSchema = exports.clearGlobalSchema = exports.setGlobalSchema = exports.EditNodeOperation = exports.RawQueryOperation = exports.buildGroupQuery = exports.buildQuery = exports.loadRows = exports.performRawQuery = exports.loadRow = exports.loadRowX = exports.loadDerivedEntX = exports.loadDerivedEnt = exports.loadCustomCount = exports.loadCustomData = exports.loadCustomEnts = exports.loadEntsFromClause = exports.loadEntsList = exports.loadEnts = exports.loadEntXFromClause = exports.loadEntFromClause = exports.loadEntXViaKey = exports.loadEntX = exports.loadEntViaKey = exports.loadEnt = exports.getEntKey = void 0;
30
- exports.getEdgeTypeInGroup = exports.applyPrivacyPolicyForRows = exports.applyPrivacyPolicyForRow = exports.loadNodesByEdge = exports.loadEdgeForID2 = void 0;
29
+ exports.loadEdgeForID2 = exports.loadRawEdgeCountX = exports.loadUniqueNode = exports.loadUniqueEdge = exports.loadCustomEdges = exports.getEdgeClauseAndFields = exports.loadEdges = exports.DefaultLimit = exports.loadEdgeDatas = exports.loadEdgeData = exports.assocEdgeLoader = exports.AssocEdgeData = exports.getCursor = exports.AssocEdge = exports.DeleteNodeOperation = exports.deleteRowsSync = exports.deleteRows = exports.editRowSync = exports.editRow = exports.buildUpdateQuery = exports.createRowSync = exports.createRow = exports.buildInsertQuery = exports.EdgeOperation = exports.__hasGlobalSchema = exports.clearGlobalSchema = exports.setGlobalSchema = exports.EditNodeOperation = exports.RawQueryOperation = exports.buildGroupQuery = exports.buildQuery = exports.loadRows = exports.performRawQuery = exports.loadRow = exports.loadRowX = exports.loadDerivedEntX = exports.loadDerivedEnt = exports.loadCustomCount = exports.loadCustomData = exports.loadCustomEnts = exports.loadEntsFromClause = exports.loadEntsList = exports.loadEnts = exports.loadEntXFromClause = exports.loadEntFromClause = exports.loadEntXViaKey = exports.loadEntX = exports.loadEntViaKey = exports.loadEnt = exports.getEntKey = void 0;
30
+ exports.getEdgeTypeInGroup = exports.applyPrivacyPolicyForRows = exports.applyPrivacyPolicyForRow = exports.loadNodesByEdge = void 0;
31
31
  const db_1 = __importStar(require("./db"));
32
32
  const privacy_1 = require("./privacy");
33
33
  const clause = __importStar(require("./clause"));
@@ -135,6 +135,7 @@ function createEntLoader(viewer, options, map) {
135
135
  return [];
136
136
  }
137
137
  let result = [];
138
+ const tableName = options.loaderFactory.options?.tableName;
138
139
  const loader = options.loaderFactory.createLoader(viewer.context);
139
140
  const rows = await loader.loadMany(ids);
140
141
  // this is a loader which should return the same order based on passed-in ids
@@ -147,7 +148,12 @@ function createEntLoader(viewer, options, map) {
147
148
  continue;
148
149
  }
149
150
  else if (!row) {
150
- result[idx] = new ErrorWrapper(new Error(`couldn't find row for value ${ids[idx]}`));
151
+ if (tableName) {
152
+ result[idx] = new ErrorWrapper(new Error(`couldn't find row for value ${ids[idx]} in table ${tableName}`));
153
+ }
154
+ else {
155
+ result[idx] = new ErrorWrapper(new Error(`couldn't find row for value ${ids[idx]}`));
156
+ }
151
157
  }
152
158
  else {
153
159
  const r = await applyPrivacyPolicyForRowImpl(viewer, options, row);
@@ -1404,14 +1410,17 @@ const edgeFields = [
1404
1410
  ];
1405
1411
  exports.DefaultLimit = 1000;
1406
1412
  // TODO default limit from somewhere
1407
- function defaultEdgeQueryOptions(id1, edgeType) {
1413
+ function defaultEdgeQueryOptions(id1, edgeType, id2) {
1414
+ let cls = clause.And(clause.Eq("id1", id1), clause.Eq("edge_type", edgeType));
1415
+ if (id2) {
1416
+ cls = clause.And(cls, clause.Eq("id2", id2));
1417
+ }
1408
1418
  return {
1409
- clause: clause.And(clause.Eq("id1", id1), clause.Eq("edge_type", edgeType)),
1419
+ clause: cls,
1410
1420
  orderby: "time DESC",
1411
1421
  limit: exports.DefaultLimit,
1412
1422
  };
1413
1423
  }
1414
- exports.defaultEdgeQueryOptions = defaultEdgeQueryOptions;
1415
1424
  async function loadEdges(options) {
1416
1425
  return loadCustomEdges({ ...options, ctr: AssocEdge });
1417
1426
  }
@@ -1432,30 +1441,37 @@ function getEdgeClauseAndFields(cls, options) {
1432
1441
  }
1433
1442
  exports.getEdgeClauseAndFields = getEdgeClauseAndFields;
1434
1443
  async function loadCustomEdges(options) {
1435
- const { id1, edgeType, context } = options;
1436
- const edgeData = await loadEdgeData(edgeType);
1437
- if (!edgeData) {
1438
- throw new Error(`error loading edge data for ${edgeType}`);
1439
- }
1440
- const defaultOptions = defaultEdgeQueryOptions(id1, edgeType);
1441
- let cls = defaultOptions.clause;
1442
- if (options.queryOptions?.clause) {
1443
- cls = clause.And(cls, options.queryOptions.clause);
1444
- }
1445
- const { cls: actualClause, fields } = getEdgeClauseAndFields(cls, options);
1444
+ const { cls: actualClause, fields, defaultOptions, tableName, } = await loadEgesInfo(options);
1446
1445
  const rows = await loadRows({
1447
- tableName: edgeData.edgeTable,
1446
+ tableName,
1448
1447
  fields: fields,
1449
1448
  clause: actualClause,
1450
1449
  orderby: options.queryOptions?.orderby || defaultOptions.orderby,
1451
1450
  limit: options.queryOptions?.limit || defaultOptions.limit,
1452
- context,
1451
+ context: options.context,
1453
1452
  });
1454
1453
  return rows.map((row) => {
1455
1454
  return new options.ctr(row);
1456
1455
  });
1457
1456
  }
1458
1457
  exports.loadCustomEdges = loadCustomEdges;
1458
+ async function loadEgesInfo(options, id2) {
1459
+ const { id1, edgeType } = options;
1460
+ const edgeData = await loadEdgeData(edgeType);
1461
+ if (!edgeData) {
1462
+ throw new Error(`error loading edge data for ${edgeType}`);
1463
+ }
1464
+ const defaultOptions = defaultEdgeQueryOptions(id1, edgeType, id2);
1465
+ let cls = defaultOptions.clause;
1466
+ if (options.queryOptions?.clause) {
1467
+ cls = clause.And(cls, options.queryOptions.clause);
1468
+ }
1469
+ return {
1470
+ ...getEdgeClauseAndFields(cls, options),
1471
+ defaultOptions,
1472
+ tableName: edgeData.edgeTable,
1473
+ };
1474
+ }
1459
1475
  async function loadUniqueEdge(options) {
1460
1476
  const { id1, edgeType, context } = options;
1461
1477
  const edgeData = await loadEdgeData(edgeType);
@@ -1505,10 +1521,16 @@ async function loadRawEdgeCountX(options) {
1505
1521
  }
1506
1522
  exports.loadRawEdgeCountX = loadRawEdgeCountX;
1507
1523
  async function loadEdgeForID2(options) {
1508
- // TODO at some point, same as in go, we can be smart about this and have heuristics to determine if we fetch everything here or not
1509
- // we're assuming a cache here but not always true and this can be expensive if not...
1510
- const edges = await loadCustomEdges(options);
1511
- return edges.find((edge) => edge.id2 == options.id2);
1524
+ const { cls: actualClause, fields, tableName, } = await loadEgesInfo(options, options.id2);
1525
+ const row = await loadRow({
1526
+ tableName,
1527
+ fields: fields,
1528
+ clause: actualClause,
1529
+ context: options.context,
1530
+ });
1531
+ if (row) {
1532
+ return new options.ctr(row);
1533
+ }
1512
1534
  }
1513
1535
  exports.loadEdgeForID2 = loadEdgeForID2;
1514
1536
  async function loadNodesByEdge(viewer, id1, edgeType, options) {
@@ -1565,26 +1587,45 @@ async function applyPrivacyPolicyForRows(viewer, rows, options) {
1565
1587
  return result.filter((r) => r !== undefined);
1566
1588
  }
1567
1589
  exports.applyPrivacyPolicyForRows = applyPrivacyPolicyForRows;
1568
- async function loadEdgeWithConst(viewer, id1, id2, edgeEnum, edgeType) {
1569
- const edge = await loadEdgeForID2({
1570
- id1: id1,
1571
- id2: id2,
1572
- edgeType: edgeType,
1573
- context: viewer.context,
1574
- ctr: AssocEdge,
1575
- });
1576
- return [edgeEnum, edge];
1577
- }
1578
1590
  // given a viewer, an id pair, and a map of edgeEnum to EdgeType
1579
1591
  // return the edgeEnum that's set in the group
1580
1592
  async function getEdgeTypeInGroup(viewer, id1, id2, m) {
1581
1593
  let promises = [];
1582
- for (const [k, v] of m) {
1583
- promises.push(loadEdgeWithConst(viewer, id1, id2, k, v));
1594
+ const edgeDatas = await loadEdgeDatas(...Array.from(m.values()));
1595
+ let tableToEdgeEnumMap = new Map();
1596
+ for (const [edgeEnum, edgeType] of m) {
1597
+ const edgeData = edgeDatas.get(edgeType);
1598
+ if (!edgeData) {
1599
+ throw new Error(`could not load edge data for '${edgeType}'`);
1600
+ }
1601
+ const l = tableToEdgeEnumMap.get(edgeData.edgeTable) ?? [];
1602
+ l.push(edgeEnum);
1603
+ tableToEdgeEnumMap.set(edgeData.edgeTable, l);
1584
1604
  }
1605
+ tableToEdgeEnumMap.forEach((edgeEnums, tableName) => {
1606
+ promises.push((async () => {
1607
+ const edgeTypes = edgeEnums.map((edgeEnum) => m.get(edgeEnum));
1608
+ const { cls, fields } = getEdgeClauseAndFields(clause.And(clause.Eq("id1", id1), clause.In("edge_type", edgeTypes), clause.Eq("id2", id2)), {});
1609
+ const rows = await loadRows({
1610
+ tableName,
1611
+ fields,
1612
+ clause: cls,
1613
+ context: viewer.context,
1614
+ });
1615
+ const row = rows[0];
1616
+ if (row) {
1617
+ const edgeType = row.edge_type;
1618
+ for (const [k, v] of m) {
1619
+ if (v === edgeType) {
1620
+ return [k, new AssocEdge(row)];
1621
+ }
1622
+ }
1623
+ }
1624
+ })());
1625
+ });
1585
1626
  const results = await Promise.all(promises);
1586
1627
  for (const res of results) {
1587
- if (res[1]) {
1628
+ if (res && res[1]) {
1588
1629
  return [res[0], res[1]];
1589
1630
  }
1590
1631
  }
@@ -45,11 +45,7 @@ class AssocEdgeCountLoader {
45
45
  if (!edgeData) {
46
46
  throw new Error(`error loading edge data for ${this.edgeType}`);
47
47
  }
48
- const { cls } = (0, ent_1.getEdgeClauseAndFields)(clause.Eq("edge_type", this.edgeType), {
49
- // don't need this..
50
- id1: "1",
51
- edgeType: this.edgeType,
52
- });
48
+ const { cls } = (0, ent_1.getEdgeClauseAndFields)(clause.Eq("edge_type", this.edgeType), {});
53
49
  this.loader = (0, raw_count_loader_1.createCountDataLoader)({
54
50
  tableName: edgeData.edgeTable,
55
51
  groupCol: "id1",
@@ -7,5 +7,4 @@ export { GraphQLNodeInterface } from "./builtins/node";
7
7
  export { GraphQLConnectionInterface } from "./builtins/connection";
8
8
  export { GraphQLEdgeInterface } from "./builtins/edge";
9
9
  export { NodeResolver, EntNodeResolver, registerResolver, clearResolvers, resolveID, nodeIDEncoder, mustDecodeIDFromGQLID, mustDecodeNullableIDFromGQLID, encodeGQLID, } from "./node_resolver";
10
- export { convertFromGQLEnum, convertToGQLEnum } from "./enums";
11
10
  export { transformUnionTypes } from "./mutations/union";
package/graphql/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.transformUnionTypes = exports.convertToGQLEnum = exports.convertFromGQLEnum = exports.encodeGQLID = exports.mustDecodeNullableIDFromGQLID = exports.mustDecodeIDFromGQLID = exports.nodeIDEncoder = exports.resolveID = exports.clearResolvers = exports.registerResolver = exports.EntNodeResolver = exports.GraphQLEdgeInterface = exports.GraphQLConnectionInterface = exports.GraphQLNodeInterface = exports.GraphQLConnectionType = exports.GraphQLEdgeType = exports.GraphQLEdgeConnection = exports.GraphQLPageInfo = exports.GraphQLTime = exports.gqlFileUpload = exports.GQLCapture = exports.gqlConnection = exports.gqlContextType = exports.gqlMutation = exports.gqlQuery = exports.gqlObjectType = exports.gqlInputObjectType = exports.gqlArgType = exports.gqlArg = exports.gqlField = void 0;
3
+ exports.transformUnionTypes = exports.encodeGQLID = exports.mustDecodeNullableIDFromGQLID = exports.mustDecodeIDFromGQLID = exports.nodeIDEncoder = exports.resolveID = exports.clearResolvers = exports.registerResolver = exports.EntNodeResolver = exports.GraphQLEdgeInterface = exports.GraphQLConnectionInterface = exports.GraphQLNodeInterface = exports.GraphQLConnectionType = exports.GraphQLEdgeType = exports.GraphQLEdgeConnection = exports.GraphQLPageInfo = exports.GraphQLTime = exports.gqlFileUpload = exports.GQLCapture = exports.gqlConnection = exports.gqlContextType = exports.gqlMutation = exports.gqlQuery = exports.gqlObjectType = exports.gqlInputObjectType = exports.gqlArgType = exports.gqlArg = exports.gqlField = void 0;
4
4
  var graphql_1 = require("./graphql");
5
5
  Object.defineProperty(exports, "gqlField", { enumerable: true, get: function () { return graphql_1.gqlField; } });
6
6
  Object.defineProperty(exports, "gqlArg", { enumerable: true, get: function () { return graphql_1.gqlArg; } });
@@ -37,8 +37,5 @@ Object.defineProperty(exports, "nodeIDEncoder", { enumerable: true, get: functio
37
37
  Object.defineProperty(exports, "mustDecodeIDFromGQLID", { enumerable: true, get: function () { return node_resolver_1.mustDecodeIDFromGQLID; } });
38
38
  Object.defineProperty(exports, "mustDecodeNullableIDFromGQLID", { enumerable: true, get: function () { return node_resolver_1.mustDecodeNullableIDFromGQLID; } });
39
39
  Object.defineProperty(exports, "encodeGQLID", { enumerable: true, get: function () { return node_resolver_1.encodeGQLID; } });
40
- var enums_1 = require("./enums");
41
- Object.defineProperty(exports, "convertFromGQLEnum", { enumerable: true, get: function () { return enums_1.convertFromGQLEnum; } });
42
- Object.defineProperty(exports, "convertToGQLEnum", { enumerable: true, get: function () { return enums_1.convertToGQLEnum; } });
43
40
  var union_1 = require("./mutations/union");
44
41
  Object.defineProperty(exports, "transformUnionTypes", { enumerable: true, get: function () { return union_1.transformUnionTypes; } });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@snowtop/ent",
3
- "version": "0.1.0-alpha92-7ebc5680-4591-11ed-b331-8b0a5597e9d8",
3
+ "version": "0.1.0-alpha92",
4
4
  "description": "snowtop ent framework",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -229,6 +229,7 @@ async function parseSchema(potentialSchemas, globalSchema) {
229
229
  }
230
230
  let processedSchema = {
231
231
  fields: [],
232
+ fieldOverrides: schema.fieldOverrides,
232
233
  schemaPath: schema.schemaPath,
233
234
  tableName: schema.tableName,
234
235
  enumTable: schema.enumTable,
@@ -1,4 +1,4 @@
1
- import { Field, FieldMap, Pattern } from "./schema";
1
+ import { Field, FieldMap, Pattern, FieldOverrideMap } from "./schema";
2
2
  import { Action, AssocEdgeGroup, Constraint, Edge, Index, Schema } from ".";
3
3
  export declare const Timestamps: Pattern;
4
4
  export declare const Node: Pattern;
@@ -6,6 +6,7 @@ export interface SchemaConfig extends Schema {
6
6
  }
7
7
  export declare class EntSchema implements Schema {
8
8
  fields: FieldMap | Field[];
9
+ fieldOverrides: FieldOverrideMap | undefined;
9
10
  tableName: string | undefined;
10
11
  patterns: Pattern[];
11
12
  edges: Edge[] | undefined;
@@ -22,6 +23,7 @@ export declare class EntSchema implements Schema {
22
23
  }
23
24
  export declare class EntSchemaWithTZ implements Schema {
24
25
  fields: FieldMap | Field[];
26
+ fieldOverrides: FieldOverrideMap | undefined;
25
27
  tableName: string | undefined;
26
28
  patterns: Pattern[];
27
29
  edges: Edge[] | undefined;
@@ -74,6 +74,7 @@ class EntSchema {
74
74
  constructor(cfg) {
75
75
  this.patterns = [exports.Node];
76
76
  this.fields = cfg.fields;
77
+ this.fieldOverrides = cfg.fieldOverrides;
77
78
  this.tableName = cfg.tableName;
78
79
  if (cfg.patterns) {
79
80
  this.patterns.push(...cfg.patterns);
@@ -100,6 +101,7 @@ class EntSchemaWithTZ {
100
101
  },
101
102
  ];
102
103
  this.fields = cfg.fields;
104
+ this.fieldOverrides = cfg.fieldOverrides;
103
105
  this.tableName = cfg.tableName;
104
106
  if (cfg.patterns) {
105
107
  this.patterns.push(...cfg.patterns);
package/schema/field.d.ts CHANGED
@@ -152,7 +152,6 @@ export declare class EnumField extends BaseField implements Field {
152
152
  private values?;
153
153
  private map?;
154
154
  constructor(options: StringEnumOptions);
155
- convertForGQL(value: string): string;
156
155
  valid(val: any): boolean;
157
156
  format(val: any): any;
158
157
  }
package/schema/field.js CHANGED
@@ -25,7 +25,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.UUIDListType = exports.IntegerEnumListType = exports.EnumListType = exports.DateListType = exports.TimetzListType = exports.TimeListType = exports.TimestamptzListType = exports.TimestampListType = exports.BooleanListType = exports.BigIntegerListType = exports.FloatListType = exports.IntegerListType = exports.IntListType = exports.StringListType = exports.ListField = exports.IntegerEnumType = exports.IntegerEnumField = exports.EnumType = exports.StringEnumField = exports.EnumField = exports.DateType = exports.DateField = exports.TimetzType = exports.TimeType = exports.TimeField = exports.leftPad = exports.TimestamptzType = exports.TimestampType = exports.TimestampField = exports.StringType = exports.PolymorphicStringField = exports.StringField = exports.BooleanType = exports.BooleanField = exports.FloatType = exports.FloatField = exports.BigIntegerType = exports.BigIntegerField = exports.IntegerType = exports.IntegerField = exports.UUIDType = exports.UUIDField = exports.BaseField = void 0;
27
27
  const luxon_1 = require("luxon");
28
- const snake_case_1 = require("snake-case");
29
28
  const camel_case_1 = require("camel-case");
30
29
  const util_1 = require("util");
31
30
  const uuid_1 = require("uuid");
@@ -553,10 +552,6 @@ class EnumField extends BaseField {
553
552
  this.values = options.values;
554
553
  this.map = options.map;
555
554
  }
556
- // TODO need to update this for map
557
- convertForGQL(value) {
558
- return (0, snake_case_1.snakeCase)(value).toUpperCase();
559
- }
560
555
  valid(val) {
561
556
  // lookup table enum and indicated via presence of foreignKey
562
557
  if (!this.values && !this.map) {
@@ -564,45 +559,17 @@ class EnumField extends BaseField {
564
559
  }
565
560
  if (this.values) {
566
561
  let str = String(val);
567
- return this.values.some((value) => value === str || this.convertForGQL(value) === str);
562
+ return this.values.some((value) => value === str);
568
563
  }
569
564
  for (const k in this.map) {
570
565
  const v = this.map[k];
571
- if (v === val || this.convertForGQL(k) === val) {
572
- // TODO decide on behavior for GQL since GQL only supports one type
566
+ if (v === val) {
573
567
  return true;
574
568
  }
575
569
  }
576
570
  return false;
577
571
  }
578
572
  format(val) {
579
- // TODO need to format correctly for graphql purposes...
580
- // how to best get the values in the db...
581
- if (!this.values && !this.map) {
582
- return val;
583
- }
584
- let str = String(val);
585
- if (this.values) {
586
- for (let i = 0; i < this.values.length; i++) {
587
- let value = this.values[i];
588
- // store the format that maps to the given value in the db instead of saving the upper case value
589
- if (str === value || str === this.convertForGQL(value)) {
590
- return value;
591
- }
592
- }
593
- }
594
- if (this.map) {
595
- for (const k in this.map) {
596
- const v = this.map[k];
597
- if (str === v) {
598
- return v;
599
- }
600
- if (str === this.convertForGQL(k)) {
601
- return v;
602
- }
603
- }
604
- }
605
- // whelp, just return what's passed
606
573
  return val;
607
574
  }
608
575
  }
@@ -18,8 +18,13 @@ export interface GlobalSchema {
18
18
  transformEdgeRead?: () => Clause;
19
19
  transformEdgeWrite?: (stmt: EdgeUpdateOperation) => TransformedEdgeUpdateOperation | null;
20
20
  }
21
+ declare type FieldOverride = Pick<FieldOptions, "nullable" | "storageKey" | "serverDefault" | "unique" | "hideFromGraphQL" | "graphqlName" | "index">;
22
+ export declare type FieldOverrideMap = {
23
+ [key: string]: FieldOverride;
24
+ };
21
25
  export default interface Schema {
22
26
  fields: FieldMap | Field[];
27
+ fieldOverrides?: FieldOverrideMap;
23
28
  tableName?: string;
24
29
  patterns?: Pattern[];
25
30
  edges?: Edge[];
@@ -260,6 +265,7 @@ export interface ActionField {
260
265
  list?: boolean;
261
266
  actionName?: string;
262
267
  excludedFields?: string[];
268
+ hideFromGraphQL?: boolean;
263
269
  [x: string]: any;
264
270
  }
265
271
  export interface Action {
package/schema/schema.js CHANGED
@@ -211,6 +211,9 @@ var ActionOperation;
211
211
  // RemoveEdge is used to provide the ability to remove an edge in an AssociationEdge.
212
212
  ActionOperation[ActionOperation["RemoveEdge"] = 32] = "RemoveEdge";
213
213
  // EdgeGroup is used to provide the ability to edit an edge group in an AssociationEdgeGroup.
214
+ // if you want to clear this edge group e.g. any set edge with id1 and id2,
215
+ // you should create a custom action that takes the id as an action only field,
216
+ // and then calls `clearEdgeTypeInGroup` in a trigger to clear
214
217
  ActionOperation[ActionOperation["EdgeGroup"] = 64] = "EdgeGroup";
215
218
  })(ActionOperation = exports.ActionOperation || (exports.ActionOperation = {}));
216
219
  // sentinel that indicates an action has no fields
@@ -31,9 +31,6 @@ class StructField extends field_1.BaseField {
31
31
  for (const k in this.options.fields) {
32
32
  const field = this.options.fields[k];
33
33
  // check two values
34
- // wait, two different things
35
- // getStoragetKey and getCamelCase()
36
- // for weird graphql case and for typescript format...
37
34
  // store in dbKey format
38
35
  // TODO more #510
39
36
  let dbKey = (0, schema_1.getStorageKey)(field, k);
@@ -2,7 +2,7 @@ import { Ent, ID, Viewer, Data, EntConstructor, PrivacyPolicy } from "../core/ba
2
2
  import { Orchestrator } from "../action/orchestrator";
3
3
  import { Action, Builder, Changeset, WriteOperation, Validator, Trigger, Observer } from "../action";
4
4
  import { FieldMap, Schema } from "../schema";
5
- import { SchemaConfig } from "../schema/base_schema";
5
+ import { SchemaConfig, EntSchema } from "../schema/base_schema";
6
6
  import { FieldInfoMap } from "../schema/schema";
7
7
  export declare class User implements Ent {
8
8
  viewer: Viewer;
@@ -62,6 +62,10 @@ export declare class Address implements Ent {
62
62
  export interface BuilderSchema<T extends Ent> extends Schema {
63
63
  ent: EntConstructor<T>;
64
64
  }
65
+ export declare class EntBuilderSchema<T extends Ent> extends EntSchema {
66
+ ent: EntConstructor<T>;
67
+ constructor(ent: EntConstructor<T>, cfg: SchemaConfig);
68
+ }
65
69
  export declare function getBuilderSchema<T extends Ent>(cfg: SchemaConfig, ent: EntConstructor<T>): BuilderSchema<T>;
66
70
  export declare function getBuilderSchemaFromFields<T extends Ent>(fields: FieldMap, ent: EntConstructor<T>): BuilderSchema<T>;
67
71
  export declare function getBuilderSchemaTZFromFields<T extends Ent>(fields: FieldMap, ent: EntConstructor<T>): BuilderSchema<T>;
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.SimpleAction = exports.SimpleBuilder = exports.getFieldInfo = exports.getTableName = exports.getSchemaName = exports.getBuilderSchemaTZFromFields = exports.getBuilderSchemaFromFields = exports.getBuilderSchema = exports.Address = exports.Message = exports.Group = exports.Contact = exports.Event = exports.User = void 0;
6
+ exports.SimpleAction = exports.SimpleBuilder = exports.getFieldInfo = exports.getTableName = exports.getSchemaName = exports.getBuilderSchemaTZFromFields = exports.getBuilderSchemaFromFields = exports.getBuilderSchema = exports.EntBuilderSchema = exports.Address = exports.Message = exports.Group = exports.Contact = exports.Event = exports.User = void 0;
7
7
  const privacy_1 = require("../core/privacy");
8
8
  const orchestrator_1 = require("../action/orchestrator");
9
9
  const action_1 = require("../action");
@@ -99,6 +99,13 @@ class Address {
99
99
  }
100
100
  }
101
101
  exports.Address = Address;
102
+ class EntBuilderSchema extends base_schema_1.EntSchema {
103
+ constructor(ent, cfg) {
104
+ super(cfg);
105
+ this.ent = ent;
106
+ }
107
+ }
108
+ exports.EntBuilderSchema = EntBuilderSchema;
102
109
  function getBuilderSchema(cfg, ent) {
103
110
  return {
104
111
  ...new base_schema_1.EntSchema(cfg),
@@ -355,9 +355,6 @@ function randomDB() {
355
355
  // always ensure it starts with an alpha character
356
356
  return "abcdefghijklmnopqrstuvwxyz"[Math.floor(Math.random() * 26)] + str;
357
357
  }
358
- function isDialect(dialect) {
359
- return !Array.isArray(dialect);
360
- }
361
358
  class TempDB {
362
359
  constructor(dialect, tables) {
363
360
  this.tables = new Map();
@@ -1,3 +0,0 @@
1
- import { GraphQLEnumValue } from "graphql";
2
- export declare function convertToGQLEnum(val: string | null, tsValues: string[], gqlValues: GraphQLEnumValue[]): any;
3
- export declare function convertFromGQLEnum(val: string, tsValues: string[], gqlValues: GraphQLEnumValue[]): string;
package/graphql/enums.js DELETED
@@ -1,25 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.convertFromGQLEnum = exports.convertToGQLEnum = void 0;
4
- function convertToGQLEnum(val, tsValues, gqlValues) {
5
- for (let i = 0; i < tsValues.length; i++) {
6
- let tsVal = tsValues[i];
7
- let gqlValue = gqlValues[i];
8
- if (val === tsVal) {
9
- return gqlValue.value;
10
- }
11
- }
12
- return val;
13
- }
14
- exports.convertToGQLEnum = convertToGQLEnum;
15
- function convertFromGQLEnum(val, tsValues, gqlValues) {
16
- for (let i = 0; i < tsValues.length; i++) {
17
- let tsVal = tsValues[i];
18
- let gqlValue = gqlValues[i];
19
- if (val === gqlValue.value) {
20
- return tsVal;
21
- }
22
- }
23
- return val;
24
- }
25
- exports.convertFromGQLEnum = convertFromGQLEnum;