couchset 0.2.7 → 0.3.0
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 +284 -153
- package/dist/connection/connection.d.ts +68 -0
- package/dist/connection/connection.js +485 -0
- package/dist/connection/connection.js.map +1 -0
- package/dist/connection/env.d.ts +2 -0
- package/dist/connection/env.js +16 -0
- package/dist/connection/env.js.map +1 -0
- package/dist/connection/index.d.ts +3 -0
- package/dist/connection/index.js +25 -0
- package/dist/connection/index.js.map +1 -0
- package/dist/connection/types.d.ts +25 -0
- package/dist/connection/types.js +3 -0
- package/dist/connection/types.js.map +1 -0
- package/dist/database.d.ts +9 -0
- package/dist/database.js +196 -0
- package/dist/database.js.map +1 -0
- package/dist/index.d.ts +18 -6
- package/dist/index.js +53 -8
- package/dist/index.js.map +1 -1
- package/dist/legacy/connection.d.ts +2 -0
- package/dist/legacy/connection.js +24 -0
- package/dist/legacy/connection.js.map +1 -0
- package/dist/legacy/index.d.ts +10 -0
- package/dist/legacy/index.js +93 -0
- package/dist/legacy/index.js.map +1 -0
- package/dist/legacy/model.d.ts +55 -0
- package/dist/legacy/model.js +282 -0
- package/dist/legacy/model.js.map +1 -0
- package/dist/legacy/pagination/index.d.ts +1 -0
- package/dist/legacy/pagination/index.js +18 -0
- package/dist/legacy/pagination/index.js.map +1 -0
- package/dist/legacy/pagination/pagination.d.ts +12 -0
- package/dist/legacy/pagination/pagination.js +85 -0
- package/dist/legacy/pagination/pagination.js.map +1 -0
- package/dist/legacy/search/customQuery.d.ts +13 -0
- package/dist/legacy/search/customQuery.js +73 -0
- package/dist/legacy/search/customQuery.js.map +1 -0
- package/dist/legacy/search/index.d.ts +1 -0
- package/dist/legacy/search/index.js +18 -0
- package/dist/legacy/search/index.js.map +1 -0
- package/dist/model/default-scope.d.ts +10 -0
- package/dist/model/default-scope.js +47 -0
- package/dist/model/default-scope.js.map +1 -0
- package/dist/model/hydrated-document.d.ts +30 -0
- package/dist/model/hydrated-document.js +118 -0
- package/dist/model/hydrated-document.js.map +1 -0
- package/dist/model/include.d.ts +33 -0
- package/dist/model/include.js +250 -0
- package/dist/model/include.js.map +1 -0
- package/dist/model/index.d.ts +137 -51
- package/dist/model/index.js +519 -174
- package/dist/model/index.js.map +1 -1
- package/dist/model/indexes.d.ts +16 -0
- package/dist/model/indexes.js +155 -0
- package/dist/model/indexes.js.map +1 -0
- package/dist/model/keyspace.d.ts +9 -0
- package/dist/model/keyspace.js +28 -0
- package/dist/model/keyspace.js.map +1 -0
- package/dist/model/read-helpers.d.ts +36 -0
- package/dist/model/read-helpers.js +275 -0
- package/dist/model/read-helpers.js.map +1 -0
- package/dist/model/safe-query.d.ts +23 -0
- package/dist/model/safe-query.js +138 -0
- package/dist/model/safe-query.js.map +1 -0
- package/dist/model/ttl.d.ts +9 -0
- package/dist/model/ttl.js +73 -0
- package/dist/model/ttl.js.map +1 -0
- package/dist/model/validation.d.ts +5 -0
- package/dist/model/validation.js +104 -0
- package/dist/model/validation.js.map +1 -0
- package/dist/model/write-helpers.d.ts +31 -0
- package/dist/model/write-helpers.js +220 -0
- package/dist/model/write-helpers.js.map +1 -0
- package/dist/pagination/index.d.ts +1 -0
- package/dist/pagination/index.js +1 -0
- package/dist/pagination/index.js.map +1 -1
- package/dist/pagination/pagination.d.ts +1 -8
- package/dist/pagination/pagination.js +16 -29
- package/dist/pagination/pagination.js.map +1 -1
- package/dist/pagination/safe-pagination.d.ts +15 -0
- package/dist/pagination/safe-pagination.js +221 -0
- package/dist/pagination/safe-pagination.js.map +1 -0
- package/dist/pagination/types.d.ts +11 -0
- package/dist/pagination/types.js +3 -0
- package/dist/pagination/types.js.map +1 -0
- package/dist/search/customQuery.d.ts +10 -3
- package/dist/search/customQuery.js +17 -18
- package/dist/search/customQuery.js.map +1 -1
- package/dist/shared/common.model.js +2 -2
- package/dist/shared/common.model.js.map +1 -1
- package/dist/timeseries/index.d.ts +1 -0
- package/dist/timeseries/index.js +18 -0
- package/dist/timeseries/index.js.map +1 -0
- package/dist/timeseries/time-series-model.d.ts +60 -0
- package/dist/timeseries/time-series-model.js +267 -0
- package/dist/timeseries/time-series-model.js.map +1 -0
- package/dist/utils/awaitTo.d.ts +1 -1
- package/dist/utils/awaitTo.js +1 -1
- package/dist/utils/awaitTo.js.map +1 -1
- package/docs/beta-migration.md +175 -0
- package/legacy/index.js +1 -0
- package/legacy/package.json +4 -0
- package/next/index.js +1 -0
- package/next/package.json +4 -0
- package/package.json +13 -8
- package/dist/connection.d.ts +0 -42
- package/dist/connection.js +0 -156
- package/dist/connection.js.map +0 -1
package/dist/model/index.d.ts
CHANGED
|
@@ -1,7 +1,19 @@
|
|
|
1
|
-
import type { Collection, GetOptions, RemoveOptions, ReplaceOptions
|
|
2
|
-
import { CustomQueryPagination } from '../search';
|
|
1
|
+
import type { Collection, GetOptions, MutateInOptions, RemoveOptions, ReplaceOptions } from 'couchbase';
|
|
3
2
|
import { SchemaTypes } from '../utils';
|
|
4
|
-
import
|
|
3
|
+
import type { ModelPageResult, ModelReadArgs } from './read-helpers';
|
|
4
|
+
import type { QueryPageOptions, QueryPageResult, QueryParameters, SafeQueryOptions } from './safe-query';
|
|
5
|
+
import type { FindByIdWithMetaResult, InsertWriteOptions, PatchByIdArgs, UpsertWriteOptions } from './write-helpers';
|
|
6
|
+
import { Hydrated } from './hydrated-document';
|
|
7
|
+
import { EnsureIndexOptions, ModelIndexDefinition } from './indexes';
|
|
8
|
+
import type { ParseHook, ValidationHook } from './validation';
|
|
9
|
+
export type { ModelPageResult, ModelReadArgs } from './read-helpers';
|
|
10
|
+
export type { QueryLogger, QueryPageOptions, QueryPageResult, QueryParameters, SafeQueryOptions, } from './safe-query';
|
|
11
|
+
export type { FindByIdWithMetaResult, PatchByIdArgs } from './write-helpers';
|
|
12
|
+
export type { Hydrated } from './hydrated-document';
|
|
13
|
+
export type { IncludeDefinition, IncludeType } from './include';
|
|
14
|
+
export type { EnsureIndexOptions, ModelIndexDefinition } from './indexes';
|
|
15
|
+
export type { TtlOptions } from './ttl';
|
|
16
|
+
export type { ParseHook, ValidationHook } from './validation';
|
|
5
17
|
export interface AutoModelFields {
|
|
6
18
|
id: string;
|
|
7
19
|
createdAt: Date;
|
|
@@ -13,91 +25,165 @@ export interface AutoModelFields {
|
|
|
13
25
|
export interface UpdateOptions extends ReplaceOptions {
|
|
14
26
|
silent?: boolean;
|
|
15
27
|
}
|
|
28
|
+
export interface DeleteByIdOptions extends RemoveOptions {
|
|
29
|
+
hard?: boolean;
|
|
30
|
+
}
|
|
16
31
|
export interface ModalOptions {
|
|
17
32
|
scope?: string;
|
|
33
|
+
collection?: string;
|
|
18
34
|
schema?: Record<string, SchemaTypes>;
|
|
19
|
-
|
|
35
|
+
softDelete?: boolean;
|
|
36
|
+
defaultWhere?: any;
|
|
37
|
+
validateCreate?: ValidationHook;
|
|
38
|
+
validateReplace?: ValidationHook;
|
|
39
|
+
parse?: ParseHook;
|
|
40
|
+
dateFields?: string[];
|
|
41
|
+
indexes?: ModelIndexDefinition[];
|
|
20
42
|
}
|
|
21
43
|
export declare class Model {
|
|
44
|
+
private static registeredModels;
|
|
22
45
|
collection: Collection;
|
|
23
46
|
collectionName: string;
|
|
24
47
|
scope: string;
|
|
48
|
+
private scopeName?;
|
|
49
|
+
private collectionTargetName?;
|
|
50
|
+
private defaultWhere?;
|
|
51
|
+
private defaultWhereMode;
|
|
52
|
+
private softDelete;
|
|
53
|
+
private validateCreateHook?;
|
|
54
|
+
private validateReplaceHook?;
|
|
55
|
+
private parseHook?;
|
|
56
|
+
private dateFields?;
|
|
57
|
+
private indexes;
|
|
25
58
|
schema: Record<string, SchemaTypes>;
|
|
26
|
-
graphqlType: any;
|
|
27
59
|
constructor(name: string, options?: ModalOptions);
|
|
28
60
|
/**
|
|
29
|
-
*
|
|
30
|
-
* setGraphqlType
|
|
61
|
+
* Ensure indexes for every constructed model with index declarations.
|
|
31
62
|
*/
|
|
32
|
-
|
|
63
|
+
static ensureIndexes(options?: EnsureIndexOptions): Promise<string[]>;
|
|
33
64
|
/**
|
|
34
65
|
* Refresh and get default collection from CouchbaseConnection
|
|
35
66
|
* Because CouchbaseConnection is a singleton, sometimes it might be undefined depending when model was created
|
|
36
67
|
* So we have to call it from all model methods
|
|
37
68
|
* to avoid error `Cannot read property 'defaultCollection' of null`
|
|
38
69
|
*/
|
|
39
|
-
fresh
|
|
70
|
+
private fresh;
|
|
71
|
+
private prepare;
|
|
72
|
+
private withConnection;
|
|
40
73
|
/** Get this collection
|
|
41
74
|
* getCollection
|
|
42
75
|
*/
|
|
43
|
-
getBucketName
|
|
76
|
+
private getBucketName;
|
|
44
77
|
/** Get this collection
|
|
45
78
|
* getCollection
|
|
46
79
|
*/
|
|
47
|
-
couchbaseConnection
|
|
80
|
+
private couchbaseConnection;
|
|
48
81
|
/** Get this collection
|
|
49
82
|
* getCollection
|
|
50
83
|
*/
|
|
51
84
|
getCollection(): Collection;
|
|
85
|
+
private collectionTarget;
|
|
86
|
+
private queryResultKey;
|
|
87
|
+
private readContext;
|
|
88
|
+
private readArgs;
|
|
89
|
+
private writeContext;
|
|
90
|
+
private cloneWithDefaultWhereMode;
|
|
91
|
+
/**
|
|
92
|
+
* Return the active bucket as a SQL++ keyspace identifier.
|
|
93
|
+
*/
|
|
94
|
+
bucket(): string;
|
|
95
|
+
/**
|
|
96
|
+
* Return this model's SQL++ keyspace target.
|
|
97
|
+
*/
|
|
98
|
+
keyspace(): string;
|
|
99
|
+
/**
|
|
100
|
+
* Return a SQL++ FROM target for this model's current bucket.
|
|
101
|
+
*/
|
|
102
|
+
from(alias?: string): string;
|
|
103
|
+
/**
|
|
104
|
+
* Return CREATE INDEX statements for this model without executing them.
|
|
105
|
+
*/
|
|
106
|
+
indexStatements(options?: EnsureIndexOptions): string[];
|
|
52
107
|
/**
|
|
53
|
-
*
|
|
108
|
+
* Create this model's declared indexes if Couchbase does not already have them.
|
|
54
109
|
*/
|
|
55
|
-
|
|
110
|
+
ensureIndexes(options?: EnsureIndexOptions): Promise<string[]>;
|
|
56
111
|
/**
|
|
57
|
-
*
|
|
112
|
+
* Run a SQL++ query and return rows directly.
|
|
58
113
|
*/
|
|
59
|
-
|
|
114
|
+
queryRows<T>(query: string, params?: QueryParameters, options?: SafeQueryOptions): Promise<T[]>;
|
|
60
115
|
/**
|
|
61
|
-
*
|
|
116
|
+
* Run a SQL++ query and return the first row or null.
|
|
62
117
|
*/
|
|
63
|
-
|
|
118
|
+
queryOne<T>(query: string, params?: QueryParameters, options?: SafeQueryOptions): Promise<T | null>;
|
|
64
119
|
/**
|
|
65
|
-
*
|
|
120
|
+
* Run a SQL++ query using limit + 1 pagination.
|
|
66
121
|
*/
|
|
67
|
-
|
|
122
|
+
queryPage<T>(query: string, params?: QueryParameters, options?: QueryPageOptions): Promise<QueryPageResult<T>>;
|
|
123
|
+
/**
|
|
124
|
+
* Find many model-scoped documents.
|
|
125
|
+
*/
|
|
126
|
+
findMany<T>(args?: ModelReadArgs): Promise<T[]>;
|
|
127
|
+
/**
|
|
128
|
+
* Find the first matching model-scoped document.
|
|
129
|
+
*/
|
|
130
|
+
findOne<T>(args?: ModelReadArgs): Promise<T | null>;
|
|
131
|
+
/**
|
|
132
|
+
* Check whether at least one model-scoped document matches.
|
|
133
|
+
*/
|
|
134
|
+
exists(args?: ModelReadArgs): Promise<boolean>;
|
|
135
|
+
/**
|
|
136
|
+
* Count model-scoped documents.
|
|
137
|
+
*/
|
|
138
|
+
count(args?: ModelReadArgs): Promise<number>;
|
|
139
|
+
/**
|
|
140
|
+
* Fetch a limit + 1 page of model-scoped documents.
|
|
141
|
+
*/
|
|
142
|
+
page<T>(args?: ModelReadArgs): Promise<ModelPageResult<T>>;
|
|
143
|
+
withDeleted(): Model;
|
|
144
|
+
onlyDeleted(): Model;
|
|
145
|
+
withoutDefaultWhere(): Model;
|
|
146
|
+
/**
|
|
147
|
+
* Insert a new document and fail if the id already exists.
|
|
148
|
+
*/
|
|
149
|
+
insert<T>(data: T, options?: InsertWriteOptions): Promise<T & AutoModelFields>;
|
|
150
|
+
/**
|
|
151
|
+
* Explicit insert-or-replace write.
|
|
152
|
+
*/
|
|
153
|
+
upsert<T>(data: T, options?: UpsertWriteOptions): Promise<T & AutoModelFields>;
|
|
154
|
+
getById<T>(id: string, options?: GetOptions): Promise<T & AutoModelFields>;
|
|
155
|
+
findDocById<T extends {
|
|
156
|
+
id: string;
|
|
157
|
+
}>(id: string, options?: GetOptions): Promise<Hydrated<T>>;
|
|
158
|
+
/**
|
|
159
|
+
* Find a document with SDK metadata.
|
|
160
|
+
*/
|
|
161
|
+
findByIdWithMeta<T>(id: string, options?: GetOptions): Promise<FindByIdWithMetaResult<T>>;
|
|
162
|
+
/**
|
|
163
|
+
* Explicit full-document replace.
|
|
164
|
+
*/
|
|
165
|
+
replaceById<T>(id: string, data: T, options?: UpdateOptions): Promise<T & AutoModelFields>;
|
|
166
|
+
/**
|
|
167
|
+
* Partial document mutation using common patch operators.
|
|
168
|
+
*/
|
|
169
|
+
patchById<T>(id: string, patch: PatchByIdArgs, options?: MutateInOptions): Promise<T & AutoModelFields>;
|
|
170
|
+
/**
|
|
171
|
+
* Couchbase subdocument mutation escape hatch.
|
|
172
|
+
*/
|
|
173
|
+
mutateById(id: string, specs: any[], options?: MutateInOptions): Promise<any>;
|
|
174
|
+
/**
|
|
175
|
+
* Atomic numeric field increment.
|
|
176
|
+
*/
|
|
177
|
+
incrementById<T>(id: string, field: string, delta: number, options?: MutateInOptions): Promise<T & AutoModelFields>;
|
|
178
|
+
softDeleteById<T>(id: string, options?: MutateInOptions): Promise<T & AutoModelFields>;
|
|
179
|
+
restoreById<T>(id: string, options?: MutateInOptions): Promise<T & AutoModelFields>;
|
|
180
|
+
deleteById<T>(id: string, options?: DeleteByIdOptions): Promise<boolean | (T & AutoModelFields)>;
|
|
181
|
+
findDocOne<T extends {
|
|
182
|
+
id: string;
|
|
183
|
+
}>(args?: ModelReadArgs): Promise<Hydrated<T> | null>;
|
|
184
|
+
hydrate<T extends {
|
|
68
185
|
id: string;
|
|
69
|
-
}
|
|
70
|
-
delete(id: string, options?: RemoveOptions): Promise<boolean>;
|
|
71
|
-
/**
|
|
72
|
-
* Pagination
|
|
73
|
-
*
|
|
74
|
-
select = ['id', 'createdAt']
|
|
75
|
-
where = {
|
|
76
|
-
where: { owner: { $eq: "stoqey" }, _type: { $eq: "Trade" } },
|
|
77
|
-
},
|
|
78
|
-
page = 0,
|
|
79
|
-
limit = 10,
|
|
80
|
-
orderBy = { createdAt: "DESC" },
|
|
81
|
-
* @param args PaginationArgs
|
|
82
|
-
*/
|
|
83
|
-
pagination({ select, where, orderBy, limit, page, customQuery, }: {
|
|
84
|
-
select?: any[] | string;
|
|
85
|
-
where?: any;
|
|
86
|
-
orderBy?: any;
|
|
87
|
-
limit?: number;
|
|
88
|
-
page?: number;
|
|
89
|
-
customQuery?: any;
|
|
90
|
-
}): Promise<any[]>;
|
|
91
|
-
/**
|
|
92
|
-
* Run a custom query with model parsing
|
|
93
|
-
* @param { select, query }
|
|
94
|
-
* @returns
|
|
95
|
-
*/
|
|
96
|
-
customQuery<T>({ params, limit, query, }: {
|
|
97
|
-
params: any;
|
|
98
|
-
limit: number;
|
|
99
|
-
query: string;
|
|
100
|
-
}): Promise<[T[], CustomQueryPagination]>;
|
|
186
|
+
}>(data: T & AutoModelFields): Hydrated<T>;
|
|
101
187
|
parse<T>(data: T): T;
|
|
102
188
|
}
|
|
103
189
|
export default Model;
|