@ez4/database 0.36.0 → 0.38.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.
Files changed (51) hide show
  1. package/dist/errors/engine.d.ts +8 -1
  2. package/dist/errors/indexes.d.ts +2 -2
  3. package/dist/errors/relations.d.ts +2 -2
  4. package/dist/errors/scalability.d.ts +8 -1
  5. package/dist/errors/table.d.ts +8 -1
  6. package/dist/library.cjs +175 -150
  7. package/dist/library.d.ts +2 -6
  8. package/dist/library.mjs +170 -145
  9. package/dist/main.cjs +10 -7
  10. package/dist/main.d.ts +9 -7
  11. package/dist/main.mjs +7 -4
  12. package/dist/metadata/engine.d.ts +4 -3
  13. package/dist/metadata/handler.d.ts +3 -3
  14. package/dist/metadata/indexes.d.ts +4 -3
  15. package/dist/metadata/relations.d.ts +4 -3
  16. package/dist/metadata/scalability.d.ts +4 -3
  17. package/dist/metadata/schema.d.ts +3 -2
  18. package/dist/metadata/service.d.ts +4 -3
  19. package/dist/metadata/stream.d.ts +4 -3
  20. package/dist/metadata/table.d.ts +4 -3
  21. package/dist/metadata/types.d.ts +70 -0
  22. package/dist/services/contract.d.ts +4 -1
  23. package/dist/services/engine.d.ts +1 -6
  24. package/dist/services/handler.d.ts +8 -0
  25. package/dist/services/incoming.d.ts +7 -0
  26. package/dist/services/indexes.d.ts +1 -9
  27. package/dist/services/insensitive.d.ts +1 -7
  28. package/dist/services/listener.d.ts +8 -0
  29. package/dist/services/lock.d.ts +1 -7
  30. package/dist/services/order.d.ts +2 -14
  31. package/dist/services/pagination.d.ts +1 -7
  32. package/dist/services/parameters.d.ts +1 -7
  33. package/dist/services/request.d.ts +13 -0
  34. package/dist/services/scalability.d.ts +6 -0
  35. package/dist/services/streams.d.ts +11 -1
  36. package/dist/services/transaction.d.ts +1 -7
  37. package/dist/types/index.d.ts +9 -0
  38. package/dist/types/mode.d.ts +42 -0
  39. package/dist/types/order.d.ts +7 -0
  40. package/package.json +6 -6
  41. package/dist/metadata/utils.d.ts +0 -9
  42. package/dist/services/common.d.ts +0 -25
  43. package/dist/types/engine.d.ts +0 -15
  44. package/dist/types/handler.d.ts +0 -6
  45. package/dist/types/indexes.d.ts +0 -6
  46. package/dist/types/relations.d.ts +0 -9
  47. package/dist/types/scalability.d.ts +0 -4
  48. package/dist/types/schema.d.ts +0 -2
  49. package/dist/types/service.d.ts +0 -13
  50. package/dist/types/stream.d.ts +0 -11
  51. package/dist/types/table.d.ts +0 -11
@@ -0,0 +1,70 @@
1
+ import type { FunctionSignature, ServiceListener } from '@ez4/common/library';
2
+ import type { LinkedVariables, ServiceMetadata } from '@ez4/project/library';
3
+ import type { ArchitectureType, RuntimeType } from '@ez4/project';
4
+ import type { ObjectSchema } from '@ez4/schema';
5
+ import type { ParametersMode, TransactionMode, InsensitiveMode, PaginationMode, OrderMode, LockMode } from '../types/mode';
6
+ import type { Index } from '../types/index';
7
+ export declare const ServiceType = "@ez4/database";
8
+ export type DatabaseService = Omit<ServiceMetadata, 'variables' | 'services'> & Required<Pick<ServiceMetadata, 'variables' | 'services'>> & {
9
+ type: typeof ServiceType;
10
+ scalability?: DatabaseScalability;
11
+ engine: DatabaseEngine;
12
+ tables: DatabaseTable[];
13
+ name: string;
14
+ };
15
+ export type TableSchema = ObjectSchema;
16
+ export type StreamHandler = FunctionSignature;
17
+ export type DatabaseEngine = {
18
+ parametersMode: ParametersMode;
19
+ transactionMode: TransactionMode;
20
+ insensitiveMode: InsensitiveMode;
21
+ paginationMode: PaginationMode;
22
+ orderMode: OrderMode;
23
+ lockMode: LockMode;
24
+ name: string;
25
+ };
26
+ export type DatabaseScalability = {
27
+ minCapacity: number;
28
+ maxCapacity: number;
29
+ };
30
+ export type TableIndex = {
31
+ name: string;
32
+ columns: string[];
33
+ type: Index;
34
+ };
35
+ export type TableRelation = {
36
+ sourceTable: string;
37
+ sourceColumn: string;
38
+ sourceIndex?: Index;
39
+ targetColumn: string;
40
+ targetAlias: string;
41
+ targetIndex?: Index;
42
+ };
43
+ export type DatabaseTable = {
44
+ name: string;
45
+ schema: TableSchema;
46
+ relations?: TableRelation[];
47
+ indexes: TableIndex[];
48
+ stream?: TableStream;
49
+ };
50
+ export type TableStream = {
51
+ listener?: ServiceListener;
52
+ handler: StreamHandler;
53
+ variables?: LinkedVariables;
54
+ architecture?: ArchitectureType;
55
+ runtime?: RuntimeType;
56
+ logRetention?: number;
57
+ timeout?: number;
58
+ memory?: number;
59
+ };
60
+ export declare const isDatabaseService: (service: ServiceMetadata) => service is DatabaseService;
61
+ export declare const createDatabaseService: (name: string) => {
62
+ variables: {};
63
+ services: {};
64
+ type: "@ez4/database";
65
+ name: string;
66
+ context: Record<string, import("@ez4/project/library").LinkedContext>;
67
+ scalability?: DatabaseScalability | null | undefined;
68
+ engine?: DatabaseEngine | null | undefined;
69
+ tables?: DatabaseTable[] | null | undefined;
70
+ };
@@ -1,6 +1,9 @@
1
1
  import type { Service as CommonService } from '@ez4/common';
2
- import type { TableStreamHandler, TableStreamIncoming, TableStreamListener, TableStreamRequest } from './common';
3
2
  import type { DatabaseScalability } from './scalability';
3
+ import type { TableStreamIncoming } from './incoming';
4
+ import type { TableStreamListener } from './listener';
5
+ import type { TableStreamHandler } from './handler';
6
+ import type { TableStreamRequest } from './request';
4
7
  import type { TableRelations } from './relations';
5
8
  import type { DatabaseEngine } from './engine';
6
9
  import type { TableIndexes } from './indexes';
@@ -1,10 +1,5 @@
1
- import type { ParametersMode } from './parameters';
2
- import type { TransactionMode } from './transaction';
3
- import type { InsensitiveMode } from './insensitive';
4
- import type { PaginationMode } from './pagination';
1
+ import type { ParametersMode, TransactionMode, InsensitiveMode, PaginationMode, OrderMode, LockMode } from '../types/mode';
5
2
  import type { Database } from './contract';
6
- import type { OrderMode } from './order';
7
- import type { LockMode } from './lock';
8
3
  /**
9
4
  * Database engine.
10
5
  */
@@ -0,0 +1,8 @@
1
+ import type { Service as CommonService } from '@ez4/common';
2
+ import type { TableStreamIncoming } from './incoming';
3
+ import type { TableSchema } from './schemas';
4
+ import type { Database } from './contract';
5
+ /**
6
+ * Table stream handler.
7
+ */
8
+ export type TableStreamHandler<T extends TableSchema> = (request: TableStreamIncoming<T>, context: CommonService.Context<Database.Service>) => Promise<void> | void;
@@ -0,0 +1,7 @@
1
+ import type { TableStreamRequest } from './request';
2
+ import type { StreamAnyChange } from './streams';
3
+ import type { TableSchema } from './schemas';
4
+ /**
5
+ * Incoming table stream event.
6
+ */
7
+ export type TableStreamIncoming<T extends TableSchema> = StreamAnyChange<T> & TableStreamRequest;
@@ -2,19 +2,11 @@ import type { ArrayRest, IsArrayEmpty } from '@ez4/utils';
2
2
  import type { DatabaseTable, DatabaseTables } from './table';
3
3
  import type { TableSchema } from './schemas';
4
4
  import type { Database } from './contract';
5
+ import type { Index } from '../types';
5
6
  /**
6
7
  * Database table indexes.
7
8
  */
8
9
  export type TableIndexes = {};
9
- /**
10
- * All supported index types.
11
- */
12
- export declare const enum Index {
13
- Primary = "primary",
14
- Secondary = "secondary",
15
- Unique = "unique",
16
- TTL = "ttl"
17
- }
18
10
  /**
19
11
  * Given an index name `T`, it produces the decomposed index names.
20
12
  */
@@ -1,11 +1,5 @@
1
+ import type { InsensitiveMode } from '../types/mode';
1
2
  import type { DatabaseEngine, EngineUtils } from './engine';
2
- /**
3
- * Insensitive mode.
4
- */
5
- export declare const enum InsensitiveMode {
6
- Unsupported = "unsupported",
7
- Enabled = "enabled"
8
- }
9
3
  /**
10
4
  * Insensitive mode utils.
11
5
  */
@@ -0,0 +1,8 @@
1
+ import type { Service as CommonService } from '@ez4/common';
2
+ import type { TableStreamIncoming } from './incoming';
3
+ import type { TableSchema } from './schemas';
4
+ import type { Database } from './contract';
5
+ /**
6
+ * Table stream listener.
7
+ */
8
+ export type TableStreamListener<T extends TableSchema> = (event: CommonService.AnyEvent<TableStreamIncoming<T>>, context: CommonService.Context<Database.Service>) => Promise<void> | void;
@@ -1,11 +1,5 @@
1
+ import type { LockMode } from '../types/mode';
1
2
  import type { TableMetadata } from './table';
2
- /**
3
- * Lock mode.
4
- */
5
- export declare const enum LockMode {
6
- Unsupported = "unsupported",
7
- Supported = "supported"
8
- }
9
3
  /**
10
4
  * Lock mode utils.
11
5
  */
@@ -1,20 +1,8 @@
1
+ import type { OrderMode } from '../types/mode';
2
+ import type { Order } from '../types/order';
1
3
  import type { DecomposeIndexName } from './indexes';
2
4
  import type { TableMetadata } from './table';
3
5
  import type { Database } from './contract';
4
- /**
5
- * Query order types.
6
- */
7
- export declare const enum Order {
8
- Asc = "asc",
9
- Desc = "desc"
10
- }
11
- /**
12
- * Order mode.
13
- */
14
- export declare const enum OrderMode {
15
- IndexColumns = "index",
16
- AnyColumns = "any"
17
- }
18
6
  /**
19
7
  * Order mode utils.
20
8
  */
@@ -1,11 +1,5 @@
1
+ import type { PaginationMode } from '../types/mode';
1
2
  import type { DatabaseEngine, EngineUtils } from './engine';
2
- /**
3
- * Pagination mode.
4
- */
5
- export declare const enum PaginationMode {
6
- Cursor = "cursor",
7
- Offset = "offset"
8
- }
9
3
  /**
10
4
  * Pagination mode utils.
11
5
  */
@@ -1,12 +1,6 @@
1
+ import type { ParametersMode } from '../types/mode';
1
2
  import type { EngineUtils } from './engine';
2
3
  import type { Database } from './contract';
3
- /**
4
- * Parameters mode.
5
- */
6
- export declare const enum ParametersMode {
7
- NameAndIndex = "both",
8
- OnlyIndex = "index"
9
- }
10
4
  /**
11
5
  * Parameters mode utils.
12
6
  */
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Table stream request.
3
+ */
4
+ export type TableStreamRequest = {
5
+ /**
6
+ * Unique identifier for the request.
7
+ */
8
+ readonly requestId: string;
9
+ /**
10
+ * Unique identifier across multiple services.
11
+ */
12
+ readonly traceId?: string;
13
+ };
@@ -2,6 +2,12 @@
2
2
  * Database scalability configuration.
3
3
  */
4
4
  export interface DatabaseScalability {
5
+ /**
6
+ * Minimum scalability threshold.
7
+ */
5
8
  minCapacity: number;
9
+ /**
10
+ * Maximum scalability threshold.
11
+ */
6
12
  maxCapacity: number;
7
13
  }
@@ -1,5 +1,7 @@
1
+ import type { ArchitectureType, RuntimeType } from '@ez4/project';
1
2
  import type { LinkedVariables } from '@ez4/project/library';
2
- import type { TableStreamHandler, TableStreamListener } from './common';
3
+ import type { TableStreamListener } from './listener';
4
+ import type { TableStreamHandler } from './handler';
3
5
  import type { TableSchema } from './schemas';
4
6
  /**
5
7
  * Database table stream.
@@ -17,6 +19,14 @@ export interface TableStream<T extends TableSchema> {
17
19
  * Variables associated to the handler.
18
20
  */
19
21
  readonly variables?: LinkedVariables;
22
+ /**
23
+ * Architecture for the stream function.
24
+ */
25
+ readonly architecture?: ArchitectureType;
26
+ /**
27
+ * Runtime for the stream function.
28
+ */
29
+ readonly runtime?: RuntimeType;
20
30
  /**
21
31
  * Log retention (in days) for the handler.
22
32
  */
@@ -1,3 +1,4 @@
1
+ import type { TransactionMode } from '../types/mode';
1
2
  import type { TableIndex, TableMetadata, TableRelation } from './table';
2
3
  import type { RelationTables } from './relations';
3
4
  import type { IndexedTables } from './indexes';
@@ -6,13 +7,6 @@ import type { TableSchemas } from './schemas';
6
7
  import type { Database } from './contract';
7
8
  import type { Client } from './client';
8
9
  import type { Query } from './query';
9
- /**
10
- * Transaction mode.
11
- */
12
- export declare const enum TransactionMode {
13
- Interactive = "interactive",
14
- Static = "static"
15
- }
16
10
  /**
17
11
  * Transaction mode utils.
18
12
  */
@@ -0,0 +1,9 @@
1
+ /**
2
+ * All supported index types.
3
+ */
4
+ export declare const enum Index {
5
+ Primary = "primary",
6
+ Secondary = "secondary",
7
+ Unique = "unique",
8
+ TTL = "ttl"
9
+ }
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Parameters mode.
3
+ */
4
+ export declare const enum ParametersMode {
5
+ NameAndIndex = "both",
6
+ OnlyIndex = "index"
7
+ }
8
+ /**
9
+ * Transaction mode.
10
+ */
11
+ export declare const enum TransactionMode {
12
+ Interactive = "interactive",
13
+ Static = "static"
14
+ }
15
+ /**
16
+ * Insensitive mode.
17
+ */
18
+ export declare const enum InsensitiveMode {
19
+ Unsupported = "unsupported",
20
+ Enabled = "enabled"
21
+ }
22
+ /**
23
+ * Pagination mode.
24
+ */
25
+ export declare const enum PaginationMode {
26
+ Cursor = "cursor",
27
+ Offset = "offset"
28
+ }
29
+ /**
30
+ * Order mode.
31
+ */
32
+ export declare const enum OrderMode {
33
+ IndexColumns = "index",
34
+ AnyColumns = "any"
35
+ }
36
+ /**
37
+ * Lock mode.
38
+ */
39
+ export declare const enum LockMode {
40
+ Unsupported = "unsupported",
41
+ Supported = "supported"
42
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Query order types.
3
+ */
4
+ export declare const enum Order {
5
+ Asc = "asc",
6
+ Desc = "desc"
7
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ez4/database",
3
3
  "description": "EZ4: Components to build database services",
4
- "version": "0.36.0",
4
+ "version": "0.38.0",
5
5
  "author": "Silas B.",
6
6
  "license": "MIT",
7
7
  "type": "module",
@@ -46,10 +46,10 @@
46
46
  "live:publish": "npm run build && npm publish --access public"
47
47
  },
48
48
  "dependencies": {
49
- "@ez4/common": "^0.36.0",
50
- "@ez4/project": "^0.36.0",
51
- "@ez4/reflection": "^0.36.0",
52
- "@ez4/schema": "^0.36.0",
53
- "@ez4/utils": "^0.36.0"
49
+ "@ez4/common": "^0.38.0",
50
+ "@ez4/project": "^0.38.0",
51
+ "@ez4/reflection": "^0.38.0",
52
+ "@ez4/schema": "^0.38.0",
53
+ "@ez4/utils": "^0.38.0"
54
54
  }
55
55
  }
@@ -1,9 +0,0 @@
1
- import type { AllType, TypeCallback, TypeClass, TypeFunction, TypeModel } from '@ez4/reflection';
2
- export declare const isDatabaseService: (type: AllType) => type is TypeClass;
3
- export declare const isDatabaseEngine: (type: AllType) => type is TypeModel;
4
- export declare const isDatabaseTable: (type: AllType) => type is TypeModel;
5
- export declare const isStreamHandler: (type: AllType) => type is TypeCallback | TypeFunction;
6
- export declare const isTableRelations: (type: TypeModel) => boolean;
7
- export declare const isTableIndexes: (type: TypeModel) => boolean;
8
- export declare const isTableSchema: (type: TypeModel) => boolean;
9
- export declare const isTableStream: (type: TypeModel) => boolean;
@@ -1,25 +0,0 @@
1
- import type { Service as CommonService } from '@ez4/common';
2
- import type { StreamAnyChange } from './streams';
3
- import type { TableSchema } from './schemas';
4
- import type { Database } from './contract';
5
- /**
6
- * Incoming table stream event.
7
- */
8
- export type TableStreamIncoming<T extends TableSchema> = StreamAnyChange<T> & TableStreamRequest;
9
- /**
10
- * Table stream request.
11
- */
12
- export type TableStreamRequest = {
13
- /**
14
- * Request tracking Id.
15
- */
16
- readonly requestId: string;
17
- };
18
- /**
19
- * Table stream listener.
20
- */
21
- export type TableStreamListener<T extends TableSchema> = (event: CommonService.AnyEvent<TableStreamIncoming<T>>, context: CommonService.Context<Database.Service>) => Promise<void> | void;
22
- /**
23
- * Table stream handler.
24
- */
25
- export type TableStreamHandler<T extends TableSchema> = (request: TableStreamIncoming<T>, context: CommonService.Context<Database.Service>) => Promise<void> | void;
@@ -1,15 +0,0 @@
1
- import type { ParametersMode } from '../services/parameters';
2
- import type { TransactionMode } from '../services/transaction';
3
- import type { InsensitiveMode } from '../services/insensitive';
4
- import type { PaginationMode } from '../services/pagination';
5
- import type { OrderMode } from '../services/order';
6
- import type { LockMode } from '../services/lock';
7
- export type DatabaseEngine = {
8
- parametersMode: ParametersMode;
9
- transactionMode: TransactionMode;
10
- insensitiveMode: InsensitiveMode;
11
- paginationMode: PaginationMode;
12
- orderMode: OrderMode;
13
- lockMode: LockMode;
14
- name: string;
15
- };
@@ -1,6 +0,0 @@
1
- export type StreamHandler = {
2
- name: string;
3
- module?: string;
4
- file: string;
5
- description?: string;
6
- };
@@ -1,6 +0,0 @@
1
- import type { Index } from '../services/indexes';
2
- export type TableIndex = {
3
- name: string;
4
- columns: string[];
5
- type: Index;
6
- };
@@ -1,9 +0,0 @@
1
- import type { Index } from '../services/indexes';
2
- export type TableRelation = {
3
- sourceTable: string;
4
- sourceColumn: string;
5
- sourceIndex?: Index;
6
- targetColumn: string;
7
- targetAlias: string;
8
- targetIndex?: Index;
9
- };
@@ -1,4 +0,0 @@
1
- export type DatabaseScalability = {
2
- minCapacity: number;
3
- maxCapacity: number;
4
- };
@@ -1,2 +0,0 @@
1
- import type { ObjectSchema } from '@ez4/schema';
2
- export type TableSchema = ObjectSchema;
@@ -1,13 +0,0 @@
1
- import type { ServiceMetadata } from '@ez4/project/library';
2
- import type { DatabaseScalability } from './scalability';
3
- import type { DatabaseEngine } from './engine';
4
- import type { DatabaseTable } from './table';
5
- export declare const ServiceType = "@ez4/database";
6
- export type DatabaseService = ServiceMetadata & {
7
- type: typeof ServiceType;
8
- scalability?: DatabaseScalability;
9
- engine: DatabaseEngine;
10
- tables: DatabaseTable[];
11
- name: string;
12
- };
13
- export declare const isDatabaseService: (service: ServiceMetadata) => service is DatabaseService;
@@ -1,11 +0,0 @@
1
- import type { LinkedVariables } from '@ez4/project/library';
2
- import type { ServiceListener } from '@ez4/common/library';
3
- import type { StreamHandler } from './handler';
4
- export type TableStream = {
5
- listener?: ServiceListener;
6
- handler: StreamHandler;
7
- variables?: LinkedVariables;
8
- logRetention?: number;
9
- timeout?: number;
10
- memory?: number;
11
- };
@@ -1,11 +0,0 @@
1
- import type { TableRelation } from './relations';
2
- import type { TableIndex } from './indexes';
3
- import type { TableSchema } from './schema';
4
- import type { TableStream } from './stream';
5
- export type DatabaseTable = {
6
- name: string;
7
- schema: TableSchema;
8
- relations?: TableRelation[];
9
- indexes: TableIndex[];
10
- stream?: TableStream;
11
- };