@pc-nexus/storage 0.5.0-next.23 → 0.5.0-next.25

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.
@@ -12,7 +12,7 @@ export interface LogicalConditionBuilder<Schema = Document, FieldChains extends
12
12
  type LimitComparisonConditionBuilder<Schema = Document, FieldChains extends KeyChains<Schema> = KeyChains<Schema>, CurrentLevel extends CurrentLevelType<Schema> = RootLevelType<Schema>, V = TypeAtKeyChain<Schema, FieldChains>, FieldType = TypeAtKeyChain<Schema, FieldChains>> = FieldType extends number ? Pick<ComparisonConditionBuilder<Schema, FieldChains, CurrentLevel, V>, "eq" | "ne" | "exists" | "gt" | "gte" | "lt" | "lte"> : FieldType extends string ? Pick<ComparisonConditionBuilder<Schema, FieldChains, CurrentLevel, V>, "eq" | "ne" | "exists" | "contains" | "notContains"> : FieldType extends boolean ? Pick<ComparisonConditionBuilder<Schema, FieldChains, CurrentLevel, V>, "eq" | "ne" | "exists"> : FieldType extends any[] ? Pick<ComparisonConditionBuilder<Schema, FieldChains, CurrentLevel, V>, "contains" | "notContains" | "eq" | "ne" | "exists"> : FieldType extends Document ? Pick<ComparisonConditionBuilder<Schema, FieldChains, CurrentLevel, V>, "eq" | "ne" | "exists"> : never;
13
13
  export type ComparisonConditionBuilderReturnType<Schema = Document, FieldChains extends KeyChains<Schema> = KeyChains<Schema>, CurrentLevel extends CurrentLevelType<Schema> = RootLevelType<Schema>, V = TypeAtKeyChain<Schema, FieldChains>> = LogicalConditionBuilder<Schema, never, CurrentLevel, V> & LimitComparisonConditionBuilder<Schema, FieldChains, CurrentLevel, V>;
14
14
  export interface ComparisonConditionBuilder<Schema = Document, FieldChains extends KeyChains<Schema> = KeyChains<Schema>, CurrentLevel extends CurrentLevelType<Schema> = RootLevelType<Schema>, V = TypeAtKeyChain<Schema, FieldChains>> {
15
- eq(value: ValueAlternativeType<V>, options?: EqOptions<QueryOperator.eq>): ComparisonConditionBuilderReturnType<Schema, FieldChains, CurrentLevel, V>;
15
+ eq(value: ValueAlternativeType<V>, options?: EqOptions<QueryOperator.EQ>): ComparisonConditionBuilderReturnType<Schema, FieldChains, CurrentLevel, V>;
16
16
  ne(value: ValueAlternativeType<V>, options?: Omit<EqOptions, "queryOperator">): ComparisonConditionBuilderReturnType<Schema, FieldChains, CurrentLevel, V>;
17
17
  gt(value: ValueAlternativeType<V>, options?: RangeOptions): ComparisonConditionBuilderReturnType<Schema, FieldChains, CurrentLevel, V>;
18
18
  gte(value: ValueAlternativeType<V>, options?: RangeOptions): ComparisonConditionBuilderReturnType<Schema, FieldChains, CurrentLevel, V>;
@@ -26,7 +26,7 @@ export declare class InnerConditionBuilder<Schema = Record<string, any>, FieldCh
26
26
  private updateQuery;
27
27
  field<TFieldChains extends FieldChains>(field: TFieldChains): InnerConditionBuilder<Schema, TFieldChains, CurrentLevel>;
28
28
  resetFieldConditions(): this;
29
- eq<OP extends QueryOperator.eq | QueryOperator.ne | QueryOperator.gt | QueryOperator.gte | QueryOperator.lte | QueryOperator.lt | QueryOperator.contains | QueryOperator.notContains = QueryOperator.eq>(value: ValueAlternativeType<V>, { queryOperator, ...options }?: EqOptions<OP>): this;
29
+ eq<OP extends QueryOperator.EQ | QueryOperator.NE | QueryOperator.GT | QueryOperator.GTE | QueryOperator.LTE | QueryOperator.LT | QueryOperator.Contains | QueryOperator.NotContains = QueryOperator.EQ>(value: ValueAlternativeType<V>, { queryOperator, ...options }?: EqOptions<OP>): this;
30
30
  ne(value: ValueAlternativeType<V>, options?: Omit<EqOptions, "queryOperator">): this;
31
31
  gte(value: ValueAlternativeType<V>, { ...options }?: RangeOptions): this;
32
32
  gt(value: ValueAlternativeType<V>, { ...options }?: RangeOptions): this;
@@ -6,7 +6,7 @@ export class InnerConditionBuilder {
6
6
  baseOptions = { ignoreUndefined: false, keepNaN: false };
7
7
  get currentField() {
8
8
  if (!this._field) {
9
- throw new NexusInnerError(NexusCode.invalidInput, NexusInnerErrorType.storageConditionBuilder, `No field specified for condition`);
9
+ throw new NexusInnerError(NexusCode.InvalidInput, NexusInnerErrorType.StorageConditionBuilder, `No field specified for condition`);
10
10
  }
11
11
  return this._field;
12
12
  }
@@ -76,7 +76,7 @@ export class InnerConditionBuilder {
76
76
  assertAtRootLevel() {
77
77
  if (!this.isAtRootLevel()) {
78
78
  const logicalOp = this.currentLevel[logicalOpSymbol];
79
- throw new NexusInnerError(NexusCode.invalidInput, NexusInnerErrorType.storageConditionBuilder, `there is still remaining "${logicalOp}" logical operator opened`);
79
+ throw new NexusInnerError(NexusCode.InvalidInput, NexusInnerErrorType.StorageConditionBuilder, `there is still remaining "${logicalOp}" logical operator opened`);
80
80
  }
81
81
  }
82
82
  assertAtLogicalLevel(expect) {
@@ -84,11 +84,11 @@ export class InnerConditionBuilder {
84
84
  const isRootLevel = _.isNil(logicalOp);
85
85
  if (expect) {
86
86
  if (logicalOp !== expect) {
87
- throw new NexusInnerError(NexusCode.invalidInput, NexusInnerErrorType.storageConditionBuilder, `there is no "${expect}" logical operator opened`);
87
+ throw new NexusInnerError(NexusCode.InvalidInput, NexusInnerErrorType.StorageConditionBuilder, `there is no "${expect}" logical operator opened`);
88
88
  }
89
89
  }
90
90
  else if (isRootLevel) {
91
- throw new NexusInnerError(NexusCode.invalidInput, NexusInnerErrorType.storageConditionBuilder, `there is no any logical operator opened`);
91
+ throw new NexusInnerError(NexusCode.InvalidInput, NexusInnerErrorType.StorageConditionBuilder, `there is no any logical operator opened`);
92
92
  }
93
93
  }
94
94
  logicalClosure(logicalOp, closure) {
@@ -125,10 +125,10 @@ export class InnerConditionBuilder {
125
125
  return that;
126
126
  }
127
127
  and(closure) {
128
- return this.logicalClosure(LogicalOperator.and, closure);
128
+ return this.logicalClosure(LogicalOperator.And, closure);
129
129
  }
130
130
  or(closure) {
131
- return this.logicalClosure(LogicalOperator.or, closure);
131
+ return this.logicalClosure(LogicalOperator.Or, closure);
132
132
  }
133
133
  shouldReserveValue(value, options) {
134
134
  options = { ...this.baseOptions, ...options };
@@ -186,7 +186,7 @@ export class InnerConditionBuilder {
186
186
  }
187
187
  return this;
188
188
  }
189
- eq(value, { queryOperator = QueryOperator.eq, ...options } = {}) {
189
+ eq(value, { queryOperator = QueryOperator.EQ, ...options } = {}) {
190
190
  const field = this.currentField;
191
191
  if (!this.shouldReserveValue(value, options)) {
192
192
  return this;
@@ -195,35 +195,35 @@ export class InnerConditionBuilder {
195
195
  return this;
196
196
  }
197
197
  ne(value, options = {}) {
198
- return this.eq(value, { ...options, queryOperator: QueryOperator.ne });
198
+ return this.eq(value, { ...options, queryOperator: QueryOperator.NE });
199
199
  }
200
200
  gte(value, { ...options } = {}) {
201
- this.eq(value, { queryOperator: QueryOperator.gte, ...options });
201
+ this.eq(value, { queryOperator: QueryOperator.GTE, ...options });
202
202
  return this;
203
203
  }
204
204
  gt(value, { ...options } = {}) {
205
- this.eq(value, { queryOperator: QueryOperator.gt, ...options });
205
+ this.eq(value, { queryOperator: QueryOperator.GT, ...options });
206
206
  return this;
207
207
  }
208
208
  lte(value, { ...options } = {}) {
209
- this.eq(value, { queryOperator: QueryOperator.lte, ...options });
209
+ this.eq(value, { queryOperator: QueryOperator.LTE, ...options });
210
210
  return this;
211
211
  }
212
212
  lt(value, { ...options } = {}) {
213
- this.eq(value, { queryOperator: QueryOperator.lt, ...options });
213
+ this.eq(value, { queryOperator: QueryOperator.LT, ...options });
214
214
  return this;
215
215
  }
216
216
  contains(value, { ...options } = {}) {
217
- this.eq(value, { queryOperator: QueryOperator.contains, ...options });
217
+ this.eq(value, { queryOperator: QueryOperator.Contains, ...options });
218
218
  return this;
219
219
  }
220
220
  notContains(value, { ...options } = {}) {
221
- this.eq(value, { queryOperator: QueryOperator.notContains, ...options });
221
+ this.eq(value, { queryOperator: QueryOperator.NotContains, ...options });
222
222
  return this;
223
223
  }
224
224
  exists(exists = true) {
225
225
  const field = this.currentField;
226
- this.updateQuery(field, { [QueryOperator.exists]: !!exists });
226
+ this.updateQuery(field, { [QueryOperator.Exists]: !!exists });
227
227
  return this;
228
228
  }
229
229
  }
@@ -5,6 +5,7 @@ import type { DeleteOptions, FindOptions, InsertOptions, UpdateOptions } from "@
5
5
  * @template T Entity type extending Entity
6
6
  */
7
7
  export declare class CustomEntityStorage<T> {
8
+ #private;
8
9
  private readonly entityName;
9
10
  /**
10
11
  * @param entityName Entity name defined in manifest
@@ -24,7 +25,7 @@ export declare class CustomEntityStorage<T> {
24
25
  * @param options Find options, e.g. projection, hint, includes
25
26
  * @returns Matching entities
26
27
  */
27
- find(condition: (conditionBuilder: ConditionBuilder<T>) => void, options?: FindOptions<T>): Promise<T[]>;
28
+ find(condition?: (conditionBuilder: ConditionBuilder<T>) => void, options?: FindOptions<T>): Promise<T[]>;
28
29
  /**
29
30
  * Update all records matching the condition
30
31
  * @param condition Query condition
@@ -38,7 +39,7 @@ export declare class CustomEntityStorage<T> {
38
39
  * @param condition Query condition
39
40
  * @returns Record count
40
41
  */
41
- count(condition: (conditionBuilder: ConditionBuilder<T>) => void): Promise<number>;
42
+ count(condition?: (conditionBuilder: ConditionBuilder<T>) => void): Promise<number>;
42
43
  /**
43
44
  * Delete records matching the condition (soft delete)
44
45
  * @param condition Query condition
@@ -1 +1 @@
1
- {"version":3,"file":"entity-storage.d.ts","sourceRoot":"","sources":["../../../src/lib/ces/entity-storage.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAA0B,MAAM,8BAA8B,CAAC;AACxF,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnG;;;GAGG;AACH,qBAAa,mBAAmB,CAAC,CAAC;IAIX,OAAO,CAAC,QAAQ,CAAC,UAAU;IAH9C;;OAEG;gBACiC,UAAU,EAAE,MAAM;IAEtD;;;;;OAKG;IACU,MAAM,CAAC,KAAK,EAAE,CAAC,EAAE,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,CAAC,EAAE,CAAC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AAO,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,CAAC,EAAE,CAAC;IACzD,MAAM,CAAC,KAAK,EAAE,CAAC,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,CAAC,CAAC;IAalE;;;;;OAKG;IACU,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,gBAAgB,EAAE,gBAAgB,CAAC,CAAC,CAAC,KAAK,IAAI,EAAE,OAAO,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,EAAE,CAAC;IAatH;;;;;;OAMG;IACU,MAAM,CACf,SAAS,EAAE,CAAC,gBAAgB,EAAE,gBAAgB,CAAC,CAAC,CAAC,KAAK,IAAI,EAC1D,KAAK,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,EAClB,OAAO,CAAC,EAAE,aAAa,GACxB,OAAO,CAAC,IAAI,CAAC;IAahB;;;;OAIG;IACU,KAAK,CAAC,SAAS,CAAC,EAAE,CAAC,gBAAgB,EAAE,gBAAgB,CAAC,CAAC,CAAC,KAAK,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC;IAYhG;;;;;OAKG;IACU,MAAM,CAAC,SAAS,EAAE,CAAC,gBAAgB,EAAE,gBAAgB,CAAC,CAAC,CAAC,KAAK,IAAI,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;CAW1H"}
@@ -12,6 +12,15 @@ export class CustomEntityStorage {
12
12
  constructor(entityName) {
13
13
  this.entityName = entityName;
14
14
  }
15
+ #buildCondition(condition, options) {
16
+ let result = {};
17
+ if (condition) {
18
+ const conditionBuilder = ConditionBuilderHelper.create();
19
+ condition(conditionBuilder);
20
+ result = conditionBuilder.done();
21
+ }
22
+ return result;
23
+ }
15
24
  async insert(value, options) {
16
25
  const response = await invoke("storage/ces", "insert", {
17
26
  body: {
@@ -30,9 +39,7 @@ export class CustomEntityStorage {
30
39
  * @returns Matching entities
31
40
  */
32
41
  async find(condition, options) {
33
- const conditionBuilder = ConditionBuilderHelper.create();
34
- condition(conditionBuilder);
35
- const ast = conditionBuilder.done();
42
+ const ast = this.#buildCondition(condition);
36
43
  const response = await invoke("storage/ces", "find", {
37
44
  body: {
38
45
  entity_name: this.entityName,
@@ -51,9 +58,7 @@ export class CustomEntityStorage {
51
58
  * @returns void
52
59
  */
53
60
  async update(condition, value, options) {
54
- const conditionBuilder = ConditionBuilderHelper.create();
55
- condition(conditionBuilder);
56
- const ast = conditionBuilder.done();
61
+ const ast = this.#buildCondition(condition);
57
62
  const response = await invoke("storage/ces", "update", {
58
63
  body: {
59
64
  entity_name: this.entityName,
@@ -70,9 +75,7 @@ export class CustomEntityStorage {
70
75
  * @returns Record count
71
76
  */
72
77
  async count(condition) {
73
- const conditionBuilder = ConditionBuilderHelper.create();
74
- condition(conditionBuilder);
75
- const ast = conditionBuilder.done();
78
+ const ast = this.#buildCondition(condition);
76
79
  const response = await invoke("storage/ces", "count", {
77
80
  body: {
78
81
  entity_name: this.entityName,
@@ -89,9 +92,7 @@ export class CustomEntityStorage {
89
92
  * @returns void
90
93
  */
91
94
  async delete(condition, options) {
92
- const conditionBuilder = ConditionBuilderHelper.create();
93
- condition(conditionBuilder);
94
- const ast = conditionBuilder.done();
95
+ const ast = this.#buildCondition(condition);
95
96
  const response = await invoke("storage/ces", "delete", {
96
97
  body: {
97
98
  entity_name: this.entityName,
package/lib/nos/type.d.ts CHANGED
@@ -17,4 +17,7 @@ export interface ObjectMetadata {
17
17
  size: number;
18
18
  created_at?: number;
19
19
  }
20
+ export type GenerateUploadUrlPayload = Pick<UploadUrlBody, "size" | "checksum" | "checksum_type">;
21
+ export type PresignedURLToObjectMetadataMap = Record<string, UploadUrlBody>;
22
+ export type PresignedURLToObjectKeyMap = Record<string, string>;
20
23
  //# sourceMappingURL=type.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../../src/lib/nos/type.ts"],"names":[],"mappings":"AA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MAAM,GAAG,UAAU,GAAG,eAAe,CAAC,CAAC;AAElG,MAAM,MAAM,+BAA+B,GAAG,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;AAE5E,MAAM,MAAM,0BAA0B,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pc-nexus/storage",
3
- "version": "0.5.0-next.23",
3
+ "version": "0.5.0-next.25",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -30,7 +30,7 @@
30
30
  },
31
31
  "type": "module",
32
32
  "dependencies": {
33
- "@pc-nexus/internal": "0.5.0-next.23",
33
+ "@pc-nexus/internal": "0.5.0-next.25",
34
34
  "lodash": "^4.17.21"
35
35
  },
36
36
  "devDependencies": {},