@snowtop/ent 0.1.0-alpha75 → 0.1.0-alpha79

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.
@@ -53,7 +53,7 @@ export interface Action<TEnt extends Ent<TViewer>, TBuilder extends Builder<TEnt
53
53
  getObservers?(): Observer<TEnt, TBuilder, TViewer, TInput, TExistingEnt>[];
54
54
  getValidators?(): Validator<TEnt, TBuilder, TViewer, TInput, TExistingEnt>[];
55
55
  getInput(): TInput;
56
- transformWrite?: (stmt: UpdateOperation<TEnt, TViewer>) => Promise<TransformedUpdateOperation<TEnt>> | TransformedUpdateOperation<TEnt> | null;
56
+ transformWrite?: (stmt: UpdateOperation<TEnt, TViewer>) => Promise<TransformedUpdateOperation<TEnt, TViewer>> | TransformedUpdateOperation<TEnt, TViewer> | null;
57
57
  valid(): Promise<boolean>;
58
58
  validX(): Promise<void>;
59
59
  viewerForEntLoad?(data: Data, context?: Context<TViewer>): TViewer | Promise<TViewer>;
@@ -108,6 +108,7 @@ export declare class EntChangeset<T extends Ent> implements Changeset {
108
108
  private options?;
109
109
  private _executor;
110
110
  constructor(viewer: Viewer, placeholderID: ID, ent: EntConstructor<T>, operations: DataOperation[], dependencies?: Map<ID, Builder<Ent<Viewer<Ent<any> | null, ID | null>>, Viewer<Ent<any> | null, ID | null>, Ent<Viewer<Ent<any> | null, ID | null>> | null>> | undefined, changesets?: Changeset[] | undefined, options?: OrchestratorOptions<T, Data, Viewer<Ent<any> | null, ID | null>, MaybeNull<T>> | undefined);
111
+ static changesetFrom(builder: Builder<any, any, any>, ops: DataOperation[]): EntChangeset<any>;
111
112
  executor(): Executor;
112
113
  }
113
114
  export {};
@@ -487,6 +487,10 @@ class Orchestrator {
487
487
  // this.defaultFieldsByFieldName[k] = val;
488
488
  }
489
489
  }
490
+ if (transformed.changeset) {
491
+ const ct = await transformed.changeset();
492
+ this.changesets.push(ct);
493
+ }
490
494
  this.actualOperation = this.getWriteOpForSQLStamentOp(transformed.op);
491
495
  if (transformed.existingEnt) {
492
496
  // @ts-ignore
@@ -719,6 +723,9 @@ class Orchestrator {
719
723
  }
720
724
  }
721
725
  exports.Orchestrator = Orchestrator;
726
+ function randomNum() {
727
+ return Math.random().toString(10).substring(2);
728
+ }
722
729
  class EntChangeset {
723
730
  constructor(viewer, placeholderID, ent, operations, dependencies, changesets, options) {
724
731
  this.viewer = viewer;
@@ -729,6 +736,9 @@ class EntChangeset {
729
736
  this.changesets = changesets;
730
737
  this.options = options;
731
738
  }
739
+ static changesetFrom(builder, ops) {
740
+ return new EntChangeset(builder.viewer, `$ent.idPlaceholderID$ ${randomNum()}-${builder.ent.name}`, builder.ent, ops);
741
+ }
732
742
  executor() {
733
743
  if (this._executor) {
734
744
  return this._executor;
package/core/clause.js CHANGED
@@ -184,9 +184,9 @@ class postgresArrayOperator {
184
184
  }
185
185
  logValues() {
186
186
  if (isSensitive(this.value)) {
187
- return [this.value.logValue()];
187
+ return [`{${this.value.logValue()}}`];
188
188
  }
189
- return [this.value];
189
+ return [`{${this.value}}`];
190
190
  }
191
191
  instanceKey() {
192
192
  if (this.not) {
@@ -211,6 +211,18 @@ class postgresArrayOperatorList extends postgresArrayOperator {
211
211
  .join(", ")}}`,
212
212
  ];
213
213
  }
214
+ logValues() {
215
+ return [
216
+ `{${this.value
217
+ .map((v) => {
218
+ if (isSensitive(v)) {
219
+ return v.logValue();
220
+ }
221
+ return v;
222
+ })
223
+ .join(", ")}}`,
224
+ ];
225
+ }
214
226
  }
215
227
  class inClause {
216
228
  constructor(col, value, type = "uuid") {
package/core/db.d.ts CHANGED
@@ -28,7 +28,7 @@ export default class DB {
28
28
  getConnection(): Connection;
29
29
  getPool(): Queryer;
30
30
  getNewClient(): Promise<Client>;
31
- getSQLiteClient(): Promise<Sqlite>;
31
+ getSQLiteClient(): Sqlite;
32
32
  endPool(): Promise<void>;
33
33
  static getInstance(): DB;
34
34
  static getDialect(): Dialect;
package/core/db.js CHANGED
@@ -148,7 +148,7 @@ class DB {
148
148
  async getNewClient() {
149
149
  return this.q.newClient();
150
150
  }
151
- async getSQLiteClient() {
151
+ getSQLiteClient() {
152
152
  if (this.db.dialect == Dialect.Postgres) {
153
153
  throw new Error(`can't call getSQLiteClient when dialect is postgres`);
154
154
  }
package/core/ent.d.ts CHANGED
@@ -89,6 +89,12 @@ export interface EditNodeOptions<T extends Ent> extends EditRowOptions {
89
89
  placeholderID?: ID;
90
90
  key: string;
91
91
  }
92
+ export declare class RawQueryOperation implements DataOperation {
93
+ private queries;
94
+ constructor(queries: (string | parameterizedQueryOptions)[]);
95
+ performWrite(queryer: Queryer, context?: Context): Promise<void>;
96
+ performWriteSync(queryer: SyncQueryer, context?: Context): void;
97
+ }
92
98
  export declare class EditNodeOperation<T extends Ent> implements DataOperation {
93
99
  options: EditNodeOptions<T>;
94
100
  private existingEnt;
package/core/ent.js CHANGED
@@ -22,8 +22,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
22
22
  return (mod && mod.__esModule) ? mod : { "default": mod };
23
23
  };
24
24
  Object.defineProperty(exports, "__esModule", { value: true });
25
- exports.loadNodesByEdge = exports.loadEdgeForID2 = 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.buildGroupQuery = exports.buildQuery = exports.loadRows = exports.performRawQuery = exports.loadRow = exports.loadRowX = exports.loadDerivedEntX = exports.loadDerivedEnt = 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;
26
- exports.getEdgeTypeInGroup = exports.applyPrivacyPolicyForRows = exports.applyPrivacyPolicyForRow = void 0;
25
+ exports.loadEdgeForID2 = 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.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;
26
+ exports.getEdgeTypeInGroup = exports.applyPrivacyPolicyForRows = exports.applyPrivacyPolicyForRow = exports.loadNodesByEdge = void 0;
27
27
  const db_1 = __importStar(require("./db"));
28
28
  const privacy_1 = require("./privacy");
29
29
  const clause = __importStar(require("./clause"));
@@ -128,7 +128,7 @@ async function applyPrivacyPolicyForRowAndStoreInCacheX(viewer, options, row, in
128
128
  throw ent;
129
129
  }
130
130
  if (ent === null) {
131
- throw new Error(`TODO`);
131
+ throw new Error(`applyPrivacyPolicyForRowImpl returned null when it shouldn't. ent error`);
132
132
  }
133
133
  return ent;
134
134
  }
@@ -151,6 +151,7 @@ async function loadEntViaKey(viewer, key, options) {
151
151
  return null;
152
152
  }
153
153
  // TODO every row.id needs to be audited...
154
+ // https://github.com/lolopinto/ent/issues/1064
154
155
  const info = entFromCacheMaybe(viewer, row.id, options);
155
156
  if (info.ent !== undefined) {
156
157
  return info.ent;
@@ -158,7 +159,6 @@ async function loadEntViaKey(viewer, key, options) {
158
159
  return applyPrivacyPolicyForRowAndStoreInCache(viewer, options, row, info);
159
160
  }
160
161
  exports.loadEntViaKey = loadEntViaKey;
161
- // need a cached error...
162
162
  async function loadEntX(viewer, id, options) {
163
163
  const info = entFromCacheMaybe(viewer, id, options);
164
164
  if (info.error !== undefined) {
@@ -175,8 +175,6 @@ async function loadEntX(viewer, id, options) {
175
175
  return applyPrivacyPolicyForRowAndStoreInCacheX(viewer, options, row, info);
176
176
  }
177
177
  exports.loadEntX = loadEntX;
178
- // TODO test this and loadEntViaKey
179
- // replace loadEntViaClause??
180
178
  async function loadEntXViaKey(viewer, key, options) {
181
179
  const row = await options.loaderFactory
182
180
  .createLoader(viewer.context)
@@ -242,6 +240,7 @@ async function loadEnts(viewer, options, ...ids) {
242
240
  });
243
241
  if (ent === null) {
244
242
  // TODO this should return null if not loadable...
243
+ // https://github.com/lolopinto/ent/issues/1070
245
244
  continue;
246
245
  }
247
246
  // @ts-ignore
@@ -282,12 +281,11 @@ async function loadEnts(viewer, options, ...ids) {
282
281
  }
283
282
  if (ent !== undefined) {
284
283
  // TODO this should return null if not loadable...?
284
+ // TODO https://github.com/lolopinto/ent/issues/1070
285
285
  m.set(id, ent);
286
286
  }
287
287
  }
288
288
  return m;
289
- // TODO do we want to change this to be a map not a list so that it's easy to check for existence?
290
- // TODO eventually this should be doing a cache then db queyr and maybe depend on dataloader to get all the results at once
291
289
  }
292
290
  exports.loadEnts = loadEnts;
293
291
  // calls loadEnts and returns the results sorted in the order they were passed in
@@ -324,6 +322,7 @@ async function loadCustomEnts(viewer, options, query) {
324
322
  const result = new Array(rows.length);
325
323
  await Promise.all(rows.map(async (row, idx) => {
326
324
  // TODO what if key is different
325
+ // TODO https://github.com/lolopinto/ent/issues/1064
327
326
  const info = entFromCacheMaybe(viewer, row.id, options);
328
327
  if (info.ent !== undefined) {
329
328
  if (info.ent === null) {
@@ -533,42 +532,27 @@ async function loadRow(options) {
533
532
  }
534
533
  const query = buildQuery(options);
535
534
  logQuery(query, options.clause.logValues());
536
- try {
537
- const pool = db_1.default.getInstance().getPool();
538
- const res = await pool.query(query, options.clause.values());
539
- if (res.rowCount != 1) {
540
- if (res.rowCount > 1) {
541
- (0, logger_1.log)("error", "got more than one row for query " + query);
542
- }
543
- return null;
544
- }
545
- // put the row in the cache...
546
- if (cache) {
547
- cache.primeCache(options, res.rows[0]);
535
+ const pool = db_1.default.getInstance().getPool();
536
+ const res = await pool.query(query, options.clause.values());
537
+ if (res.rowCount != 1) {
538
+ if (res.rowCount > 1) {
539
+ (0, logger_1.log)("error", "got more than one row for query " + query);
548
540
  }
549
- return res.rows[0];
550
- }
551
- catch (e) {
552
- // an example of an error being suppressed
553
- // another one. TODO https://github.com/lolopinto/ent/issues/862
554
- (0, logger_1.log)("error", e);
555
541
  return null;
556
542
  }
543
+ // put the row in the cache...
544
+ if (cache) {
545
+ cache.primeCache(options, res.rows[0]);
546
+ }
547
+ return res.rows[0];
557
548
  }
558
549
  exports.loadRow = loadRow;
559
550
  // this always goes to the db, no cache, nothing
560
551
  async function performRawQuery(query, values, logValues) {
561
552
  const pool = db_1.default.getInstance().getPool();
562
553
  logQuery(query, logValues || []);
563
- try {
564
- const res = await pool.queryAll(query, values);
565
- return res.rows;
566
- }
567
- catch (e) {
568
- // TODO need to change every query to catch an error!
569
- (0, logger_1.log)("error", e);
570
- return [];
571
- }
554
+ const res = await pool.queryAll(query, values);
555
+ return res.rows;
572
556
  }
573
557
  exports.performRawQuery = performRawQuery;
574
558
  // TODO this should throw, we can't be hiding errors here
@@ -626,6 +610,36 @@ function buildGroupQuery(options) {
626
610
  ];
627
611
  }
628
612
  exports.buildGroupQuery = buildGroupQuery;
613
+ class RawQueryOperation {
614
+ constructor(queries) {
615
+ this.queries = queries;
616
+ }
617
+ async performWrite(queryer, context) {
618
+ for (const q of this.queries) {
619
+ if (typeof q === "string") {
620
+ logQuery(q, []);
621
+ await queryer.query(q);
622
+ }
623
+ else {
624
+ logQuery(q.query, q.logValues || []);
625
+ await queryer.query(q.query, q.values);
626
+ }
627
+ }
628
+ }
629
+ performWriteSync(queryer, context) {
630
+ for (const q of this.queries) {
631
+ if (typeof q === "string") {
632
+ logQuery(q, []);
633
+ queryer.execSync(q);
634
+ }
635
+ else {
636
+ logQuery(q.query, q.logValues || []);
637
+ queryer.execSync(q.query, q.values);
638
+ }
639
+ }
640
+ }
641
+ }
642
+ exports.RawQueryOperation = RawQueryOperation;
629
643
  class EditNodeOperation {
630
644
  constructor(options, existingEnt = null) {
631
645
  this.options = options;
@@ -1094,40 +1108,26 @@ function isSyncQueryer(queryer) {
1094
1108
  async function mutateRow(queryer, query, values, logValues, options) {
1095
1109
  logQuery(query, logValues);
1096
1110
  let cache = options.context?.cache;
1097
- try {
1098
- let res;
1099
- if (isSyncQueryer(queryer)) {
1100
- res = queryer.execSync(query, values);
1101
- }
1102
- else {
1103
- res = await queryer.exec(query, values);
1104
- }
1105
- if (cache) {
1106
- cache.clearCache();
1107
- }
1108
- return res;
1111
+ let res;
1112
+ if (isSyncQueryer(queryer)) {
1113
+ res = queryer.execSync(query, values);
1109
1114
  }
1110
- catch (err) {
1111
- // TODO:::why is this not rethrowing?
1112
- (0, logger_1.log)("error", err);
1113
- throw err;
1115
+ else {
1116
+ res = await queryer.exec(query, values);
1117
+ }
1118
+ if (cache) {
1119
+ cache.clearCache();
1114
1120
  }
1121
+ return res;
1115
1122
  }
1116
1123
  function mutateRowSync(queryer, query, values, logValues, options) {
1117
1124
  logQuery(query, logValues);
1118
1125
  let cache = options.context?.cache;
1119
- try {
1120
- const res = queryer.execSync(query, values);
1121
- if (cache) {
1122
- cache.clearCache();
1123
- }
1124
- return res;
1125
- }
1126
- catch (err) {
1127
- // TODO:::why is this not rethrowing?
1128
- (0, logger_1.log)("error", err);
1129
- throw err;
1126
+ const res = queryer.execSync(query, values);
1127
+ if (cache) {
1128
+ cache.clearCache();
1130
1129
  }
1130
+ return res;
1131
1131
  }
1132
1132
  function buildInsertQuery(options, suffix) {
1133
1133
  let fields = [];
@@ -1516,6 +1516,8 @@ async function applyPrivacyPolicyForRowX(viewer, options, row) {
1516
1516
  return await applyPrivacyPolicyForEntX(viewer, ent, row, options);
1517
1517
  }
1518
1518
  // TODO this needs to be changed to use ent cache as needed...
1519
+ // most current callsites fine not using it
1520
+ // custom_query is one that should be updated
1519
1521
  async function applyPrivacyPolicyForRows(viewer, rows, options) {
1520
1522
  let m = new Map();
1521
1523
  // apply privacy logic
@@ -71,6 +71,9 @@ function createDataLoader(options) {
71
71
  const rows = await (0, ent_1.loadRows)(rowOptions);
72
72
  for (const row of rows) {
73
73
  const id = row[col];
74
+ if (id === undefined) {
75
+ throw new Error(`need to query for column ${col} when using an object loader because the query may not be sorted and we need the id to maintain sort order`);
76
+ }
74
77
  const idx = m.get(id);
75
78
  if (idx === undefined) {
76
79
  throw new Error(`malformed query. got ${id} back but didn't query for it`);
@@ -195,6 +198,9 @@ class ObjectLoader {
195
198
  }
196
199
  }
197
200
  exports.ObjectLoader = ObjectLoader;
201
+ // NOTE: if not querying for all columns
202
+ // have to query for the id field as one of the fields
203
+ // because it's used to maintain sort order of the queried ids
198
204
  class ObjectLoaderFactory {
199
205
  constructor(options) {
200
206
  this.options = options;
package/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export * from "./core/base";
2
- export { loadEnt, loadCustomData, loadCustomEnts, loadEntX, loadEnts, CustomQuery, loadDerivedEnt, loadDerivedEntX, loadEntViaKey, loadEntXViaKey, performRawQuery, loadRowX, loadRow, loadRows, DataOperation, EditNodeOptions, EditNodeOperation, EdgeOperation, DeleteNodeOperation, AssocEdge, AssocEdgeInputOptions, AssocEdgeInput, AssocEdgeData, loadEdgeData, loadEdgeDatas, loadEdges, loadUniqueEdge, loadUniqueNode, loadRawEdgeCountX, loadEdgeForID2, loadNodesByEdge, getEdgeTypeInGroup, setGlobalSchema, } from "./core/ent";
2
+ export { loadEnt, loadCustomData, loadCustomEnts, loadEntX, loadEnts, CustomQuery, loadDerivedEnt, loadDerivedEntX, loadEntViaKey, loadEntXViaKey, performRawQuery, loadRowX, loadRow, loadRows, DataOperation, EditNodeOptions, EditNodeOperation, RawQueryOperation, EdgeOperation, DeleteNodeOperation, AssocEdge, AssocEdgeInputOptions, AssocEdgeInput, AssocEdgeData, loadEdgeData, loadEdgeDatas, loadEdges, loadUniqueEdge, loadUniqueNode, loadRawEdgeCountX, loadEdgeForID2, loadNodesByEdge, getEdgeTypeInGroup, setGlobalSchema, } from "./core/ent";
3
3
  import DB from "./core/db";
4
4
  export * from "./core/loaders";
5
5
  export { DB };
package/index.js CHANGED
@@ -25,8 +25,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
25
25
  return (mod && mod.__esModule) ? mod : { "default": mod };
26
26
  };
27
27
  Object.defineProperty(exports, "__esModule", { value: true });
28
- exports.DenyIfEdgeDoesNotExistRule = exports.DenyIfViewerOutboundEdgeExistsRule = exports.DenyIfViewerInboundEdgeExistsRule = exports.DenyIfEdgeExistsRule = exports.AllowIfViewerOutboundEdgeExistsRule = exports.AllowIfViewerInboundEdgeExistsRule = exports.AllowIfEdgeExistsRule = exports.DenyIfViewerEqualsRule = exports.AllowIfViewerEqualsRule = exports.DenyIfEntPropertyIsRule = exports.AllowIfEntPropertyIsRule = exports.AllowIfViewerIsEntPropertyRule = exports.AllowIfViewerIsRule = exports.AllowIfFuncRule = exports.AllowIfViewerRule = exports.AllowIfHasIdentity = exports.DenyIfLoggedOutRule = exports.DenyIfLoggedInRule = exports.AlwaysDenyRule = exports.AlwaysAllowRule = exports.EntPrivacyError = exports.DB = exports.setGlobalSchema = exports.getEdgeTypeInGroup = exports.loadNodesByEdge = exports.loadEdgeForID2 = exports.loadRawEdgeCountX = exports.loadUniqueNode = exports.loadUniqueEdge = exports.loadEdges = exports.loadEdgeDatas = exports.loadEdgeData = exports.AssocEdgeData = exports.AssocEdge = exports.DeleteNodeOperation = exports.EdgeOperation = exports.EditNodeOperation = exports.loadRows = exports.loadRow = exports.loadRowX = exports.performRawQuery = exports.loadEntXViaKey = exports.loadEntViaKey = exports.loadDerivedEntX = exports.loadDerivedEnt = exports.loadEnts = exports.loadEntX = exports.loadCustomEnts = exports.loadCustomData = exports.loadEnt = void 0;
29
- exports.setLogLevels = exports.loadConfig = exports.LoggedOutViewer = exports.IDViewer = exports.ContextCache = exports.query = exports.AllowIfViewerHasIdentityPrivacyPolicy = exports.AllowIfViewerPrivacyPolicy = exports.AllowIfSubPolicyAllowsRule = exports.AllowIfConditionAppliesRule = exports.AlwaysDenyPrivacyPolicy = exports.AlwaysAllowPrivacyPolicy = exports.applyPrivacyPolicyX = exports.applyPrivacyPolicy = exports.DelayedResultRule = exports.DenyIfEntIsVisiblePolicy = exports.AllowIfEntIsVisiblePolicy = exports.DenyIfEntIsNotVisibleRule = exports.DenyIfEntIsVisibleRule = exports.AllowIfEntIsNotVisibleRule = exports.AllowIfEntIsVisibleRule = exports.DenyIfViewerOutboundEdgeDoesNotExistRule = exports.DenyIfViewerInboundEdgeDoesNotExistRule = void 0;
28
+ exports.DenyIfViewerOutboundEdgeExistsRule = exports.DenyIfViewerInboundEdgeExistsRule = exports.DenyIfEdgeExistsRule = exports.AllowIfViewerOutboundEdgeExistsRule = exports.AllowIfViewerInboundEdgeExistsRule = exports.AllowIfEdgeExistsRule = exports.DenyIfViewerEqualsRule = exports.AllowIfViewerEqualsRule = exports.DenyIfEntPropertyIsRule = exports.AllowIfEntPropertyIsRule = exports.AllowIfViewerIsEntPropertyRule = exports.AllowIfViewerIsRule = exports.AllowIfFuncRule = exports.AllowIfViewerRule = exports.AllowIfHasIdentity = exports.DenyIfLoggedOutRule = exports.DenyIfLoggedInRule = exports.AlwaysDenyRule = exports.AlwaysAllowRule = exports.EntPrivacyError = exports.DB = exports.setGlobalSchema = exports.getEdgeTypeInGroup = exports.loadNodesByEdge = exports.loadEdgeForID2 = exports.loadRawEdgeCountX = exports.loadUniqueNode = exports.loadUniqueEdge = exports.loadEdges = exports.loadEdgeDatas = exports.loadEdgeData = exports.AssocEdgeData = exports.AssocEdge = exports.DeleteNodeOperation = exports.EdgeOperation = exports.RawQueryOperation = exports.EditNodeOperation = exports.loadRows = exports.loadRow = exports.loadRowX = exports.performRawQuery = exports.loadEntXViaKey = exports.loadEntViaKey = exports.loadDerivedEntX = exports.loadDerivedEnt = exports.loadEnts = exports.loadEntX = exports.loadCustomEnts = exports.loadCustomData = exports.loadEnt = void 0;
29
+ exports.setLogLevels = exports.loadConfig = exports.LoggedOutViewer = exports.IDViewer = exports.ContextCache = exports.query = exports.AllowIfViewerHasIdentityPrivacyPolicy = exports.AllowIfViewerPrivacyPolicy = exports.AllowIfSubPolicyAllowsRule = exports.AllowIfConditionAppliesRule = exports.AlwaysDenyPrivacyPolicy = exports.AlwaysAllowPrivacyPolicy = exports.applyPrivacyPolicyX = exports.applyPrivacyPolicy = exports.DelayedResultRule = exports.DenyIfEntIsVisiblePolicy = exports.AllowIfEntIsVisiblePolicy = exports.DenyIfEntIsNotVisibleRule = exports.DenyIfEntIsVisibleRule = exports.AllowIfEntIsNotVisibleRule = exports.AllowIfEntIsVisibleRule = exports.DenyIfViewerOutboundEdgeDoesNotExistRule = exports.DenyIfViewerInboundEdgeDoesNotExistRule = exports.DenyIfEdgeDoesNotExistRule = void 0;
30
30
  __exportStar(require("./core/base"), exports);
31
31
  var ent_1 = require("./core/ent");
32
32
  Object.defineProperty(exports, "loadEnt", { enumerable: true, get: function () { return ent_1.loadEnt; } });
@@ -44,6 +44,7 @@ Object.defineProperty(exports, "loadRowX", { enumerable: true, get: function ()
44
44
  Object.defineProperty(exports, "loadRow", { enumerable: true, get: function () { return ent_1.loadRow; } });
45
45
  Object.defineProperty(exports, "loadRows", { enumerable: true, get: function () { return ent_1.loadRows; } });
46
46
  Object.defineProperty(exports, "EditNodeOperation", { enumerable: true, get: function () { return ent_1.EditNodeOperation; } });
47
+ Object.defineProperty(exports, "RawQueryOperation", { enumerable: true, get: function () { return ent_1.RawQueryOperation; } });
47
48
  Object.defineProperty(exports, "EdgeOperation", { enumerable: true, get: function () { return ent_1.EdgeOperation; } });
48
49
  Object.defineProperty(exports, "DeleteNodeOperation", { enumerable: true, get: function () { return ent_1.DeleteNodeOperation; } });
49
50
  Object.defineProperty(exports, "AssocEdge", { enumerable: true, get: function () { return ent_1.AssocEdge; } });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@snowtop/ent",
3
- "version": "0.1.0-alpha75",
3
+ "version": "0.1.0-alpha79",
4
4
  "description": "snowtop ent framework",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -1,5 +1,5 @@
1
1
  import { Data, Ent, LoaderInfo, PrivacyPolicy, Viewer } from "../core/base";
2
- import { Builder } from "../action/action";
2
+ import { Builder, Changeset } from "../action/action";
3
3
  import { Clause } from "../core/clause";
4
4
  import { AssocEdgeInput } from "../core/ent";
5
5
  export declare type FieldMap = {
@@ -79,7 +79,7 @@ export interface Pattern {
79
79
  disableMixin?: boolean;
80
80
  edges?: Edge[];
81
81
  transformRead?: () => Clause;
82
- transformWrite?: <T extends Ent>(stmt: UpdateOperation<T>) => TransformedUpdateOperation<T> | null;
82
+ transformWrite?: <T extends Ent<TViewer>, TViewer extends Viewer = Viewer>(stmt: UpdateOperation<T, TViewer>) => TransformedUpdateOperation<T, TViewer> | null;
83
83
  transformsDelete?: boolean;
84
84
  transformsInsert?: boolean;
85
85
  transformsUpdate?: boolean;
@@ -99,14 +99,15 @@ export interface TransformedEdgeUpdateOperation {
99
99
  }
100
100
  export interface UpdateOperation<TEnt extends Ent<TViewer>, TViewer extends Viewer = Viewer> {
101
101
  op: SQLStatementOperation;
102
- builder: Builder<TEnt, TViewer>;
102
+ builder: Builder<TEnt, TViewer, any>;
103
103
  input: Data;
104
104
  data?: Map<string, any>;
105
105
  }
106
- export interface TransformedUpdateOperation<T extends Ent> {
106
+ export interface TransformedUpdateOperation<T extends Ent<TViewer>, TViewer extends Viewer = Viewer> {
107
107
  op: SQLStatementOperation;
108
108
  data?: Data;
109
109
  existingEnt?: T | null;
110
+ changeset?(): Promise<Changeset> | Changeset;
110
111
  }
111
112
  export declare enum DBType {
112
113
  UUID = "UUID",
@@ -0,0 +1,4 @@
1
+ export declare class DBTimeZone {
2
+ private static getVal;
3
+ static getDateOffset(d: Date): Promise<string>;
4
+ }
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.DBTimeZone = void 0;
7
+ const luxon_1 = require("luxon");
8
+ const schema_1 = require("../schema");
9
+ const db_1 = __importDefault(require("../core/db"));
10
+ let dbCurrentZone = undefined;
11
+ class DBTimeZone {
12
+ static async getVal() {
13
+ if (dbCurrentZone !== undefined) {
14
+ return dbCurrentZone;
15
+ }
16
+ const r = await db_1.default.getInstance()
17
+ .getPool()
18
+ .query("SELECT current_setting('TIMEZONE');");
19
+ if (r.rows.length) {
20
+ dbCurrentZone = r.rows[0].current_setting;
21
+ }
22
+ else {
23
+ dbCurrentZone = null;
24
+ }
25
+ return dbCurrentZone;
26
+ }
27
+ static async getDateOffset(d) {
28
+ let zone = await DBTimeZone.getVal();
29
+ let dt = luxon_1.DateTime.fromJSDate(d);
30
+ if (zone) {
31
+ dt = dt.setZone(zone);
32
+ }
33
+ // use
34
+ const val = (0, schema_1.leftPad)(dt.get("offset") / 60);
35
+ if (val == "00") {
36
+ return "+00";
37
+ }
38
+ return val;
39
+ }
40
+ }
41
+ exports.DBTimeZone = DBTimeZone;
@@ -1,16 +1,38 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
4
20
  };
5
21
  Object.defineProperty(exports, "__esModule", { value: true });
6
22
  exports.deleteRowsForTest = exports.editRowForTest = exports.createRowForTest = void 0;
7
23
  const ent_1 = require("../core/ent");
8
- const db_1 = __importDefault(require("../core/db"));
24
+ const db_1 = __importStar(require("../core/db"));
9
25
  function isSyncClient(client) {
10
26
  return client.execSync !== undefined;
11
27
  }
12
28
  async function createRowForTest(options, suffix) {
13
- const client = await db_1.default.getInstance().getNewClient();
29
+ let client;
30
+ if (db_1.Dialect.SQLite === db_1.default.getDialect()) {
31
+ client = db_1.default.getInstance().getSQLiteClient();
32
+ }
33
+ else {
34
+ client = await db_1.default.getInstance().getNewClient();
35
+ }
14
36
  try {
15
37
  if (isSyncClient(client)) {
16
38
  return (0, ent_1.createRowSync)(client, options, suffix || "");