@pc-nexus/storage 0.0.1-next.1 → 0.0.1-next.2

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.
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # Nexus Storage API
2
+
3
+ API methods exposed during runtime in Nexus apps.
package/index.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ export * from "./lib/ces/type.js";
2
+ export * from "./lib/ces/condition-builder/index.js";
3
+ export * from "./lib/ces/index.js";
4
+ export * from "./lib/kvs/index.js";
5
+ export * from "./lib/os/index.js";
6
+ //# sourceMappingURL=index.d.ts.map
package/index.d.ts.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,sCAAsC,CAAC;AACrD,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC"}
package/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from "./lib/ces/type.js";
2
+ export * from "./lib/ces/condition-builder/index.js";
2
3
  export * from "./lib/ces/index.js";
3
4
  export * from "./lib/kvs/index.js";
4
5
  export * from "./lib/os/index.js";
@@ -0,0 +1,45 @@
1
+ import type { CurrentLevelType, EqOptions, InOptions, KeyChains, LogicalLevelType, Query, Condition, ConditionBuilderOptions, QueryOperatorCondition$in, RangeOptions, RootLevelType, TypeAtKeyChain, ValueAlternativeType } from "./type.js";
2
+ import { QueryOperator } from "./type.js";
3
+ export declare class ConditionBuilder<Schema = any, FieldChain extends KeyChains<Schema> = never, CurrentLevel extends CurrentLevelType<Schema> = RootLevelType<Schema>, FieldChains extends KeyChains<Schema> = KeyChains<Schema>, V = TypeAtKeyChain<Schema, FieldChain>> {
4
+ private _field;
5
+ private baseOptions;
6
+ private get currentField();
7
+ private set currentField(value);
8
+ private root;
9
+ private currentLevel;
10
+ static create<Schema>(options?: ConditionBuilderOptions): ConditionBuilder<Schema>;
11
+ constructor(options?: ConditionBuilderOptions);
12
+ done(reset?: boolean): Condition;
13
+ reset(this: ConditionBuilder<Schema, never, CurrentLevelType<Schema>>): ConditionBuilder<Schema>;
14
+ private getRawQuery;
15
+ merge(queryOrBuilder: Query<Schema> | ConditionBuilder<Schema, any, CurrentLevelType<Schema>>, override?: CurrentLevel extends RootLevelType<Schema> ? boolean : never): this;
16
+ clone(): this;
17
+ private isAtRootLevel;
18
+ private assertAtRootLevel;
19
+ private assertAtLogicalLevel;
20
+ private logicalClosure;
21
+ private logicalOpen;
22
+ private logicalClose;
23
+ and(closure: (andBuilder: ConditionBuilder<Schema, never, LogicalLevelType<Schema>>) => void): ConditionBuilder<Schema, FieldChain, CurrentLevel, FieldChains, V>;
24
+ or(closure: (orBuilder: ConditionBuilder<Schema, never, LogicalLevelType<Schema>>) => void): ConditionBuilder<Schema, FieldChain, CurrentLevel, FieldChains, V>;
25
+ private shouldReserveValue;
26
+ private updateQuery;
27
+ field<FieldChain extends FieldChains>(field: FieldChain): ConditionBuilder<Schema, FieldChain, CurrentLevel>;
28
+ resetFieldConditions(): this;
29
+ eq<OP extends QueryOperator.eq | QueryOperator.ne | QueryOperator.gt | QueryOperator.gte | QueryOperator.lte | QueryOperator.lt = QueryOperator.eq>(value: ValueAlternativeType<V>, { queryOperator, ...options }?: EqOptions<OP>): this;
30
+ ne(value: ValueAlternativeType<V>, options?: Omit<EqOptions, "queryOperator">): this;
31
+ range(values: Partial<Record<"gte" | "lte" | "gt" | "lt", ValueAlternativeType<V>>>, { ...options }?: RangeOptions): this;
32
+ gte(value: ValueAlternativeType<V>, { ...options }?: RangeOptions): this;
33
+ gt(value: ValueAlternativeType<V>, { ...options }?: RangeOptions): this;
34
+ lte(value: ValueAlternativeType<V>, { ...options }?: RangeOptions): this;
35
+ lt(value: ValueAlternativeType<V>, { ...options }?: RangeOptions): this;
36
+ in(value: QueryOperatorCondition$in<V>, { queryOperator, ...options }?: InOptions): this;
37
+ nin(value: QueryOperatorCondition$in<V>, options?: Omit<InOptions, "queryOperator">): this;
38
+ exists(exists?: boolean): this;
39
+ private toAST;
40
+ private mapLogicalKey;
41
+ private convertTopLevelObject;
42
+ private convertFieldEntry;
43
+ }
44
+ export type ConditionBuilderApi<Schema = any> = Omit<ConditionBuilder<Schema>, "done">;
45
+ //# sourceMappingURL=condition-builder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"condition-builder.d.ts","sourceRoot":"","sources":["../../../../src/lib/ces/condition-builder/condition-builder.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACR,gBAAgB,EAChB,SAAS,EACT,SAAS,EACT,SAAS,EAGT,gBAAgB,EAChB,KAAK,EACL,SAAS,EAIT,uBAAuB,EAEvB,yBAAyB,EAEzB,YAAY,EACZ,aAAa,EACb,cAAc,EACd,oBAAoB,EACvB,MAAM,WAAW,CAAC;AACnB,OAAO,EAAuD,aAAa,EAAE,MAAM,WAAW,CAAC;AAG/F,qBAAa,gBAAgB,CACzB,MAAM,GAAG,GAAG,EACZ,UAAU,SAAS,SAAS,CAAC,MAAM,CAAC,GAAG,KAAK,EAC5C,YAAY,SAAS,gBAAgB,CAAC,MAAM,CAAC,GAAG,aAAa,CAAC,MAAM,CAAC,EACrE,WAAW,SAAS,SAAS,CAAC,MAAM,CAAC,GAAG,SAAS,CAAC,MAAM,CAAC,EACzD,CAAC,GAAG,cAAc,CAAC,MAAM,EAAE,UAAU,CAAC;IAEtC,OAAO,CAAC,MAAM,CAA0B;IAExC,OAAO,CAAC,WAAW,CAAuE;IAE1F,OAAO,KAAK,YAAY,GAKvB;IAED,OAAO,KAAK,YAAY,QAEvB;IAED,OAAO,CAAC,IAAI,CAAyB;IACrC,OAAO,CAAC,YAAY,CAAgB;WAEtB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,uBAAuB,GAAG,gBAAgB,CAAC,MAAM,CAAC;gBAItE,OAAO,GAAE,uBAA4B;I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B/G,GAAG,CAAC,KAAK,EAAE,yBAAyB,CAAC,CAAC,CAAC,EAAE,OAAO,GAAE,IAAI,CAAC,SAAS,EAAE,eAAe,CAAM,GAAG,IAAI;IAI9F,MAAM,CAAC,MAAM,UAAO,GAAG,IAAI;IAMlC,OAAO,CAAC,KAAK;IA6Bb,OAAO,CAAC,aAAa;IAIrB,OAAO,CAAC,qBAAqB;IAqB7B,OAAO,CAAC,iBAAiB;CAwB5B;AAED,MAAM,MAAM,mBAAmB,CAAC,MAAM,GAAG,GAAG,IAAI,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,CAAC"}
@@ -0,0 +1,333 @@
1
+ import { LogicalOperator, logicalOpSymbol, parentLevelSymbol, QueryOperator } from "./type.js";
2
+ import _ from "lodash";
3
+ export class ConditionBuilder {
4
+ _field;
5
+ baseOptions = { ignoreUndefined: false, keepNaN: false };
6
+ get currentField() {
7
+ if (!this._field) {
8
+ throw new Error("field not set. please set by field()");
9
+ }
10
+ return this._field;
11
+ }
12
+ set currentField(field) {
13
+ this._field = field;
14
+ }
15
+ root;
16
+ currentLevel;
17
+ static create(options) {
18
+ return new ConditionBuilder(options);
19
+ }
20
+ constructor(options = {}) {
21
+ Object.assign(this.baseOptions, options);
22
+ this.reset();
23
+ }
24
+ done(reset = true) {
25
+ this.assertAtRootLevel();
26
+ const ast = this.toAST(this.root);
27
+ if (reset) {
28
+ this.reset();
29
+ }
30
+ return ast;
31
+ }
32
+ reset() {
33
+ const root = {};
34
+ this.currentLevel = this.root = root;
35
+ this.currentField = undefined;
36
+ return this;
37
+ }
38
+ getRawQuery(clone = true) {
39
+ return clone ? _.cloneDeep(this.root) : this.root;
40
+ }
41
+ merge(queryOrBuilder, override) {
42
+ const query = queryOrBuilder instanceof ConditionBuilder ? queryOrBuilder.getRawQuery(true) : _.cloneDeep(queryOrBuilder);
43
+ if (this.isAtRootLevel()) {
44
+ const { root } = this;
45
+ const mergeArgs = override ? [root, query] : [query, root];
46
+ this.currentLevel = this.root = _.mergeWith(...mergeArgs, (targetValue, srcValue, key) => {
47
+ if (key in LogicalOperator) {
48
+ return (targetValue || []).concat(srcValue || []);
49
+ }
50
+ else if (key in QueryOperator) {
51
+ return srcValue;
52
+ }
53
+ });
54
+ }
55
+ else {
56
+ this.assertAtLogicalLevel();
57
+ this.currentLevel.push(query);
58
+ }
59
+ return this;
60
+ }
61
+ clone() {
62
+ return _.cloneDeep(this);
63
+ }
64
+ isAtRootLevel() {
65
+ const isRootLevel = _.isNil(this.currentLevel[logicalOpSymbol]);
66
+ return isRootLevel;
67
+ }
68
+ assertAtRootLevel() {
69
+ if (!this.isAtRootLevel()) {
70
+ const logicalOp = this.currentLevel[logicalOpSymbol];
71
+ throw new Error(`there is still remaining "${logicalOp}" logical operator opened`);
72
+ }
73
+ }
74
+ assertAtLogicalLevel(expect) {
75
+ const logicalOp = this.currentLevel[logicalOpSymbol];
76
+ const isRootLevel = _.isNil(logicalOp);
77
+ if (expect) {
78
+ if (logicalOp !== expect) {
79
+ throw new Error(`there is no "${expect}" logical operator opened`);
80
+ }
81
+ }
82
+ else if (isRootLevel) {
83
+ throw new Error(`there is no any logical operator opened`);
84
+ }
85
+ }
86
+ logicalClosure(logicalOp, closure) {
87
+ const logicalQB = new ConditionBuilder(this.baseOptions).logicalOpen(logicalOp);
88
+ closure(logicalQB);
89
+ logicalQB.logicalClose(logicalOp);
90
+ if (this.isAtRootLevel()) {
91
+ this.merge(logicalQB.getRawQuery(true), true);
92
+ }
93
+ else {
94
+ this.merge(logicalQB.getRawQuery(true));
95
+ }
96
+ return this;
97
+ }
98
+ logicalOpen(logicalOp) {
99
+ const parentLevel = this.currentLevel;
100
+ const currentLevel = [];
101
+ currentLevel[logicalOpSymbol] = logicalOp;
102
+ currentLevel[parentLevelSymbol] = parentLevel;
103
+ const that = this;
104
+ that.currentLevel = currentLevel;
105
+ return that;
106
+ }
107
+ logicalClose(logicalOp) {
108
+ this.assertAtLogicalLevel(logicalOp);
109
+ const currentLevel = this.currentLevel;
110
+ const that = this;
111
+ that.currentLevel = currentLevel[parentLevelSymbol];
112
+ const currentLogicalOp = currentLevel[logicalOpSymbol];
113
+ const logicalCondition = [...currentLevel];
114
+ if (!_.isEmpty(logicalCondition)) {
115
+ that.updateQuery(currentLogicalOp, logicalCondition);
116
+ }
117
+ return that;
118
+ }
119
+ and(closure) {
120
+ return this.logicalClosure(LogicalOperator.and, closure);
121
+ }
122
+ or(closure) {
123
+ return this.logicalClosure(LogicalOperator.or, closure);
124
+ }
125
+ shouldReserveValue(value, options) {
126
+ options = { ...this.baseOptions, ...options };
127
+ if (options.ignoreUndefined && value === undefined) {
128
+ return false;
129
+ }
130
+ if (!options.keepNaN && Number.isNaN(value)) {
131
+ return false;
132
+ }
133
+ return true;
134
+ }
135
+ updateQuery(field, condition) {
136
+ if (this.isAtRootLevel()) {
137
+ if (field in LogicalOperator && _.isArray(condition)) {
138
+ const currentLevel = this.currentLevel;
139
+ const logicalOp = field;
140
+ const c = condition;
141
+ currentLevel[logicalOp] = [...(currentLevel[logicalOp] || []), ...c];
142
+ }
143
+ else {
144
+ const currentLevel = this.currentLevel;
145
+ const f = field;
146
+ const c = condition;
147
+ if (_.isPlainObject(currentLevel[f])) {
148
+ Object.assign(currentLevel[f], c);
149
+ }
150
+ else {
151
+ currentLevel[f] = c;
152
+ }
153
+ }
154
+ }
155
+ else {
156
+ const currentLevel = this.currentLevel;
157
+ const entry = { [field]: condition };
158
+ currentLevel.push(entry);
159
+ }
160
+ }
161
+ field(field) {
162
+ this.currentField = field;
163
+ return this;
164
+ }
165
+ resetFieldConditions() {
166
+ if (this.isAtRootLevel()) {
167
+ delete this.currentLevel[this.currentField];
168
+ }
169
+ else {
170
+ const currentLevel = this.currentLevel;
171
+ let i = currentLevel.length;
172
+ while (--i >= 0) {
173
+ const ele = currentLevel[i];
174
+ if (ele && this.currentField in ele) {
175
+ currentLevel.splice(i, 1);
176
+ }
177
+ }
178
+ }
179
+ return this;
180
+ }
181
+ eq(value, { queryOperator = QueryOperator.eq, ...options } = {}) {
182
+ const field = this.currentField;
183
+ if (!this.shouldReserveValue(value, options)) {
184
+ return this;
185
+ }
186
+ this.updateQuery(field, { [queryOperator]: value });
187
+ return this;
188
+ }
189
+ ne(value, options = {}) {
190
+ return this.eq(value, { ...options, queryOperator: QueryOperator.ne });
191
+ }
192
+ range(values, { ...options } = {}) {
193
+ const condition = {};
194
+ const setCondition = (key, value) => {
195
+ if (value !== undefined && this.shouldReserveValue(value, options)) {
196
+ condition[key] = value;
197
+ }
198
+ };
199
+ setCondition("gte", values.gte);
200
+ setCondition("gt", values.gt);
201
+ setCondition("lte", values.lte);
202
+ setCondition("lt", values.lt);
203
+ if (!_.isEmpty(condition)) {
204
+ this.updateQuery(this.currentField, condition);
205
+ }
206
+ return this;
207
+ }
208
+ gte(value, { ...options } = {}) {
209
+ this.eq(value, { queryOperator: QueryOperator.gte, ...options });
210
+ return this;
211
+ }
212
+ gt(value, { ...options } = {}) {
213
+ this.eq(value, { queryOperator: QueryOperator.gt, ...options });
214
+ return this;
215
+ }
216
+ lte(value, { ...options } = {}) {
217
+ this.eq(value, { queryOperator: QueryOperator.lte, ...options });
218
+ return this;
219
+ }
220
+ lt(value, { ...options } = {}) {
221
+ this.eq(value, { queryOperator: QueryOperator.lt, ...options });
222
+ return this;
223
+ }
224
+ in(value, { queryOperator = QueryOperator.in, ...options } = {}) {
225
+ const field = this.currentField;
226
+ if (value === undefined) {
227
+ if (this.shouldReserveValue(value, options)) {
228
+ throw new Error(`${queryOperator} needs an array`);
229
+ }
230
+ else {
231
+ return this;
232
+ }
233
+ }
234
+ else if (!_.isArray(value)) {
235
+ throw new Error(`${queryOperator} needs an array`);
236
+ }
237
+ if (options.ignoreEmpty && _.isEmpty(value)) {
238
+ return this;
239
+ }
240
+ this.updateQuery(field, {
241
+ [queryOperator]: value.filter((ele) => this.shouldReserveValue(ele, options)),
242
+ });
243
+ return this;
244
+ }
245
+ nin(value, options = {}) {
246
+ return this.in(value, { ...options, queryOperator: QueryOperator.nin });
247
+ }
248
+ exists(exists = true) {
249
+ const field = this.currentField;
250
+ this.updateQuery(field, { [QueryOperator.exists]: !!exists });
251
+ return this;
252
+ }
253
+ toAST(query) {
254
+ const nodes = [];
255
+ const entries = Object.entries(query);
256
+ for (const [key, value] of entries) {
257
+ if (key in LogicalOperator) {
258
+ const group = {
259
+ kind: "group",
260
+ op: this.mapLogicalKey(key),
261
+ nodes: [],
262
+ };
263
+ const arr = value;
264
+ for (const ele of arr) {
265
+ const subNodes = this.convertTopLevelObject(ele);
266
+ group.nodes.push(...subNodes);
267
+ }
268
+ if (group.nodes.length > 0) {
269
+ nodes.push(group);
270
+ }
271
+ }
272
+ else {
273
+ const fieldNodes = this.convertFieldEntry(key, value);
274
+ if (fieldNodes.length > 0)
275
+ nodes.push(...fieldNodes);
276
+ }
277
+ }
278
+ if (nodes.length === 1) {
279
+ return nodes[0];
280
+ }
281
+ return { kind: "group", op: LogicalOperator.and, nodes };
282
+ }
283
+ mapLogicalKey(key) {
284
+ return key;
285
+ }
286
+ convertTopLevelObject(obj) {
287
+ const out = [];
288
+ for (const [k, v] of Object.entries(obj)) {
289
+ if (k in LogicalOperator) {
290
+ const group = {
291
+ kind: "group",
292
+ op: this.mapLogicalKey(k),
293
+ nodes: [],
294
+ };
295
+ for (const ele of v) {
296
+ group.nodes.push(...this.convertTopLevelObject(ele));
297
+ }
298
+ out.push(group);
299
+ }
300
+ else {
301
+ const fieldNodes = this.convertFieldEntry(k, v);
302
+ out.push(...fieldNodes);
303
+ }
304
+ }
305
+ return out;
306
+ }
307
+ convertFieldEntry(field, condition) {
308
+ const out = [];
309
+ if (_.isPlainObject(condition) && !_.isRegExp(condition)) {
310
+ const supported = {
311
+ [QueryOperator.eq]: true,
312
+ [QueryOperator.ne]: true,
313
+ [QueryOperator.gt]: true,
314
+ [QueryOperator.gte]: true,
315
+ [QueryOperator.lt]: true,
316
+ [QueryOperator.lte]: true,
317
+ [QueryOperator.in]: true,
318
+ [QueryOperator.nin]: true,
319
+ [QueryOperator.exists]: true,
320
+ };
321
+ for (const [k, val] of Object.entries(condition)) {
322
+ const op = k;
323
+ if (!supported[op])
324
+ continue;
325
+ out.push({ kind: "field", field, op, value: op === QueryOperator.exists ? !!val : val });
326
+ }
327
+ }
328
+ else {
329
+ out.push({ kind: "field", field, op: QueryOperator.eq, value: condition });
330
+ }
331
+ return out;
332
+ }
333
+ }
@@ -0,0 +1,3 @@
1
+ export { ConditionBuilder, type ConditionBuilderApi } from "./condition-builder.js";
2
+ export * from "./type.js";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/lib/ces/condition-builder/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,KAAK,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AACpF,cAAc,WAAW,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { ConditionBuilder } from "./condition-builder.js";
2
+ export * from "./type.js";
@@ -0,0 +1,81 @@
1
+ export type NestedPathsIterator<Type, WalkedType> = Required<NonNullable<Type>> extends Required<WalkedType> ? [] | (string | (WalkedType extends readonly unknown[] ? ArrayIndexes : never))[] : Type extends (...args: any[]) => any ? never : Type extends string | number | boolean | Date | RegExp | Buffer | Uint8Array | {
2
+ _bsontype: string;
3
+ } ? [] : Type extends readonly (infer EleType)[] ? [ArrayIndexes<Type>, ...NestedPathsIterator<EleType, WalkedType | Type>] | [...NestedPathsIterator<EleType, WalkedType | Type>] : Type extends object ? {
4
+ [Key in Extract<keyof Type, string>]: [Key, ...NestedPathsIterator<Type[Key], WalkedType | Type>];
5
+ }[Extract<keyof Type, string>] | [] : [];
6
+ export type NestedPaths<Type> = NestedPathsIterator<Type, never>;
7
+ export type KeyChains<T> = Exclude<NestedPaths<T>, []> extends infer Paths ? Paths extends readonly (string | number)[] ? Paths extends readonly [infer First, ...infer Rest] ? First extends string | number ? Rest extends readonly (string | number)[] ? `${First}${Rest extends readonly [] ? "" : "."}${KeyChainsJoin<Rest>}` : never : never : "" : never : never;
8
+ type KeyChainsJoin<Paths extends readonly (string | number)[]> = Paths extends readonly [infer First, ...infer Rest] ? First extends string | number ? Rest extends readonly (string | number)[] ? `${First}${Rest extends readonly [] ? "" : "."}${KeyChainsJoin<Rest>}` : never : never : "";
9
+ export type IntegerListAsc<Len extends number = 10, Result extends readonly number[] = []> = Result["length"] extends Len ? Result : IntegerListAsc<Len, [...Result, Result["length"]]>;
10
+ export type Integer = IntegerListAsc[number];
11
+ export type ArrayIndexes<Array extends readonly any[] = readonly any[]> = number extends any[]["length"] ? Integer : any[] extends [infer Ele, ...infer RestArray] ? ArrayIndexes<RestArray> | RestArray["length"] : never;
12
+ export type Document = Record<string, any>;
13
+ export declare const parentLevelSymbol: unique symbol;
14
+ export declare const logicalOpSymbol: unique symbol;
15
+ export declare enum QueryOperator {
16
+ eq = "eq",
17
+ ne = "ne",
18
+ gt = "gt",
19
+ gte = "gte",
20
+ lt = "lt",
21
+ lte = "lte",
22
+ in = "in",
23
+ nin = "nin",
24
+ exists = "exists"
25
+ }
26
+ export type MaybeRegExp<T> = T extends string ? RegExp | T : T;
27
+ export type ValueAlternativeType<V> = V extends (infer E)[] ? MaybeRegExp<E> | V : MaybeRegExp<V>;
28
+ export type QueryOperatorCondition$in<V> = readonly ValueAlternativeType<V>[];
29
+ export type QueryOperatorConditions<V> = Partial<Record<QueryOperator.eq | QueryOperator.ne | QueryOperator.gt | QueryOperator.gte | QueryOperator.lt | QueryOperator.lte, ValueAlternativeType<V>>> & Partial<Record<QueryOperator.in | QueryOperator.nin, QueryOperatorCondition$in<V>>> & {
30
+ [QueryOperator.exists]?: boolean;
31
+ };
32
+ export type QueryConditions<Schema> = {
33
+ [KeyChain in KeyChains<Schema>]?: QueryOperatorConditions<TypeAtKeyChain<Schema, KeyChain>> | ValueAlternativeType<TypeAtKeyChain<Schema, KeyChain>>;
34
+ };
35
+ export declare enum LogicalOperator {
36
+ and = "and",
37
+ or = "or"
38
+ }
39
+ export type LogicalCondition<Schema> = (QueryConditions<Schema> | LogicalConditions<Schema>)[];
40
+ export type LogicalConditions<Schema> = Record<LogicalOperator, LogicalCondition<Schema>>;
41
+ export type Query<Schema> = QueryConditions<Schema> & LogicalConditions<Schema>;
42
+ export type LogicalLevelType<Schema> = {
43
+ [logicalOpSymbol]: LogicalOperator;
44
+ [parentLevelSymbol]: CurrentLevelType<Schema>;
45
+ } & LogicalCondition<Schema>;
46
+ export type RootLevelType<Schema> = {
47
+ [logicalOpSymbol]?: never;
48
+ } & Query<Schema>;
49
+ export type CurrentLevelType<Schema> = RootLevelType<Schema> | LogicalLevelType<Schema>;
50
+ export interface ConditionBuilderOptions {
51
+ ignoreUndefined?: boolean;
52
+ keepNaN?: boolean;
53
+ }
54
+ export type RangeOptions = ConditionBuilderOptions;
55
+ export type EqOptions<OP extends QueryOperator = QueryOperator.eq> = {
56
+ queryOperator?: OP;
57
+ } & ConditionBuilderOptions;
58
+ export type InOptions = {
59
+ queryOperator?: QueryOperator.in | QueryOperator.nin;
60
+ ignoreEmpty?: boolean;
61
+ } & ConditionBuilderOptions;
62
+ export type TryConvertToInt<T extends string> = T extends `${Integer}` ? IntegerListAsc[T] : T extends `${number}` ? number : T;
63
+ export type TypeAtKey<T extends Document | readonly unknown[], K> = T extends readonly unknown[] ? K extends number ? T[K] : never : K extends keyof T ? T[K] : never;
64
+ export type ParseKeyChainToPath<KeyChain extends string, Separator extends string = "."> = KeyChain extends `${infer Key}${Separator}${infer Rest}` ? [TryConvertToInt<Key>, ...ParseKeyChainToPath<Rest>] : [TryConvertToInt<KeyChain>];
65
+ export type TypeAtKeyPath<T, KeyPath> = KeyPath extends (string | ArrayIndexes)[] ? KeyPath extends [infer Key, ...infer RestKeyPath] ? T extends readonly (infer E)[] ? Key extends ArrayIndexes<T> ? TypeAtKeyPath<TypeAtKey<T, Key>, RestKeyPath> : TypeAtKeyPath<E, KeyPath> : T extends Document ? TypeAtKeyPath<TypeAtKey<T, Key>, RestKeyPath> : never : T : never;
66
+ export type TypeAtKeyChain<T, KeyChain extends string, Separator extends string = "."> = TypeAtKeyPath<T, ParseKeyChainToPath<KeyChain, Separator>>;
67
+ export interface ConditionFieldNode {
68
+ kind: "field";
69
+ field: string;
70
+ op: QueryOperator;
71
+ value: any;
72
+ }
73
+ export interface ConditionGroupNode {
74
+ kind: "group";
75
+ op: LogicalOperator;
76
+ nodes: ConditionNode[];
77
+ }
78
+ export type ConditionNode = ConditionFieldNode | ConditionGroupNode;
79
+ export type Condition = ConditionNode;
80
+ export {};
81
+ //# sourceMappingURL=type.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../../../src/lib/ces/condition-builder/type.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,mBAAmB,CAAC,IAAI,EAAE,UAAU,IAC5C,QAAQ,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,SAAS,QAAQ,CAAC,UAAU,CAAC,GAClD,EAAE,GAAG,CAAC,MAAM,GAAG,CAAC,UAAU,SAAS,SAAS,OAAO,EAAE,GAAG,YAAY,GAAG,KAAK,CAAC,CAAC,EAAE,GAChF,IAAI,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,GAClC,KAAK,GACL,IAAI,SACI,MAAM,GACN,MAAM,GACN,OAAO,GACP,IAAI,GACJ,MAAM,GACN,MAAM,GACN,UAAU,GACV;IACI,SAAS,EAAE,MAAM,CAAC;CACrB,GACP,EAAE,GACF,IAAI,SAAS,SAAS,CAAC,MAAM,OAAO,CAAC,EAAE,GAE/B,CAAC,YAAY,CAAC,IAAI,CAAC,EAAE,GAAG,mBAAmB,CAAC,OAAO,EAAE,UAAU,GAAG,IAAI,CAAC,CAAC,GACxE,CAAC,GAAG,mBAAmB,CAAC,OAAO,EAAE,UAAU,GAAG,IAAI,CAAC,CAAC,GAC1D,IAA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,MAAM,WAAW,kBAAkB;IAC/B,IAAI,EAAE,OAAO,CAAC;IACd,EAAE,EAAE,eAAe,CAAC;IACpB,KAAK,EAAE,aAAa,EAAE,CAAC;CAC1B;AAED,MAAM,MAAM,aAAa,GAAG,kBAAkB,GAAG,kBAAkB,CAAC;AAEpE,MAAM,MAAM,SAAS,GAAG,aAAa,CAAC"}
@@ -0,0 +1,19 @@
1
+ export const parentLevelSymbol = Symbol("parentLevel");
2
+ export const logicalOpSymbol = Symbol("logicalOp");
3
+ export var QueryOperator;
4
+ (function (QueryOperator) {
5
+ QueryOperator["eq"] = "eq";
6
+ QueryOperator["ne"] = "ne";
7
+ QueryOperator["gt"] = "gt";
8
+ QueryOperator["gte"] = "gte";
9
+ QueryOperator["lt"] = "lt";
10
+ QueryOperator["lte"] = "lte";
11
+ QueryOperator["in"] = "in";
12
+ QueryOperator["nin"] = "nin";
13
+ QueryOperator["exists"] = "exists";
14
+ })(QueryOperator || (QueryOperator = {}));
15
+ export var LogicalOperator;
16
+ (function (LogicalOperator) {
17
+ LogicalOperator["and"] = "and";
18
+ LogicalOperator["or"] = "or";
19
+ })(LogicalOperator || (LogicalOperator = {}));
@@ -0,0 +1,50 @@
1
+ import { type ConditionBuilderApi } from "./condition-builder/condition-builder.js";
2
+ import type { InsertOptions, FindOptions, UpdateOptions, DeleteOptions } from "./type.js";
3
+ /**
4
+ * Entity storage API implementation, provides CRUD operations for entities via CES hook
5
+ * @template T Entity type extending Entity
6
+ */
7
+ export declare class CustomEntityStorage<T> {
8
+ private readonly entityName;
9
+ /**
10
+ * @param entityName Entity name defined in manifest
11
+ */
12
+ constructor(entityName: string);
13
+ /**
14
+ * Insert records
15
+ * @param value Entity or entities to insert
16
+ * @param options Insert options, e.g. ordered for insert order
17
+ * @returns Inserted entity or entities
18
+ */
19
+ insert(value: T[], options?: InsertOptions): Promise<T[]>;
20
+ insert(value: T, options?: InsertOptions): Promise<T>;
21
+ /**
22
+ * Find records matching the condition
23
+ * @param condition Query condition
24
+ * @param options Find options, e.g. projection, hint, includes
25
+ * @returns Matching entities
26
+ */
27
+ find(condition: (conditionBuilder: ConditionBuilderApi<T>) => void, options?: FindOptions): Promise<T[]>;
28
+ /**
29
+ * Update all records matching the condition
30
+ * @param condition Query condition
31
+ * @param value Update content, if value is null or undefined, it will clear the record property
32
+ * @param options Update options, e.g. returnValue, upsert, hint
33
+ * @returns void
34
+ */
35
+ update(condition: (conditionBuilder: ConditionBuilderApi<T>) => void, value?: Partial<T>, options?: UpdateOptions): Promise<void>;
36
+ /**
37
+ * Count records matching the condition
38
+ * @param condition Query condition
39
+ * @returns Record count
40
+ */
41
+ count(condition: (conditionBuilder: ConditionBuilderApi<T>) => void): Promise<number>;
42
+ /**
43
+ * Delete records matching the condition (soft delete)
44
+ * @param condition Query condition
45
+ * @param options Delete options, e.g. justOne
46
+ * @returns void
47
+ */
48
+ delete(condition: (conditionBuilder: ConditionBuilderApi<T>) => void, options?: DeleteOptions): Promise<void>;
49
+ }
50
+ //# sourceMappingURL=entity-storage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entity-storage.d.ts","sourceRoot":"","sources":["../../../src/lib/ces/entity-storage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,KAAK,mBAAmB,EAAE,MAAM,0CAA0C,CAAC;AACtG,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAG1F;;;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;IACzD,MAAM,CAAC,KAAK,EAAE,CAAC,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,CAAC,CAAC;IAOlE;;;;;OAKG;IACU,IAAI,CAAC,SAAS,EAAE,CAAC,gBAAgB,EAAE,mBAAmB,CAAC,CAAC,CAAC,KAAK,IAAI,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,CAAC,EAAE,CAAC;IASrH;;;;;;OAMG;IACU,MAAM,CACf,SAAS,EAAE,CAAC,gBAAgB,EAAE,mBAAmB,CAAC,CAAC,CAAC,KAAK,IAAI,EAC7D,KAAK,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,EAClB,OAAO,CAAC,EAAE,aAAa,GACxB,OAAO,CAAC,IAAI,CAAC;IAOhB;;;;OAIG;IACU,KAAK,CAAC,SAAS,EAAE,CAAC,gBAAgB,EAAE,mBAAmB,CAAC,CAAC,CAAC,KAAK,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC;IASlG;;;;;OAKG;IACU,MAAM,CAAC,SAAS,EAAE,CAAC,gBAAgB,EAAE,mBAAmB,CAAC,CAAC,CAAC,KAAK,IAAI,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;CAM7H"}
@@ -0,0 +1,72 @@
1
+ import { ConditionBuilder } from "./condition-builder/condition-builder.js";
2
+ import { hook } from "@pc-nexus/core";
3
+ /**
4
+ * Entity storage API implementation, provides CRUD operations for entities via CES hook
5
+ * @template T Entity type extending Entity
6
+ */
7
+ export class CustomEntityStorage {
8
+ entityName;
9
+ /**
10
+ * @param entityName Entity name defined in manifest
11
+ */
12
+ constructor(entityName) {
13
+ this.entityName = entityName;
14
+ }
15
+ async insert(value, options) {
16
+ const response = await hook("storage/ces").insert(this.entityName, value, options);
17
+ const result = await response.json();
18
+ return result;
19
+ }
20
+ /**
21
+ * Find records matching the condition
22
+ * @param condition Query condition
23
+ * @param options Find options, e.g. projection, hint, includes
24
+ * @returns Matching entities
25
+ */
26
+ async find(condition, options) {
27
+ const conditionBuilder = new ConditionBuilder();
28
+ condition(conditionBuilder);
29
+ const ast = conditionBuilder.done();
30
+ const response = await hook("storage/ces").find(this.entityName, ast, options);
31
+ const result = await response.json();
32
+ return result;
33
+ }
34
+ /**
35
+ * Update all records matching the condition
36
+ * @param condition Query condition
37
+ * @param value Update content, if value is null or undefined, it will clear the record property
38
+ * @param options Update options, e.g. returnValue, upsert, hint
39
+ * @returns void
40
+ */
41
+ async update(condition, value, options) {
42
+ const conditionBuilder = new ConditionBuilder();
43
+ condition(conditionBuilder);
44
+ const ast = conditionBuilder.done();
45
+ await hook("storage/ces").update(this.entityName, ast, value, options);
46
+ }
47
+ /**
48
+ * Count records matching the condition
49
+ * @param condition Query condition
50
+ * @returns Record count
51
+ */
52
+ async count(condition) {
53
+ const conditionBuilder = new ConditionBuilder();
54
+ condition(conditionBuilder);
55
+ const ast = conditionBuilder.done();
56
+ const response = await hook("storage/ces").count(this.entityName, ast);
57
+ const result = await response.json();
58
+ return result;
59
+ }
60
+ /**
61
+ * Delete records matching the condition (soft delete)
62
+ * @param condition Query condition
63
+ * @param options Delete options, e.g. justOne
64
+ * @returns void
65
+ */
66
+ async delete(condition, options) {
67
+ const conditionBuilder = new ConditionBuilder();
68
+ condition(conditionBuilder);
69
+ const ast = conditionBuilder.done();
70
+ await hook("storage/ces").delete(this.entityName, ast, options);
71
+ }
72
+ }
@@ -0,0 +1,9 @@
1
+ import { CustomEntityStorage } from "./entity-storage.js";
2
+ /** Pre-created CES storage instance */
3
+ export declare const ces: {
4
+ /**
5
+ * @param entityName Entity name defined in manifest
6
+ */
7
+ entity<T>(entityName: string): CustomEntityStorage<T>;
8
+ };
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/ces/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAE1D,uCAAuC;AACvC,eAAO,MAAM,GAAG;IACZ;;OAEG;WACI,CAAC,cAAc,MAAM,GAAG,mBAAmB,CAAC,CAAC,CAAC;CAGxD,CAAC"}
@@ -0,0 +1,10 @@
1
+ import { CustomEntityStorage } from "./entity-storage.js";
2
+ /** Pre-created CES storage instance */
3
+ export const ces = {
4
+ /**
5
+ * @param entityName Entity name defined in manifest
6
+ */
7
+ entity(entityName) {
8
+ return new CustomEntityStorage(entityName);
9
+ },
10
+ };
@@ -0,0 +1,46 @@
1
+ export type Projection = string[];
2
+ export interface InsertOptions {
3
+ /** Whether to insert in order, default is false */
4
+ ordered?: boolean;
5
+ }
6
+ /**
7
+ * Options for entity().updateOne or entity().updateMany
8
+ */
9
+ export interface UpdateOptions {
10
+ }
11
+ /**
12
+ * Options for entity().delete
13
+ */
14
+ export interface DeleteOptions {
15
+ }
16
+ /**
17
+ * Options for find operations that return multiple records
18
+ * @template T Entity type extending Entity
19
+ */
20
+ export interface FindOptions {
21
+ /** Number of records to skip */
22
+ skip?: number;
23
+ /** Maximum number of records to return */
24
+ limit?: number;
25
+ /** Sort order specification, multiple sort properties are supported */
26
+ sort?: SortProperty[];
27
+ /** Index hint for query optimization */
28
+ hint?: string;
29
+ /** Fields to include or exclude in the result */
30
+ projection?: Projection;
31
+ /** Whether to include metadata in the result
32
+ * 1: default is false not include metadata
33
+ * 2: true include metadata [_created_by, _created_at, _is_deleted,_updated_by, _updated_at, _deleted_by, _deleted_at] */
34
+ includes?: {
35
+ metadata: boolean;
36
+ };
37
+ }
38
+ export interface SortProperty {
39
+ propertyKey: string;
40
+ order: Direction;
41
+ }
42
+ export declare enum Direction {
43
+ ascending = 1,
44
+ descending = -1
45
+ }
46
+ //# sourceMappingURL=type.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../../src/lib/ces/type.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,UAAU,GAAG,MAAM,EAAE,CAAC;AAElC,MAAM,WAAW,aAAa;IAC1B,mDAAmD;IACnD,OAAO,CAAC,EAAE,OAAO,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;CAAG;AAEjC;;GAEG;AACH,MAAM,WAAW,aAAa;CAAG;AAEjC;;;GAGG;AACH,MAAM,WAAW,WAAW;IACxB,gCAAgC;IAChC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,0CAA0C;IAC1C,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,uEAAuE;IACvE,IAAI,CAAC,EAAE,YAAY,EAAE,CAAC;IACtB,wCAAwC;IACxC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,iDAAiD;IACjD,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB;;6HAEyH;IACzH,QAAQ,CAAC,EAAE;QAAE,QAAQ,EAAE,OAAO,CAAA;KAAE,CAAC;CACpC;AAED,MAAM,WAAW,YAAY;IACzB,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,SAAS,CAAC;CACpB;AAED,oBAAY,SAAS;IACjB,SAAS,IAAI;IACb,UAAU,KAAK;CAClB"}
@@ -0,0 +1,5 @@
1
+ export var Direction;
2
+ (function (Direction) {
3
+ Direction[Direction["ascending"] = 1] = "ascending";
4
+ Direction[Direction["descending"] = -1] = "descending";
5
+ })(Direction || (Direction = {}));
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Key-Value Store (KVS)
3
+ */
4
+ export declare const kvs: {};
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/kvs/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,GAAG,IAAK,CAAC"}
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Key-Value Store (KVS)
3
+ */
4
+ export const kvs = {};
@@ -0,0 +1,5 @@
1
+ /**
2
+ * EAP (Early Access Program)
3
+ */
4
+ export {};
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/os/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,10 +1,12 @@
1
1
  {
2
2
  "name": "@pc-nexus/storage",
3
- "version": "0.0.1-next.1",
3
+ "version": "0.0.1-next.2",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
7
7
  "build": "tsc",
8
+ "pretest": "npm run build",
9
+ "test": "NODE_OPTIONS=\"--experimental-vm-modules --loader ts-node/esm\" jest",
8
10
  "pub:alpha": "cd dist && npm publish --access public --tag alpha",
9
11
  "pub": "cd dist && npm publish --access public --tag latest",
10
12
  "pub-next": "cd dist && npm publish --access public --tag next"
@@ -19,9 +21,6 @@
19
21
  "test": "test",
20
22
  "lib": "dist"
21
23
  },
22
- "files": [
23
- "dist"
24
- ],
25
24
  "types": "index.d.ts",
26
25
  "exports": {
27
26
  ".": {
@@ -30,7 +29,9 @@
30
29
  }
31
30
  },
32
31
  "type": "module",
33
- "dependencies": {},
32
+ "dependencies": {
33
+ "lodash": "^4.17.21"
34
+ },
34
35
  "devDependencies": {},
35
36
  "peerDependencies": {}
36
37
  }