@kubun/db-adapter 0.2.0 → 0.3.1

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/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { AbstractPostgresAdapter } from './postgres.js';
2
- export { AbstractSQLiteAdapter } from './sqlite.js';
3
- export type { AbstractAdapter, Adapter } from './types.js';
1
+ export { AbstractPostgresAdapter, type PostgresTypes } from './postgres.js';
2
+ export { AbstractSQLiteAdapter, type SQLiteTypes } from './sqlite.js';
3
+ export type { AbstractAdapter, Adapter, AdapterTypes } from './types.js';
4
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAA;AACvD,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAA;AACnD,YAAY,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,KAAK,aAAa,EAAE,MAAM,eAAe,CAAA;AAC3E,OAAO,EAAE,qBAAqB,EAAE,KAAK,WAAW,EAAE,MAAM,aAAa,CAAA;AACrE,YAAY,EAAE,eAAe,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA"}
package/lib/postgres.d.ts CHANGED
@@ -1,8 +1,15 @@
1
- import type { AbstractAdapter, ColumnTypes, Functions } from './types.js';
2
- export declare class AbstractPostgresAdapter implements AbstractAdapter {
1
+ import type { AbstractAdapter, AdapterTypes, ColumnTypes, Functions } from './types.js';
2
+ export type PostgresTypes = {
3
+ Binary: Uint8Array;
4
+ JSON: unknown;
5
+ Timestamp: string;
6
+ };
7
+ export declare class AbstractPostgresAdapter<T extends AdapterTypes = PostgresTypes> implements AbstractAdapter<T> {
3
8
  functions: Functions;
4
9
  types: ColumnTypes;
5
- encodeBinary(value: Uint8Array): Uint8Array;
6
- encodeJSON(value: unknown): any;
10
+ encodeBinary(value: Uint8Array): Uint8Array<ArrayBufferLike>;
11
+ encodeJSON(value: unknown): unknown;
12
+ encodeTimestamp(value: Date): string;
13
+ decodeTimestamp(value: string): Date;
7
14
  }
8
15
  //# sourceMappingURL=postgres.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"postgres.d.ts","sourceRoot":"","sources":["../src/postgres.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAEzE,qBAAa,uBAAwB,YAAW,eAAe;IAC7D,SAAS,EAEJ,SAAS,CAAA;IAEd,KAAK,EAOA,WAAW,CAAA;IAEhB,YAAY,CAAC,KAAK,EAAE,UAAU,GAAG,UAAU;IAK3C,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,GAAG;CAGhC"}
1
+ {"version":3,"file":"postgres.d.ts","sourceRoot":"","sources":["../src/postgres.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAEvF,MAAM,MAAM,aAAa,GAAG;IAC1B,MAAM,EAAE,UAAU,CAAA;IAClB,IAAI,EAAE,OAAO,CAAA;IACb,SAAS,EAAE,MAAM,CAAA;CAClB,CAAA;AAED,qBAAa,uBAAuB,CAAC,CAAC,SAAS,YAAY,GAAG,aAAa,CACzE,YAAW,eAAe,CAAC,CAAC,CAAC;IAE7B,SAAS,EAEJ,SAAS,CAAA;IAEd,KAAK,EAOA,WAAW,CAAA;IAEhB,YAAY,CAAC,KAAK,EAAE,UAAU;IAI9B,UAAU,CAAC,KAAK,EAAE,OAAO;IAIzB,eAAe,CAAC,KAAK,EAAE,IAAI;IAI3B,eAAe,CAAC,KAAK,EAAE,MAAM;CAG9B"}
package/lib/postgres.js CHANGED
@@ -13,8 +13,13 @@ export class AbstractPostgresAdapter {
13
13
  encodeBinary(value) {
14
14
  return value;
15
15
  }
16
- // biome-ignore lint/suspicious/noExplicitAny: JSON type
17
16
  encodeJSON(value) {
18
17
  return value;
19
18
  }
19
+ encodeTimestamp(value) {
20
+ return value.toISOString();
21
+ }
22
+ decodeTimestamp(value) {
23
+ return new Date(value);
24
+ }
20
25
  }
package/lib/sqlite.d.ts CHANGED
@@ -1,8 +1,15 @@
1
- import type { AbstractAdapter, ColumnTypes, Functions } from './types.js';
2
- export declare class AbstractSQLiteAdapter<BinaryType = Uint8Array, JSONType = string> implements AbstractAdapter<BinaryType, JSONType> {
1
+ import type { AbstractAdapter, AdapterTypes, ColumnTypes, Functions } from './types.js';
2
+ export type SQLiteTypes = {
3
+ Binary: Uint8Array;
4
+ JSON: string;
5
+ Timestamp: number;
6
+ };
7
+ export declare class AbstractSQLiteAdapter<T extends AdapterTypes = SQLiteTypes> implements AbstractAdapter<T> {
3
8
  functions: Functions;
4
9
  types: ColumnTypes;
5
- encodeBinary(value: Uint8Array): BinaryType;
6
- encodeJSON(value: unknown): JSONType;
10
+ encodeBinary(value: Uint8Array): Uint8Array<ArrayBufferLike>;
11
+ encodeJSON(value: unknown): string;
12
+ encodeTimestamp(value: Date): number;
13
+ decodeTimestamp(value: number): Date;
7
14
  }
8
15
  //# sourceMappingURL=sqlite.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"sqlite.d.ts","sourceRoot":"","sources":["../src/sqlite.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAEzE,qBAAa,qBAAqB,CAAC,UAAU,GAAG,UAAU,EAAE,QAAQ,GAAG,MAAM,CAC3E,YAAW,eAAe,CAAC,UAAU,EAAE,QAAQ,CAAC;IAEhD,SAAS,EAEJ,SAAS,CAAA;IAEd,KAAK,EAMA,WAAW,CAAA;IAEhB,YAAY,CAAC,KAAK,EAAE,UAAU,GAAG,UAAU;IAI3C,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,QAAQ;CAGrC"}
1
+ {"version":3,"file":"sqlite.d.ts","sourceRoot":"","sources":["../src/sqlite.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAEvF,MAAM,MAAM,WAAW,GAAG;IACxB,MAAM,EAAE,UAAU,CAAA;IAClB,IAAI,EAAE,MAAM,CAAA;IACZ,SAAS,EAAE,MAAM,CAAA;CAClB,CAAA;AAED,qBAAa,qBAAqB,CAAC,CAAC,SAAS,YAAY,GAAG,WAAW,CACrE,YAAW,eAAe,CAAC,CAAC,CAAC;IAE7B,SAAS,EAEJ,SAAS,CAAA;IAEd,KAAK,EAMA,WAAW,CAAA;IAEhB,YAAY,CAAC,KAAK,EAAE,UAAU;IAI9B,UAAU,CAAC,KAAK,EAAE,OAAO;IAIzB,eAAe,CAAC,KAAK,EAAE,IAAI;IAK3B,eAAe,CAAC,KAAK,EAAE,MAAM;CAI9B"}
package/lib/sqlite.js CHANGED
@@ -16,4 +16,12 @@ export class AbstractSQLiteAdapter {
16
16
  encodeJSON(value) {
17
17
  return JSON.stringify(value);
18
18
  }
19
+ encodeTimestamp(value) {
20
+ // SQLite timestamps are stored in seconds
21
+ return Math.floor(value.getTime() / 1000);
22
+ }
23
+ decodeTimestamp(value) {
24
+ // SQLite timestamps are stored in seconds
25
+ return new Date(value * 1000);
26
+ }
19
27
  }
package/lib/types.d.ts CHANGED
@@ -9,13 +9,20 @@ export type ColumnTypes = {
9
9
  export type Functions = {
10
10
  now: string | RawBuilder<string>;
11
11
  };
12
- export type AbstractAdapter<BinaryType = Uint8Array, JSONType = any> = {
12
+ export type AdapterTypes = {
13
+ Binary: unknown;
14
+ JSON: unknown;
15
+ Timestamp: unknown;
16
+ };
17
+ export type AbstractAdapter<T extends AdapterTypes = AdapterTypes> = {
13
18
  functions: Functions;
14
19
  types: ColumnTypes;
15
- encodeBinary(value: Uint8Array): BinaryType;
16
- encodeJSON(value: unknown): JSONType;
20
+ encodeBinary(value: Uint8Array): T['Binary'];
21
+ encodeJSON(value: unknown): T['JSON'];
22
+ encodeTimestamp(value: Date): T['Timestamp'];
23
+ decodeTimestamp(value: T['Timestamp']): Date;
17
24
  };
18
- export type Adapter<BinaryType = Uint8Array, JSONType = any> = AbstractAdapter<BinaryType, JSONType> & {
25
+ export type Adapter<T extends AdapterTypes = AdapterTypes> = AbstractAdapter<T> & {
19
26
  dialect: Dialect;
20
27
  };
21
28
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAA;AAEjE,MAAM,MAAM,WAAW,GAAG;IACxB,MAAM,EAAE,cAAc,CAAA;IACtB,IAAI,EAAE,cAAc,CAAA;IACpB,IAAI,EAAE,cAAc,CAAA;IACpB,SAAS,EAAE,cAAc,CAAA;IACzB,IAAI,EAAE,cAAc,CAAA;CACrB,CAAA;AAED,MAAM,MAAM,SAAS,GAAG;IACtB,GAAG,EAAE,MAAM,GAAG,UAAU,CAAC,MAAM,CAAC,CAAA;CACjC,CAAA;AAGD,MAAM,MAAM,eAAe,CAAC,UAAU,GAAG,UAAU,EAAE,QAAQ,GAAG,GAAG,IAAI;IACrE,SAAS,EAAE,SAAS,CAAA;IACpB,KAAK,EAAE,WAAW,CAAA;IAClB,YAAY,CAAC,KAAK,EAAE,UAAU,GAAG,UAAU,CAAA;IAC3C,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,QAAQ,CAAA;CACrC,CAAA;AAGD,MAAM,MAAM,OAAO,CAAC,UAAU,GAAG,UAAU,EAAE,QAAQ,GAAG,G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}
package/lib/types.js CHANGED
@@ -1,2 +1 @@
1
- // biome-ignore lint/suspicious/noExplicitAny: JSON type
2
1
  export { };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubun/db-adapter",
3
- "version": "0.2.0",
3
+ "version": "0.3.1",
4
4
  "license": "see LICENSE.md",
5
5
  "keywords": [],
6
6
  "type": "module",