@sprucelabs/data-stores 28.3.236 → 28.3.238
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.
@@ -1,8 +1,8 @@
|
|
1
|
-
import { Schema, SchemaFieldNames, SchemaPartialValues, SchemaPublicFieldNames, SchemaValues } from '@sprucelabs/schema';
|
1
|
+
import { Schema, SchemaFieldNames, SchemaPartialValues, SchemaPublicFieldNames, SchemaValues, ValuesWithPaths } from '@sprucelabs/schema';
|
2
2
|
import { FindBatchOptions } from '../cursors/BatchCursor';
|
3
3
|
import AbstractMutexer from '../mutexers/AbstractMutexer';
|
4
4
|
import { Database } from '../types/database.types';
|
5
|
-
import { QueryBuilder, QueryOptions
|
5
|
+
import { QueryBuilder, QueryOptions } from '../types/query.types';
|
6
6
|
import { PrepareOptions, PrepareResults, SaveOperations, DataStore, DataStorePlugin } from '../types/stores.types';
|
7
7
|
export default abstract class AbstractStore<FullSchema extends Schema, CreateSchema extends Schema = FullSchema, UpdateSchema extends Schema = CreateSchema, DatabaseSchema extends Schema = FullSchema, PrimaryFieldName extends SchemaFieldNames<DatabaseSchema> | 'id' = 'id', DatabaseRecord = SchemaValues<DatabaseSchema>, QueryRecord = SchemaPartialValues<FullSchema>, FullRecord = SchemaValues<FullSchema>, CreateRecord = SchemaValues<CreateSchema>, UpdateRecord = SchemaValues<UpdateSchema> & SaveOperations> extends AbstractMutexer implements DataStore {
|
8
8
|
abstract readonly name: string;
|
@@ -50,7 +50,7 @@ export default abstract class AbstractStore<FullSchema extends Schema, CreateSch
|
|
50
50
|
id?: string;
|
51
51
|
}, options?: PrepareOptions<IncludePrivateFields, FullSchema, F>): Promise<Response<FullSchema, CreateEntityInstances, IncludePrivateFields, PF, F>>;
|
52
52
|
updateOne<IncludePrivateFields extends boolean = false, CreateEntityInstances extends boolean = false, F extends SchemaFieldNames<FullSchema> = SchemaFieldNames<FullSchema>, PF extends SchemaPublicFieldNames<FullSchema> = SchemaPublicFieldNames<FullSchema>>(query: QueryBuilder<QueryRecord>, updates: ValuesWithPaths<UpdateRecord>, options?: PrepareOptions<IncludePrivateFields, FullSchema, F>): Promise<Response<FullSchema, CreateEntityInstances, IncludePrivateFields, PF, F>>;
|
53
|
-
update(query: QueryBuilder<QueryRecord>, updates: UpdateRecord): Promise<number>;
|
53
|
+
update(query: QueryBuilder<QueryRecord>, updates: ValuesWithPaths<UpdateRecord>): Promise<number>;
|
54
54
|
private findOneAndUpdate;
|
55
55
|
private handleWillUpdateOnePlugins;
|
56
56
|
private pluckOperations;
|
@@ -1,24 +1,11 @@
|
|
1
|
+
import { PathsWithDotNotation } from '@sprucelabs/schema';
|
1
2
|
import { QuerySelector, RootQuerySelector } from '../databases/mongo.types';
|
2
3
|
type Obj = Record<string, any>;
|
3
|
-
export type QueryBuilder<Query, Keys extends
|
4
|
+
export type QueryBuilder<Query, Keys extends PathsWithDotNotation<Query> = PathsWithDotNotation<Query>> = {
|
4
5
|
[K in Keys]?: QuerySelector<TypeAtPath<Query, K>> | TypeAtPath<Query, K>;
|
5
6
|
} & {
|
6
7
|
id?: string | QuerySelector<string>;
|
7
8
|
} & RootQuerySelector<Query>;
|
8
|
-
export type ValuesWithPaths<Values, Keys extends Paths<Values> = Paths<Values>> = {
|
9
|
-
[K in RequiredKeys<Values, Keys>]: TypeAtPath<Values, K>;
|
10
|
-
} & {
|
11
|
-
[K in OptionalKeys<Values, Keys>]?: TypeAtPath<Values, K>;
|
12
|
-
};
|
13
|
-
type IsOptional<T, K extends keyof T> = {} extends Pick<T, K> ? true : false;
|
14
|
-
type IsPathOptional<T, P extends string> = P extends `${infer K}.${infer Rest}` ? K extends keyof T ? IsOptional<T, K> extends true ? true : IsPathOptional<T[K], Rest> : true : P extends keyof T ? IsOptional<T, P> : true;
|
15
|
-
type RequiredKeys<Values, Keys extends Paths<Values>> = {
|
16
|
-
[K in Keys]: IsPathOptional<Values, K> extends true ? never : K;
|
17
|
-
}[Keys];
|
18
|
-
type OptionalKeys<Values, Keys extends Paths<Values>> = Exclude<Keys, RequiredKeys<Values, Keys>>;
|
19
|
-
type Paths<T, D extends number = 3> = [D] extends [never] ? never : T extends object ? {
|
20
|
-
[K in keyof T]-?: K extends string | number ? `${K}` | Join<K, Paths<T[K], Prev[D]>> : never;
|
21
|
-
}[keyof T] : '';
|
22
9
|
type TypeAtPath<T, P extends string> = P extends `${infer K}.${infer Rest}` ? K extends keyof T ? TypeAtPath<T[K], Rest> : any : P extends keyof T ? T[P] : any;
|
23
10
|
export interface QuerySortField {
|
24
11
|
field: string;
|
@@ -33,30 +20,4 @@ export interface QueryOptions {
|
|
33
20
|
export type PathKeys<Query extends Obj, Prefix extends string = ''> = {
|
34
21
|
[K in Extract<keyof Query, string> as `${Prefix}${K}`]: Query[K] extends Obj ? PathKeys<Query[K], `${K}.`> : Query[K];
|
35
22
|
};
|
36
|
-
type Join<K, P> = K extends string | number ? P extends string | number ? `${K}${'' extends P ? '' : '.'}${P}` : never : never;
|
37
|
-
type Prev = [
|
38
|
-
never,
|
39
|
-
0,
|
40
|
-
1,
|
41
|
-
2,
|
42
|
-
3,
|
43
|
-
4,
|
44
|
-
5,
|
45
|
-
6,
|
46
|
-
7,
|
47
|
-
8,
|
48
|
-
9,
|
49
|
-
10,
|
50
|
-
11,
|
51
|
-
12,
|
52
|
-
13,
|
53
|
-
14,
|
54
|
-
15,
|
55
|
-
16,
|
56
|
-
17,
|
57
|
-
18,
|
58
|
-
19,
|
59
|
-
20,
|
60
|
-
...0[]
|
61
|
-
];
|
62
23
|
export {};
|
@@ -1,8 +1,8 @@
|
|
1
|
-
import { Schema, SchemaFieldNames, SchemaPartialValues, SchemaPublicFieldNames, SchemaValues } from '@sprucelabs/schema';
|
1
|
+
import { Schema, SchemaFieldNames, SchemaPartialValues, SchemaPublicFieldNames, SchemaValues, ValuesWithPaths } from '@sprucelabs/schema';
|
2
2
|
import { FindBatchOptions } from '../cursors/BatchCursor';
|
3
3
|
import AbstractMutexer from '../mutexers/AbstractMutexer';
|
4
4
|
import { Database } from '../types/database.types';
|
5
|
-
import { QueryBuilder, QueryOptions
|
5
|
+
import { QueryBuilder, QueryOptions } from '../types/query.types';
|
6
6
|
import { PrepareOptions, PrepareResults, SaveOperations, DataStore, DataStorePlugin } from '../types/stores.types';
|
7
7
|
export default abstract class AbstractStore<FullSchema extends Schema, CreateSchema extends Schema = FullSchema, UpdateSchema extends Schema = CreateSchema, DatabaseSchema extends Schema = FullSchema, PrimaryFieldName extends SchemaFieldNames<DatabaseSchema> | 'id' = 'id', DatabaseRecord = SchemaValues<DatabaseSchema>, QueryRecord = SchemaPartialValues<FullSchema>, FullRecord = SchemaValues<FullSchema>, CreateRecord = SchemaValues<CreateSchema>, UpdateRecord = SchemaValues<UpdateSchema> & SaveOperations> extends AbstractMutexer implements DataStore {
|
8
8
|
abstract readonly name: string;
|
@@ -50,7 +50,7 @@ export default abstract class AbstractStore<FullSchema extends Schema, CreateSch
|
|
50
50
|
id?: string;
|
51
51
|
}, options?: PrepareOptions<IncludePrivateFields, FullSchema, F>): Promise<Response<FullSchema, CreateEntityInstances, IncludePrivateFields, PF, F>>;
|
52
52
|
updateOne<IncludePrivateFields extends boolean = false, CreateEntityInstances extends boolean = false, F extends SchemaFieldNames<FullSchema> = SchemaFieldNames<FullSchema>, PF extends SchemaPublicFieldNames<FullSchema> = SchemaPublicFieldNames<FullSchema>>(query: QueryBuilder<QueryRecord>, updates: ValuesWithPaths<UpdateRecord>, options?: PrepareOptions<IncludePrivateFields, FullSchema, F>): Promise<Response<FullSchema, CreateEntityInstances, IncludePrivateFields, PF, F>>;
|
53
|
-
update(query: QueryBuilder<QueryRecord>, updates: UpdateRecord): Promise<number>;
|
53
|
+
update(query: QueryBuilder<QueryRecord>, updates: ValuesWithPaths<UpdateRecord>): Promise<number>;
|
54
54
|
private findOneAndUpdate;
|
55
55
|
private handleWillUpdateOnePlugins;
|
56
56
|
private pluckOperations;
|
@@ -1,24 +1,11 @@
|
|
1
|
+
import { PathsWithDotNotation } from '@sprucelabs/schema';
|
1
2
|
import { QuerySelector, RootQuerySelector } from '../databases/mongo.types';
|
2
3
|
type Obj = Record<string, any>;
|
3
|
-
export type QueryBuilder<Query, Keys extends
|
4
|
+
export type QueryBuilder<Query, Keys extends PathsWithDotNotation<Query> = PathsWithDotNotation<Query>> = {
|
4
5
|
[K in Keys]?: QuerySelector<TypeAtPath<Query, K>> | TypeAtPath<Query, K>;
|
5
6
|
} & {
|
6
7
|
id?: string | QuerySelector<string>;
|
7
8
|
} & RootQuerySelector<Query>;
|
8
|
-
export type ValuesWithPaths<Values, Keys extends Paths<Values> = Paths<Values>> = {
|
9
|
-
[K in RequiredKeys<Values, Keys>]: TypeAtPath<Values, K>;
|
10
|
-
} & {
|
11
|
-
[K in OptionalKeys<Values, Keys>]?: TypeAtPath<Values, K>;
|
12
|
-
};
|
13
|
-
type IsOptional<T, K extends keyof T> = {} extends Pick<T, K> ? true : false;
|
14
|
-
type IsPathOptional<T, P extends string> = P extends `${infer K}.${infer Rest}` ? K extends keyof T ? IsOptional<T, K> extends true ? true : IsPathOptional<T[K], Rest> : true : P extends keyof T ? IsOptional<T, P> : true;
|
15
|
-
type RequiredKeys<Values, Keys extends Paths<Values>> = {
|
16
|
-
[K in Keys]: IsPathOptional<Values, K> extends true ? never : K;
|
17
|
-
}[Keys];
|
18
|
-
type OptionalKeys<Values, Keys extends Paths<Values>> = Exclude<Keys, RequiredKeys<Values, Keys>>;
|
19
|
-
type Paths<T, D extends number = 3> = [D] extends [never] ? never : T extends object ? {
|
20
|
-
[K in keyof T]-?: K extends string | number ? `${K}` | Join<K, Paths<T[K], Prev[D]>> : never;
|
21
|
-
}[keyof T] : '';
|
22
9
|
type TypeAtPath<T, P extends string> = P extends `${infer K}.${infer Rest}` ? K extends keyof T ? TypeAtPath<T[K], Rest> : any : P extends keyof T ? T[P] : any;
|
23
10
|
export interface QuerySortField {
|
24
11
|
field: string;
|
@@ -33,30 +20,4 @@ export interface QueryOptions {
|
|
33
20
|
export type PathKeys<Query extends Obj, Prefix extends string = ''> = {
|
34
21
|
[K in Extract<keyof Query, string> as `${Prefix}${K}`]: Query[K] extends Obj ? PathKeys<Query[K], `${K}.`> : Query[K];
|
35
22
|
};
|
36
|
-
type Join<K, P> = K extends string | number ? P extends string | number ? `${K}${'' extends P ? '' : '.'}${P}` : never : never;
|
37
|
-
type Prev = [
|
38
|
-
never,
|
39
|
-
0,
|
40
|
-
1,
|
41
|
-
2,
|
42
|
-
3,
|
43
|
-
4,
|
44
|
-
5,
|
45
|
-
6,
|
46
|
-
7,
|
47
|
-
8,
|
48
|
-
9,
|
49
|
-
10,
|
50
|
-
11,
|
51
|
-
12,
|
52
|
-
13,
|
53
|
-
14,
|
54
|
-
15,
|
55
|
-
16,
|
56
|
-
17,
|
57
|
-
18,
|
58
|
-
19,
|
59
|
-
20,
|
60
|
-
...0[]
|
61
|
-
];
|
62
23
|
export {};
|
package/package.json
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
"publishConfig": {
|
4
4
|
"access": "public"
|
5
5
|
},
|
6
|
-
"version": "28.3.
|
6
|
+
"version": "28.3.238",
|
7
7
|
"files": [
|
8
8
|
"build/**/*",
|
9
9
|
"!build/__tests__",
|
@@ -67,8 +67,8 @@
|
|
67
67
|
"@seald-io/nedb": "^4.0.4",
|
68
68
|
"@sprucelabs/error": "^6.0.549",
|
69
69
|
"@sprucelabs/globby": "^2.0.499",
|
70
|
-
"@sprucelabs/schema": "^30.0.
|
71
|
-
"@sprucelabs/spruce-skill-utils": "^31.0.
|
70
|
+
"@sprucelabs/schema": "^30.0.581",
|
71
|
+
"@sprucelabs/spruce-skill-utils": "^31.0.643",
|
72
72
|
"just-clone": "^6.2.0",
|
73
73
|
"lodash": "^4.17.21",
|
74
74
|
"mongodb": "^6.11.0"
|
@@ -79,7 +79,7 @@
|
|
79
79
|
"@sprucelabs/resolve-path-aliases": "^2.0.519",
|
80
80
|
"@sprucelabs/semantic-release": "^5.0.2",
|
81
81
|
"@sprucelabs/test": "^9.0.62",
|
82
|
-
"@sprucelabs/test-utils": "^5.1.
|
82
|
+
"@sprucelabs/test-utils": "^5.1.517",
|
83
83
|
"@types/lodash": "^4.17.13",
|
84
84
|
"@types/node": "^22.10.1",
|
85
85
|
"chokidar-cli": "^3.0.0",
|