gs-idb-pro 0.1.4 → 1.0.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/lib/impl.d.ts ADDED
@@ -0,0 +1,265 @@
1
+ import { StrOrNum } from 'gs-base/types';
2
+ import { DbQuery } from 'gs-idb-basic/type';
3
+ import { ArrayDbRecord, DataOperationSchema, DbRecord, DbRecordResult, DBSchema, FindFn, GetRowMapper, IChangeManyOption, IChangeRangeArg, ICursorArg, ICursorOption, ICursorResultArg, ICursorRow, IDataOperationSchema, IDataOperatorFactory, IDataOperators, IDataReader, IDataWriter, IDbIterator, IDbIteratorArg, IDbIteratorOption, IDbIteratorParser, IDbMap, IDbNoneKeyPathRecord, IDbQuery, IDbSchema, IDbVersionBounds, IDeleteOption, IDeleteRangeOption, IFilterArg, IFindArg, IFindMapArg, IForEachable, IForEachArg, IForEachResultArg, IGenerateOption, IGetAllArgs, IIDbPro, IInfoTarget, ImportUse, INativeOperationResult, IndexSchema, IPage, IPageArg, IPageInfo, IStoreSchema, IStoreUpgradeable, IUpgradeContext, IUpgradeContextArgs, IValidDataOperationSchema, NativeReader, NativeTarget, NativeWriter, OperationTarget, ReadCallFn, RequiredDbNoneKeyPathRecord, SaveRowMapper, StoreSchema, ValueCallFn, ValueModifyFn, VersionValidateFn, VoidCallFn, VoidModifyFn, WriteCallFn } from './type.d.ts';
4
+
5
+ interface IOpenCursorArg extends ICursorOption {
6
+ fn: (cursor: IDBCursorWithValue) => void | false | Promise<void | false>;
7
+ }
8
+ declare class DataOperationBase implements IValidDataOperationSchema<any>, IForEachable {
9
+ #private;
10
+ readonly idbPro?: IIDbPro;
11
+ readonly target: any;
12
+ constructor(schema: IValidDataOperationSchema<any>, db?: IIDbPro);
13
+ get storeName(): string;
14
+ get storeSchema(): IStoreSchema;
15
+ get factory(): IDataOperatorFactory;
16
+ get nativeStore(): IDBObjectStore | undefined;
17
+ get keyPath(): string | string[] | null | undefined;
18
+ forEach<T = any>(fn: VoidCallFn<T> | IForEachArg<T>): Promise<void>;
19
+ forEach<R = DbRecordResult, T = any>(fn: ValueCallFn<T, R> | IForEachResultArg<T, R>, returns: true): Promise<R[]>;
20
+ protected tx(writable?: false): Promise<INativeOperationResult<NativeTarget>>;
21
+ protected tx(writable: true): Promise<INativeOperationResult<IDBObjectStore>>;
22
+ protected tx<T>(fn: ReadCallFn<T>): Promise<T>;
23
+ protected tx<T>(writable: false, fn?: ReadCallFn<T>): Promise<T>;
24
+ protected tx<T>(writable: true, fn?: WriteCallFn<T>, rollbackOnError?: boolean): Promise<T>;
25
+ protected openCursor(arg: IOpenCursorArg, writable?: boolean): Promise<void>;
26
+ protected cursorVoid({ query, direction, preSkip, startKey, startPrimaryKey, fn }: ICursorArg, writable: boolean): Promise<void>;
27
+ protected cursorResult({ query, direction, preSkip, startKey, startPrimaryKey, fn, mapper: mpr }: ICursorResultArg, writable: boolean): Promise<any>;
28
+ }
29
+
30
+ declare class DataOperators<S1 = any, S2 = any, S3 = any, S4 = any, S5 = any> implements IDataOperators<S1, S2, S3, S4, S5> {
31
+ #private;
32
+ readonly idbPro: IIDbPro;
33
+ readonly schemas: IValidDataOperationSchema<IInfoTarget>[];
34
+ constructor(idbPro: IIDbPro, schemas: IValidDataOperationSchema<IInfoTarget>[]);
35
+ get storeNames(): string[];
36
+ read<Rtn = any>(fn: (s1: NativeReader<S1>, s2: NativeReader<S2>, s3: NativeReader<S3>, s4: NativeReader<S4>, s5: NativeReader<S5>, ...stores: NativeReader[]) => (Promise<Rtn> | Rtn)): Promise<Rtn>;
37
+ write<Rtn = any>(fn: (s1: NativeWriter<S1>, s2: NativeWriter<S2>, s3: NativeWriter<S3>, s4: NativeWriter<S4>, s5: NativeWriter<S5>, ...stores: NativeWriter[]) => (Promise<Rtn> | Rtn), rollbackOnError?: boolean): Promise<Rtn>;
38
+ export(): Promise<Record<string, any[]>>;
39
+ import(data: Record<string, any[]>, returns?: false, use?: ImportUse): Promise<void>;
40
+ import(data: Record<string, any[]>, returns?: true, use?: ImportUse): Promise<Record<string, any[]>>;
41
+ protected tx(method: keyof Pick<IDataOperatorFactory, 'newReader' | 'newWriter'>, fn: Function, writable?: boolean, rollbackOnError?: boolean): Promise<any>;
42
+ }
43
+
44
+ declare class DataReader<Row, Tar extends OperationTarget = OperationTarget> extends DataOperationBase implements IDataReader<Row, Tar> {
45
+ all(query?: IDbQuery, limit?: number): Promise<Row[]>;
46
+ all(args?: IGetAllArgs): Promise<Row[]>;
47
+ count(): Promise<number>;
48
+ count(query: IDbQuery | FindFn<Row>, direction?: IDBCursorDirection): Promise<number>;
49
+ count(query: IDbQuery, fn: FindFn<Row>, direction?: IDBCursorDirection): Promise<number>;
50
+ count(arg: IFindArg<Row>): Promise<number>;
51
+ get(key: IDbQuery): Promise<Row | undefined>;
52
+ getMany(keys: IDbQuery[], excludeEmpty?: boolean): Promise<Row[]>;
53
+ getRange(query: IDbQuery, direction?: IDBCursorDirection): Promise<DbRecordResult<Row>[]>;
54
+ getRangeMany(keys: IDbQuery[], direction?: IDBCursorDirection): Promise<DbRecordResult<Row>[]>;
55
+ index(name: string): IDataReader<Row, Tar>;
56
+ index(name: string, writable: true): IDataWriter<Row, Tar>;
57
+ asStore(): IDataReader<Row, Tar>;
58
+ asStore(writable: true): IDataWriter<Row, Tar>;
59
+ batchRead<R = any>(fn: (reader: IDataReader<Row, NativeTarget>) => Promise<void | R>): Promise<R>;
60
+ iterator(query: IDbQuery, direction?: IDBCursorDirection): AsyncIterable<Row>;
61
+ iterator(arg: IDbIteratorArg): AsyncIterable<Row>;
62
+ filter(): Promise<Row[]>;
63
+ filter<R = ArrayDbRecord<Row>>(args: IFilterArg<R, Row>): Promise<R[]>;
64
+ filter(query: IDbQuery | FindFn<Row>, direction?: IDBCursorDirection): Promise<ArrayDbRecord<Row>[]>;
65
+ filter(query: IDbQuery, fn: FindFn<Row>, direction?: IDBCursorDirection): Promise<ArrayDbRecord<Row>[]>;
66
+ filter(arg1?: IDbQuery | FindFn<Row> | IFilterArg<Row>, arg2?: IDBCursorDirection | FindFn<Row>, arg3?: IDBCursorDirection, limit?: number): Promise<ArrayDbRecord<Row>[]>;
67
+ find(): Promise<Row | undefined>;
68
+ find(query: IDbQuery | FindFn<Row>, direction?: IDBCursorDirection): Promise<ArrayDbRecord<Row> | undefined>;
69
+ find(query: IDbQuery, fn: FindFn<Row>, direction?: IDBCursorDirection): Promise<ArrayDbRecord<Row> | undefined>;
70
+ find<R = ArrayDbRecord<Row>>(args: IFindMapArg<R, Row>): Promise<Row | undefined>;
71
+ page<R = ArrayDbRecord<Row>>(): Promise<IPage<R, Row>>;
72
+ page<R = ArrayDbRecord<Row>>(arg: IPageArg<R, Row> | IPageInfo<R, Row>, page?: number): Promise<IPage<R, Row>>;
73
+ nextPage<R = Row>(info: IPageInfo<R, Row>): Promise<IPage<R, Row>>;
74
+ export<R = ArrayDbRecord<Row>>(): Promise<ArrayDbRecord<R>[]>;
75
+ export<R = ArrayDbRecord<Row>>(query: IDbQuery | FindFn<Row>): Promise<ArrayDbRecord<R>[]>;
76
+ export<R = ArrayDbRecord<Row>>(query: IDbQuery, fn: FindFn<Row>): Promise<ArrayDbRecord<R>[]>;
77
+ asMap<Key extends StrOrNum = StrOrNum>(): IDbMap<Key, Row, Tar>;
78
+ protected createOperator(target: OperationTarget, writable?: boolean): any;
79
+ }
80
+
81
+ declare class DataWriter<Row, Tar extends OperationTarget = OperationTarget> extends DataReader<Row, Tar> implements IDataWriter<Row, Tar> {
82
+ add(record: DbRecord<Row>): Promise<DbRecordResult<Row>>;
83
+ addMany(records: DbRecord<Row>[], returns?: false): Promise<void>;
84
+ addMany(records: DbRecord<Row>[], returns: true): Promise<DbRecordResult<Row>[]>;
85
+ addOrSkip(record: DbRecord<Row>): Promise<DbRecordResult<Row>>;
86
+ addOrSkipMany(records: DbRecord<Row>[], returns?: false): Promise<void>;
87
+ addOrSkipMany(records: DbRecord<Row>[], returns: true): Promise<DbRecordResult<Row>[]>;
88
+ replace(record: DbRecord<Row>): Promise<DbRecordResult<Row>>;
89
+ replaceMany(records: DbRecord<Row>[], returns?: false): Promise<void>;
90
+ replaceMany(records: DbRecord<Row>[], returns: true): Promise<DbRecordResult<Row>[]>;
91
+ change(record: DbRecord<Partial<Row>>, throwIfMissing?: boolean): Promise<DbRecordResult<Row> | undefined>;
92
+ changeMany(records: DbRecord<Partial<Row>>[], returns?: false): Promise<void>;
93
+ changeMany(records: DbRecord<Partial<Row>>[], returns: true): Promise<(DbRecordResult<Row> | undefined)[]>;
94
+ changeMany(records: DbRecord<Partial<Row>>[], option: IChangeManyOption<false | undefined>): Promise<void>;
95
+ changeMany(records: DbRecord<Partial<Row>>[], option: IChangeManyOption<true>): Promise<(DbRecordResult<Row> | undefined)[]>;
96
+ addOrChange(record: DbRecord<Partial<Row>>): Promise<DbRecordResult<Row> | undefined>;
97
+ addOrChangeMany(records: DbRecord<Partial<Row>>[], returns?: false): Promise<void>;
98
+ addOrChangeMany(records: DbRecord<Partial<Row>>[], returns: true): Promise<DbRecordResult<Row>[]>;
99
+ delete(key: IDbQuery, returns?: false): Promise<void>;
100
+ delete(key: IDbQuery, returns: true): Promise<DbRecordResult<Row>>;
101
+ delete(key: IDbQuery, option: IDeleteOption<false | undefined>): Promise<void>;
102
+ delete(key: IDbQuery, option: IDeleteOption<true>): Promise<DbRecordResult<Row>>;
103
+ deleteMany(keys: IDbQuery[], returns?: false): Promise<void>;
104
+ deleteMany(keys: IDbQuery[], returns: true): Promise<DbRecordResult<Row>[]>;
105
+ deleteMany(key: IDbQuery, option: IDeleteOption<false | undefined>): Promise<void>;
106
+ deleteMany(key: IDbQuery, option: IDeleteOption<true>): Promise<DbRecordResult<Row>[]>;
107
+ deleteRange(key: IDbQuery, returns?: false): Promise<void>;
108
+ deleteRange(key: IDbQuery, returns: true): Promise<DbRecordResult<Row>[]>;
109
+ deleteRange(key: IDbQuery, option: IDeleteRangeOption<false | undefined>): Promise<void>;
110
+ deleteRange(key: IDbQuery, option: IDeleteRangeOption<true>): Promise<DbRecordResult<Row>[]>;
111
+ deleteRangeMany(keys: IDbQuery[], returns?: false): Promise<void>;
112
+ deleteRangeMany(keys: IDbQuery[], returns: true): Promise<DbRecordResult<Row>[][]>;
113
+ deleteRangeMany(keys: IDbQuery[], option: IDeleteRangeOption<false | undefined>): Promise<void>;
114
+ deleteRangeMany(keys: IDbQuery[], option: IDeleteRangeOption<true>): Promise<DbRecordResult<Row>[][]>;
115
+ changeRange(arg: DbRecord<Partial<Row>> | IChangeRangeArg<Row>, returns?: false): Promise<void>;
116
+ changeRange(arg: DbRecord<Partial<Row>> | IChangeRangeArg<Row>, returns: true): Promise<DbRecordResult<Row>[]>;
117
+ changeRangeMany(args: DbRecord<Partial<Row>> | IChangeRangeArg<Row>[], returns?: false): Promise<void>;
118
+ changeRangeMany(args: DbRecord<Partial<Row>> | IChangeRangeArg<Row>[], returns: true): Promise<DbRecordResult<Row>[][]>;
119
+ cursor(option?: ICursorOption): AsyncIterable<ICursorRow>;
120
+ cursor<Val extends Row = Row>(fn: VoidModifyFn<Val> | ICursorArg<Val>): Promise<void>;
121
+ cursor<Rtn = DbRecordResult<Row>, Val extends Row = Row>(fn: ValueModifyFn<Val, Rtn> | ICursorResultArg<Val, Rtn>, returns: true): Promise<Rtn[]>;
122
+ batchWrite<R = any>(fn: (writer: IDataWriter<Row, NativeTarget>) => Promise<void | R>, rollbackOnError?: boolean): Promise<R>;
123
+ protected changeByPk({ pk, record, fn, requiredPk, getOld, requiredOld, saveMapper, getMapper }: {
124
+ pk?: IDbQuery;
125
+ record?: DbRecord<Partial<Row>>;
126
+ fn: (store: IDBObjectStore, pk: DbQuery, newValue: any, oldValue: any, keyPath?: string | string[]) => void | [Row, DbQuery?] | Promise<void | [Row, DbQuery?]>;
127
+ requiredPk?: boolean;
128
+ getOld?: boolean;
129
+ requiredOld?: boolean;
130
+ saveMapper?: SaveRowMapper<any, any>;
131
+ getMapper?: GetRowMapper<any, any>;
132
+ }): any;
133
+ }
134
+
135
+ declare class DbIterator<T> extends DataOperationBase implements IDbIterator<T> {
136
+ direction: IDBCursorDirection;
137
+ query: IDbQuery;
138
+ writable: boolean;
139
+ parser: IDbIteratorParser;
140
+ endsWithNull: boolean;
141
+ preSkip?: number;
142
+ startKey?: IDBValidKey;
143
+ startPrimaryKey?: IDBValidKey;
144
+ constructor(schema: IValidDataOperationSchema<any>, db?: IIDbPro, option?: IDbIteratorOption<T>);
145
+ [Symbol.asyncIterator](): AsyncIterator<T>;
146
+ }
147
+
148
+ declare class DbMap<K extends StrOrNum = StrOrNum, V = any, Tar extends OperationTarget = OperationTarget> extends DataOperationBase implements IDbMap<K, V, Tar> {
149
+ get size(): Promise<number>;
150
+ delete(key: K): Promise<void>;
151
+ batch<R = any, T extends V = V>(fn: (map: IDbMap<K, T, NativeTarget>) => (Promise<R> | R)): Promise<R>;
152
+ asStore(): IDataReader<V, Tar>;
153
+ asStore(writable: true): IDataWriter<V, Tar>;
154
+ entries<T extends V = V>(): AsyncIterable<[K, T]>;
155
+ get<T extends V = V>(key: K, defaultValue?: T): Promise<T | undefined>;
156
+ getMany<T extends V = V>(keys: K[]): Promise<(T | undefined)[]>;
157
+ has(key: K): Promise<boolean>;
158
+ keys(): AsyncIterable<K>;
159
+ set<T extends V = V>(key: K, value: T): Promise<void>;
160
+ setMany<T extends V = V>(values: [K, V][]): Promise<void>;
161
+ values<T extends V = V>(): AsyncIterable<T>;
162
+ }
163
+
164
+ declare function dbStore<T = any, RT extends IDataWriter<T, IInfoTarget> = IDataWriter<T, IInfoTarget>>(schema: StoreSchema): RT;
165
+ declare function dbStore<T = any, RT extends IDataWriter<T, IInfoTarget> = IDataWriter<T, IInfoTarget>>(schema: IDataOperationSchema): RT;
166
+ declare function dbStore<T = any, RT extends IDataWriter<T, IInfoTarget> = IDataWriter<T, IInfoTarget>>(store: StoreSchema, index: IndexSchema): RT;
167
+ declare function dbMap<K extends StrOrNum = StrOrNum, V = any>(storeName?: string, defaultData?: RequiredDbNoneKeyPathRecord<V, K>[]): IDbMap<K, V, IInfoTarget>;
168
+ declare function dbMap<K extends StrOrNum = StrOrNum, V = any>(defaultData?: RequiredDbNoneKeyPathRecord<V, K>[], storeName?: string): IDbMap<K, V, IInfoTarget>;
169
+ declare function dbStores<S1 = any, S2 = any, S3 = any, S4 = any, S5 = any, Rtn extends IDataOperators = IDataOperators<S1, S2, S3, S4, S5>>(schemas: DataOperationSchema[]): Rtn;
170
+ /**
171
+ * 释放默认数据库实例(如果存在)
172
+ */
173
+ declare function releaseDefaultDB(): void;
174
+
175
+ declare class IDbPro implements IIDbPro {
176
+ #private;
177
+ constructor(schema: DBSchema, skipPreOpenValidation?: true);
178
+ /**
179
+ * 默认实例
180
+ */
181
+ static get defaultDb(): IIDbPro;
182
+ get initialized(): boolean;
183
+ get schema(): IDbSchema;
184
+ get storeNames(): string[];
185
+ get factory(): IDataOperatorFactory;
186
+ /**
187
+ * 释放默认数据库实例(如果存在)
188
+ */
189
+ static releaseDefaultDB(): void;
190
+ /**
191
+ * 从已经存在的`name`数据库中打开
192
+ * @warning 该方法仅用于不需要修改原有数据库结构的场景
193
+ * - 如果需要修改,请使用 `generateDbSchema()` 从现有数据库生成配置,且适当修改后重新打开
194
+ * @param name
195
+ */
196
+ static openExistDb(name: string): Promise<IIDbPro>;
197
+ static store<T = any, RT extends IDataWriter<T> = IDataWriter<T>>(store: StoreSchema): RT;
198
+ static store<T = any, RT extends IDataWriter<T> = IDataWriter<T>>(operation: IDataOperationSchema): RT;
199
+ static store<T = any, RT extends IDataWriter<T> = IDataWriter<T>>(store: StoreSchema, index: IndexSchema): RT;
200
+ static stores<S1 = any, S2 = any, S3 = any, S4 = any, S5 = any, Rtn extends IDataOperators = IDataOperators<S1, S2, S3, S4, S5>>(schemas: DataOperationSchema[]): IDataOperators<Rtn>;
201
+ static map<K extends StrOrNum = StrOrNum, V = any>(storeName?: string, defaultData?: (IDbNoneKeyPathRecord<V, K> | [V, K])[]): IDbMap<K, V, IInfoTarget>;
202
+ static map<K extends StrOrNum = StrOrNum, V = any>(defaultData?: (IDbNoneKeyPathRecord<V, K> | [V, K])[], storeName?: string): IDbMap<K, V, IInfoTarget>;
203
+ openNativeDb(): Promise<IDBDatabase>;
204
+ store<T = any, RT extends IDataWriter<T, IInfoTarget> = IDataWriter<T, IInfoTarget>>(store: StoreSchema): RT;
205
+ store<T = any, RT extends IDataWriter<T, IInfoTarget> = IDataWriter<T, IInfoTarget>>(operation: IDataOperationSchema): RT;
206
+ store<T = any, RT extends IDataWriter<T, IInfoTarget> = IDataWriter<T, IInfoTarget>>(store: StoreSchema, index: IndexSchema): RT;
207
+ stores<S1 = any, S2 = any, S3 = any, S4 = any, S5 = any, Rtn extends IDataOperators = IDataOperators<S1, S2, S3, S4, S5>>(schemas: DataOperationSchema[]): Rtn;
208
+ initSchema(): IDbSchema;
209
+ traceSchema(showFn?: boolean): Promise<void>;
210
+ map<K extends StrOrNum = StrOrNum, V = any>(storeName?: string, defaultData?: RequiredDbNoneKeyPathRecord<V, K>[]): IDbMap<K, V, IInfoTarget>;
211
+ map<K extends StrOrNum = StrOrNum, V = any>(defaultData?: RequiredDbNoneKeyPathRecord<V, K>[], storeName?: string): IDbMap<K, V, IInfoTarget>;
212
+ export(): Promise<Record<string, any[]>>;
213
+ import(data: Record<string, any[]>, returns?: false, use?: ImportUse): Promise<void>;
214
+ import(data: Record<string, any[]>, returns?: true, use?: ImportUse): Promise<Record<string, any[]>>;
215
+ getStoreSchema(name: string): IStoreSchema;
216
+ }
217
+
218
+ declare function parseIDbQuery(query: IDbQuery | IDBKeyRange | undefined | null): IDBValidKey | IDBKeyRange | null | undefined;
219
+ declare function isIDbQuery(query: any): boolean;
220
+
221
+ declare class StoreUpgradeable<T = any> implements IStoreUpgradeable<T> {
222
+ #private;
223
+ readonly upgradeContext: IUpgradeContext;
224
+ readonly storeSchema: IStoreSchema;
225
+ readonly nativeStore: IDBObjectStore;
226
+ constructor(upgradeContext: IUpgradeContext, storeSchema: IStoreSchema, nativeStore: IDBObjectStore);
227
+ get writer(): IDataWriter<T>;
228
+ add(versionBounds: IDbVersionBounds, values: DbRecord<T>[], returns?: false): Promise<void>;
229
+ add(versionBounds: IDbVersionBounds, values: DbRecord<T>[], returns: true): Promise<DbRecord<T>>;
230
+ addOrChange(versionBounds: IDbVersionBounds, values: DbRecord<T>[], returns?: false): Promise<void>;
231
+ addOrChange(versionBounds: IDbVersionBounds, values: DbRecord<T>[], returns: true): Promise<DbRecord<T>[]>;
232
+ call<R = any>(versionBounds: IDbVersionBounds, fn: (store: IDataWriter, upgradeContext?: IUpgradeContext) => (Promise<R> | R)): Promise<R>;
233
+ replace(versionBounds: IDbVersionBounds, values: DbRecord<T>[], returns?: false): Promise<void>;
234
+ replace(versionBounds: IDbVersionBounds, values: DbRecord<T>[], returns: true): Promise<DbRecord<T>[]>;
235
+ }
236
+
237
+ declare class UpgradeContext implements IUpgradeContext {
238
+ #private;
239
+ readonly database: IDBDatabase;
240
+ readonly newVersion: number;
241
+ readonly oldVersion: number;
242
+ readonly dbSchema: Readonly<IDbSchema>;
243
+ readonly transaction: IDBTransaction;
244
+ constructor(args: IUpgradeContextArgs);
245
+ deleteStoreIfExists(storeName: string): void;
246
+ destroy(): void;
247
+ store<T = any>(storeName: string): IStoreUpgradeable<T>;
248
+ versionIn({ oldMin, oldMax, newMax, newMin }: IDbVersionBounds): boolean;
249
+ }
250
+
251
+ declare const validateSchemaWithDefaults: IDbSchema['validateSchemaWithDefaults'];
252
+
253
+ /**
254
+ * 版本差异验证器
255
+ * @param context
256
+ */
257
+ declare const versionDiffValidate: VersionValidateFn;
258
+
259
+ declare const versionSameValidate: VersionValidateFn;
260
+
261
+ declare function generateDbSchema(db: string, option?: IGenerateOption<undefined | false>): Promise<IDbSchema>;
262
+ declare function generateDbSchema(db: string, option: IGenerateOption<true | number>): Promise<string>;
263
+
264
+ export { DataOperationBase, DataOperators, DataReader, DataWriter, DbIterator, DbMap, dbMap, dbStore, dbStores, generateDbSchema, IDbPro, isIDbQuery, parseIDbQuery, releaseDefaultDB, StoreUpgradeable, UpgradeContext, validateSchemaWithDefaults, versionDiffValidate, versionSameValidate };
265
+ export type { IOpenCursorArg };
@@ -1,34 +1,13 @@
1
- import { isObject, copyFields, isFunction, deepFreeze, isNumber, asyncMap, isString, asyncForEach, isBoolean, destroyRecords, destroy, logJson, toJson, copyObject } from "gs-base";
2
- import { isDbQueryOrNull, requestDbResult, Bool, findExistDb, openDb, readTx, DefaultDbName, DefaultStorageStoreName } from "gs-idb-basic";
3
- const Save = Symbol("save"), Delete = Symbol("delete"), DbIteratorParsers = Object.freeze({
4
- key: ({ primaryKey: value }) => ({ value }),
5
- value: ({ value }) => ({ value }),
6
- keyValue: ({ primaryKey: key, value }) => ({ value: [key, value] })
7
- });
8
- function parseDbNoneKeyPathRecord(record) {
9
- if (Array.isArray(record))
10
- return { key: record[1], value: record[0] };
11
- if ("value" in record) {
12
- const { key, value } = record;
13
- return { key, value };
14
- }
15
- throw new Error(`not include value in invalid DBRecord:${JSON.stringify(record)}`);
16
- }
17
- const Break = Symbol("break"), Finished = Symbol("finished"), Continue = Symbol("continue"), ContinueKey = Symbol("continue key"), NextKey = Symbol("next key"), ContinuePrimaryKey = Symbol("continue primary key"), NextPrimaryKey = Symbol("next primary key");
18
- function isNativeTarget(target) {
19
- return target instanceof IDBObjectStore || target instanceof IDBIndex;
20
- }
21
- const defaultStoreSchemaTemplate = Object.freeze({
22
- keyPath: "id",
23
- autoIncrement: !0,
24
- addedTimeField: !0,
25
- updatedTimeField: !0
26
- }), defaultSpecialFields = Object.freeze({
27
- addedTimeField: "added_at",
28
- softDeletedField: "deleted",
29
- updatedCountField: "updated_count",
30
- updatedTimeField: "updated_at"
31
- }), toNum = (v) => v instanceof Date ? v.getTime() : v;
1
+ import { isNativeTarget, Save, Delete, ContinuePrimaryKey, ContinueKey, Break, Finished, NextKey, NextPrimaryKey, DbIteratorParsers, Continue, parseDbNoneKeyPathRecord, defaultStoreSchemaTemplate, defaultSpecialFields } from './type.mjs';
2
+ import { isObject, isFunction, isNumber, isString, isBoolean } from 'gs-base/types';
3
+ import { requestDbResult } from 'gs-idb-basic/store';
4
+ import { isDbQueryOrNull, Bool } from 'gs-idb-basic/type';
5
+ import { copyFields, deepFreeze, asyncMap, asyncForEach, destroyRecords, destroy, copyObject } from 'gs-base/basic';
6
+ import { logJson, toJson } from 'gs-base/json';
7
+ import { readTx } from 'gs-idb-basic/tx';
8
+ import { findExistDb, openDb } from 'gs-idb-basic/db';
9
+ import { DefaultDbName, DefaultStorageStoreName } from 'gs-idb-basic/storage';
10
+ const toNum = (v) => v instanceof Date ? v.getTime() : v;
32
11
  function parseIDbQuery(query) {
33
12
  if (isDbQueryOrNull(query) || !isObject(query))
34
13
  return query;
@@ -1048,7 +1027,7 @@ async function upgradeDb(dbSchema, database, e, request) {
1048
1027
  function validateDataOperationSchema(schema, dbSchema) {
1049
1028
  return Object.isFrozen(dbSchema) ? frozenValidate(schema) : initValidate(schema, dbSchema);
1050
1029
  }
1051
- function frozenValidate(schema, dbSchema) {
1030
+ function frozenValidate(schema) {
1052
1031
  let { store, index } = schema;
1053
1032
  const target = { store: isString(store) ? store : store.name };
1054
1033
  return index && (target.index = isString(index) ? index : index.name), {
@@ -1268,36 +1247,25 @@ function generateRoot(db, specialFields) {
1268
1247
  }
1269
1248
  });
1270
1249
  }
1271
- var generateDbSchema$1 = /* @__PURE__ */ Object.freeze({ __proto__: null, generateDbSchema });
1250
+ var generateDbSchema$1 = /* @__PURE__ */ Object.freeze({
1251
+ __proto__: null,
1252
+ generateDbSchema
1253
+ });
1272
1254
  export {
1273
- Break,
1274
- Continue,
1275
- ContinueKey,
1276
- ContinuePrimaryKey,
1277
1255
  DataOperationBase,
1278
1256
  DataOperators,
1279
1257
  DataReader,
1280
1258
  DataWriter,
1281
1259
  DbIterator,
1282
- DbIteratorParsers,
1283
1260
  DbMap,
1284
- Delete,
1285
- Finished,
1286
1261
  IDbPro,
1287
- NextKey,
1288
- NextPrimaryKey,
1289
- Save,
1290
1262
  StoreUpgradeable,
1291
1263
  UpgradeContext,
1292
1264
  dbMap,
1293
1265
  dbStore,
1294
1266
  dbStores,
1295
- defaultSpecialFields,
1296
- defaultStoreSchemaTemplate,
1297
1267
  generateDbSchema,
1298
1268
  isIDbQuery,
1299
- isNativeTarget,
1300
- parseDbNoneKeyPathRecord,
1301
1269
  parseIDbQuery,
1302
1270
  releaseDefaultDB,
1303
1271
  validateSchemaWithDefaults,