@snowtop/ent 0.0.39-alpha4 → 0.0.39-alpha6

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.
@@ -51,7 +51,7 @@ export interface Action<T extends Ent> {
51
51
  observers?: Observer<T>[];
52
52
  validators?: Validator<T>[];
53
53
  getInput(): Data;
54
- transformWrite?: (stmt: UpdateOperation<T>) => Promise<TransformedUpdateOperation<T>> | TransformedUpdateOperation<T> | undefined;
54
+ transformWrite?: <T2 extends Ent>(stmt: UpdateOperation<T2>) => Promise<TransformedUpdateOperation<T2>> | TransformedUpdateOperation<T2> | undefined;
55
55
  valid(): Promise<boolean>;
56
56
  validX(): Promise<void>;
57
57
  viewerForEntLoad?(data: Data): Viewer | Promise<Viewer>;
package/core/clause.d.ts CHANGED
@@ -36,6 +36,7 @@ export declare function Less(col: string, value: any): simpleClause;
36
36
  export declare function GreaterEq(col: string, value: any): simpleClause;
37
37
  export declare function LessEq(col: string, value: any): simpleClause;
38
38
  export declare function And(...args: Clause[]): compositeClause;
39
+ export declare function AndOptional(...args: (Clause | undefined)[]): Clause;
39
40
  export declare function Or(...args: Clause[]): compositeClause;
40
41
  export declare function In(col: string, ...values: any): Clause;
41
42
  export declare function sensitiveValue(val: any): SensitiveValue;
package/core/clause.js CHANGED
@@ -19,7 +19,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
19
19
  return result;
20
20
  };
21
21
  Object.defineProperty(exports, "__esModule", { value: true });
22
- exports.sensitiveValue = exports.In = exports.Or = exports.And = exports.LessEq = exports.GreaterEq = exports.Less = exports.Greater = exports.NotEq = exports.Eq = void 0;
22
+ exports.sensitiveValue = exports.In = exports.Or = exports.AndOptional = exports.And = exports.LessEq = exports.GreaterEq = exports.Less = exports.Greater = exports.NotEq = exports.Eq = void 0;
23
23
  const db_1 = __importStar(require("./db"));
24
24
  function isSensitive(val) {
25
25
  return (val !== null &&
@@ -50,11 +50,10 @@ class simpleClause {
50
50
  return `${this.col} ${this.op} ?`;
51
51
  }
52
52
  sqliteNull() {
53
- if (!this.handleSqliteNull) {
53
+ if (!this.handleSqliteNull || this.value !== null) {
54
54
  return;
55
55
  }
56
- const dialect = db_1.default.getDialect();
57
- if (this.value !== null || dialect !== db_1.Dialect.SQLite) {
56
+ if (db_1.default.getDialect() !== db_1.Dialect.SQLite) {
58
57
  return;
59
58
  }
60
59
  return this.handleSqliteNull;
@@ -236,6 +235,15 @@ function And(...args) {
236
235
  return new compositeClause(args, " AND ");
237
236
  }
238
237
  exports.And = And;
238
+ function AndOptional(...args) {
239
+ // @ts-ignore
240
+ let filtered = args.filter((v) => v !== undefined);
241
+ if (filtered.length === 1) {
242
+ return filtered[0];
243
+ }
244
+ return And(...filtered);
245
+ }
246
+ exports.AndOptional = AndOptional;
239
247
  function Or(...args) {
240
248
  return new compositeClause(args, " OR ");
241
249
  }
package/core/ent.js CHANGED
@@ -84,54 +84,8 @@ function createDataLoader(options) {
84
84
  return result;
85
85
  }, loaderOptions);
86
86
  }
87
- // TODO probably delete since we're going to generate it now
88
- // instead of passing this here.
89
- // async function doPerformQuery<T extends Ent>(
90
- // viewer: Viewer,
91
- // id: ID,
92
- // options: LoadEntOptions<T>,
93
- // ): Promise<Data | null> {
94
- // let newClause: clause.Clause | undefined = undefined;
95
- // if (options.schema) {
96
- // const schema = getSchema(options.schema);
97
- // if (schema.patterns) {
98
- // for (const p of schema.patterns) {
99
- // if (p.transformRead) {
100
- // newClause = p.transformRead({
101
- // op: QueryOperation.Select,
102
- // clause: clause.Eq("id", id),
103
- // });
104
- // }
105
- // }
106
- // }
107
- // }
108
- // // we want a loader if possible . we don't want this to slow
109
- // // things down...
110
- // // id = x and deleted_at == null
111
- // if (newClause) {
112
- // // loader
113
- // // return loadRow({});
114
- // // TODO
115
- // }
116
- // // we want a deleted_at loader...
117
- // return options.loaderFactory.createLoader(viewer.context).load(id);
118
- // }
119
87
  // Ent accessors
120
88
  async function loadEnt(viewer, id, options) {
121
- let newClause;
122
- // if (options.schema) {
123
- // const schema = getSchema(options.schema);
124
- // if (schema.patterns) {
125
- // for (const p of schema.patterns) {
126
- // if (p.transformRead) {
127
- // newClause = p.transformRead({
128
- // op: QueryOperation.Select,
129
- // clause: clause.Eq("id", id),
130
- // });
131
- // }
132
- // }
133
- // }
134
- // }
135
89
  const row = await options.loaderFactory.createLoader(viewer.context).load(id);
136
90
  return await applyPrivacyPolicyForRow(viewer, options, row);
137
91
  }
@@ -480,7 +434,7 @@ class EditNodeOperation {
480
434
  };
481
435
  if (this.existingEnt) {
482
436
  if (this.hasData(options.fields)) {
483
- // even this with returning * doesn't work if transformed...
437
+ // even this with returning * may not always work if transformed...
484
438
  // we can have a transformed flag to see if it should be returned?
485
439
  this.row = await editRow(queryer, options, this.existingEnt.id, "RETURNING *");
486
440
  }
@@ -493,7 +447,7 @@ class EditNodeOperation {
493
447
  }
494
448
  }
495
449
  reloadRow(queryer, id, options) {
496
- // TODO this isn'talways an ObjectLoader. should throw or figure out a way to get query
450
+ // TODO this isn't always an ObjectLoader. should throw or figure out a way to get query
497
451
  // and run this on its own...
498
452
  const loader = this.options.loadEntOptions.loaderFactory.createLoader(options.context);
499
453
  const opts = loader.getOptions();
@@ -4,6 +4,7 @@ exports.IndexLoaderFactory = void 0;
4
4
  const query_loader_1 = require("./query_loader");
5
5
  // we're keeping this for legacy reasons so as to not break existing callers
6
6
  // and to decouple the change here but all callers can safely be changed here to use QueryLoaderFactory
7
+ // @deprecated use QueryLoaderFactory
7
8
  class IndexLoaderFactory {
8
9
  constructor(options, col, opts) {
9
10
  this.factory = new query_loader_1.QueryLoaderFactory({
package/index.d.ts CHANGED
@@ -11,6 +11,7 @@ declare const query: {
11
11
  Eq: typeof q.Eq;
12
12
  NotEq: typeof q.NotEq;
13
13
  And: typeof q.And;
14
+ AndOptional: typeof q.AndOptional;
14
15
  Or: typeof q.Or;
15
16
  In: typeof q.In;
16
17
  Greater: typeof q.Greater;
package/index.js CHANGED
@@ -109,6 +109,7 @@ const query = {
109
109
  Eq: q.Eq,
110
110
  NotEq: q.NotEq,
111
111
  And: q.And,
112
+ AndOptional: q.AndOptional,
112
113
  Or: q.Or,
113
114
  In: q.In,
114
115
  Greater: q.Greater,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@snowtop/ent",
3
- "version": "0.0.39-alpha4",
3
+ "version": "0.0.39-alpha6",
4
4
  "description": "snowtop ent framework",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",