@ez4/database 0.1.0 → 0.2.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 CHANGED
@@ -1 +1,3 @@
1
1
  # EZ4: Database
2
+
3
+ It uses the power of [reflection](../reflection/) to provide an API which determines how to build and connect database components.
package/dist/library.cjs CHANGED
@@ -5,7 +5,7 @@ IncompleteTableError:()=>g,IncorrectIndexesTypeError:()=>x,IncorrectSchemaTypeEr
5
5
  InvalidIndexReferenceError:()=>h,InvalidIndexTypeError:()=>M,InvalidIndexesTypeError:()=>S,
6
6
  InvalidSchemaTypeError:()=>v,ServiceType:()=>E,getDatabaseServices:()=>R,getDatabaseTable:()=>H,
7
7
  getTableSchema:()=>C,isDatabaseService:()=>Te,registerTriggers:()=>he});module.exports=
8
- fe(ve);var ne=require("@ez4/common/library"),ie=require("@ez4/schema/library"),pe=require("@ez4/project");var c=require("@ez4/common/library"),ae=require("@ez4/reflection");var E="@ez4/database",Te=e=>e.type===E;var V=require("@ez4/common/library"),y=class extends V.IncompleteTypeError{constructor(t,r){
8
+ fe(ve);var ne=require("@ez4/common/library"),ie=require("@ez4/schema/library"),pe=require("@ez4/project/library");var c=require("@ez4/common/library"),ae=require("@ez4/reflection");var E="@ez4/database",Te=e=>e.type===E;var V=require("@ez4/common/library"),y=class extends V.IncompleteTypeError{constructor(t,r){
9
9
  super("Incomplete database service",t,r)}};var T=require("@ez4/common/library"),d=require("@ez4/reflection");var N=require("@ez4/common/library"),g=class extends N.IncompleteTypeError{constructor(t,r){
10
10
  super("Incomplete database table",t,r)}};var u=require("@ez4/common/library"),S=class extends u.InvalidTypeError{constructor(t){
11
11
  super("Invalid table indexes type",void 0,"Database.Indexes",t)}},x=class extends u.IncorrectTypeError{constructor(r,o){
package/dist/library.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import{registerTriggers as He}from"@ez4/common/library";import{registerTriggers as Re}from"@ez4/schema/library";
2
- import{createTrigger as Fe}from"@ez4/project";import{getLinkedServices as ke,getLinkedVariables as Ae,getModelMembers as Oe,getPropertyTuple as we}from"@ez4/common/library";
2
+ import{createTrigger as Fe}from"@ez4/project/library";import{getLinkedServices as ke,getLinkedVariables as Ae,getModelMembers as Oe,getPropertyTuple as we}from"@ez4/common/library";
3
3
  import{isModelProperty as Pe}from"@ez4/reflection";var x="@ez4/database",Ve=e=>e.type===x;import{IncompleteTypeError as B}from"@ez4/common/library";var m=class extends B{constructor(t,r){
4
4
  super("Incomplete database service",t,r)}};import{getModelMembers as xe,getObjectMembers as Me,getPropertyString as he}from"@ez4/common/library";
5
5
  import{isModelProperty as ve,isTypeObject as Ie,isTypeReference as De}from"@ez4/reflection";import{IncompleteTypeError as G}from"@ez4/common/library";var l=class extends G{constructor(t,r){
package/dist/main.cjs CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";var o=Object.defineProperty;var s=Object.getOwnPropertyDescriptor;var c=Object.getOwnPropertyNames;var T=Object.prototype.hasOwnProperty;var S=(r,t)=>{for(var m in t)o(r,m,{get:t[m],enumerable:!0})},l=(r,t,m,a)=>{if(t&&
1
+ "use strict";var o=Object.defineProperty;var s=Object.getOwnPropertyDescriptor;var c=Object.getOwnPropertyNames;var T=Object.prototype.hasOwnProperty;var l=(r,t)=>{for(var m in t)o(r,m,{get:t[m],enumerable:!0})},S=(r,t,m,a)=>{if(t&&
2
2
  typeof t=="object"||typeof t=="function")for(let e of c(t))!T.call(r,e)&&e!==m&&
3
- o(r,e,{get:()=>t[e],enumerable:!(a=s(t,e))||a.enumerable});return r};var x=r=>l(o({},"__esModule",{value:!0}),r);var d={};S(d,{Database:()=>n,Index:()=>p,StreamType:()=>i});module.exports=x(d);var n;(r=>{})(n||={});var p=(e=>(e.Primary="primary",e.Regular="regular",e.Unique="unique",e.TTL="ttl",
3
+ o(r,e,{get:()=>t[e],enumerable:!(a=s(t,e))||a.enumerable});return r};var x=r=>S(o({},"__esModule",{value:!0}),r);var d={};l(d,{Database:()=>n,Index:()=>p,StreamType:()=>i});module.exports=x(d);var n;(r=>{})(n||={});var p=(e=>(e.Primary="primary",e.Regular="regular",e.Unique="unique",e.TTL="ttl",
4
4
  e))(p||{});var i=(a=>(a.Insert="insert",a.Update="update",a.Delete="delete",a))(i||{});0&&(module.exports={Database,Index,StreamType});
@@ -4,7 +4,7 @@ import type { Database } from './database.js';
4
4
  /**
5
5
  * Database client.
6
6
  */
7
- export interface Client<T extends Database.Service<any>> {
7
+ export type Client<T extends Database.Service<any>> = ClientTables<T> & {
8
8
  /**
9
9
  * Prepare and execute the given query.
10
10
  *
@@ -13,18 +13,15 @@ export interface Client<T extends Database.Service<any>> {
13
13
  * @returns Returns the results for the given query.
14
14
  */
15
15
  rawQuery(query: string, values?: unknown[]): Promise<Record<string, unknown>[]>;
16
- /**
17
- * Table clients.
18
- */
19
- table: ClientTables<T>;
20
- }
16
+ };
21
17
  export type ClientTables<T extends Database.Service<any>> = {
22
18
  [P in keyof TableSchemas<T>]: TableSchemas<T>[P] extends Database.Schema ? Table<TableSchemas<T>[P]> : never;
23
19
  };
24
20
  export interface Table<T extends Database.Schema> {
25
21
  insertOne(query: Query.InsertOneInput<T>): Promise<Query.InsertOneResult>;
22
+ findOne<U extends Query.SelectInput<T>>(query: Query.FindOneInput<T, U>): Promise<Query.FindOneResult<T, U>>;
23
+ upsertOne<U extends Query.SelectInput<T>>(query: Query.UpsertOneInput<T, U>): Promise<Query.UpsertOneResult<T, U>>;
26
24
  updateMany<U extends Query.SelectInput<T>>(query: Query.UpdateManyInput<T, U>): Promise<Query.UpdateManyResult<T, U>>;
27
- findFirst<U extends Query.SelectInput<T>>(query: Query.FindFirstInput<T, U>): Promise<Query.FindFirstResult<T, U>>;
28
25
  findMany<U extends Query.SelectInput<T>>(query: Query.FindManyInput<T, U>): Promise<Query.FindManyResult<T, U>>;
29
26
  deleteMany<U extends Query.SelectInput<T>>(query: Query.DeleteManyInput<T, U>): Promise<Query.DeleteManyResult<T, U>>;
30
27
  }
@@ -32,6 +29,16 @@ export declare namespace Query {
32
29
  type InsertOneInput<T extends Database.Schema> = {
33
30
  data: T;
34
31
  };
32
+ type FindOneInput<T extends Database.Schema, S extends Database.Schema> = {
33
+ select: S;
34
+ where: WhereInput<T>;
35
+ };
36
+ type UpsertOneInput<T extends Database.Schema, S extends Database.Schema> = {
37
+ select?: S;
38
+ insert: T;
39
+ update: DeepPartial<T>;
40
+ where: WhereInput<T>;
41
+ };
35
42
  type UpdateManyInput<T extends Database.Schema, S extends Database.Schema> = {
36
43
  select?: S;
37
44
  data: DeepPartial<T>;
@@ -51,13 +58,10 @@ export declare namespace Query {
51
58
  cursor?: number | string;
52
59
  limit?: number;
53
60
  };
54
- type FindFirstInput<T extends Database.Schema, S extends Database.Schema> = {
55
- select: S;
56
- where: WhereInput<T>;
57
- };
58
61
  type InsertOneResult = void;
62
+ type FindOneResult<T extends Database.Schema, S extends AnyObject> = Record<T, S> | undefined;
63
+ type UpsertOneResult<T extends Database.Schema, S extends AnyObject> = FindOneResult<T, S> | undefined;
59
64
  type UpdateManyResult<T extends Database.Schema, S extends AnyObject> = Record<T, S>[];
60
- type FindFirstResult<T extends Database.Schema, S extends AnyObject> = Record<T, S> | undefined;
61
65
  type FindManyResult<T extends Database.Schema, S extends AnyObject> = {
62
66
  records: Record<T, S>[];
63
67
  cursor?: number | string;
@@ -1,5 +1,5 @@
1
1
  import type { Service } from '@ez4/common';
2
- import type { LinkedVariables } from '@ez4/project';
2
+ import type { LinkedVariables } from '@ez4/project/library';
3
3
  import type { TableTypes } from './helpers.js';
4
4
  import type { StreamChange } from './stream.js';
5
5
  import type { Index } from './indexes.js';
@@ -1,4 +1,4 @@
1
- import type { ServiceMetadata } from '@ez4/project';
1
+ import type { ServiceMetadata } from '@ez4/project/library';
2
2
  import type { DatabaseTable } from './table.js';
3
3
  export declare const ServiceType = "@ez4/database";
4
4
  export type DatabaseService = ServiceMetadata & {
@@ -1,4 +1,4 @@
1
- import type { LinkedVariables } from '@ez4/project';
1
+ import type { LinkedVariables } from '@ez4/project/library';
2
2
  import type { StreamHandler } from './handler.js';
3
3
  export type TableStream = {
4
4
  handler: StreamHandler;
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.1.0",
4
+ "version": "0.2.0",
5
5
  "author": "Silas B.",
6
6
  "license": "MIT",
7
7
  "type": "module",
@@ -31,10 +31,10 @@
31
31
  "live:publish": "npm run test && npm publish --access public"
32
32
  },
33
33
  "dependencies": {
34
- "@ez4/common": "^0.1.0",
35
- "@ez4/project": "^0.1.0",
36
- "@ez4/reflection": "^0.1.0",
37
- "@ez4/schema": "^0.1.0",
38
- "@ez4/utils": "^0.1.0"
34
+ "@ez4/common": "^0.2.0",
35
+ "@ez4/project": "^0.2.0",
36
+ "@ez4/reflection": "^0.2.0",
37
+ "@ez4/schema": "^0.2.0",
38
+ "@ez4/utils": "^0.2.0"
39
39
  }
40
40
  }