@ez4/database 0.2.1 → 0.4.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 +12 -0
- package/dist/errors/stream.d.ts +8 -1
- package/dist/library.cjs +67 -64
- package/dist/library.mjs +62 -56
- package/dist/main.cjs +4 -4
- package/dist/main.d.ts +3 -2
- package/dist/main.mjs +2 -2
- package/dist/metadata/stream.d.ts +4 -2
- package/dist/metadata/utils.d.ts +3 -3
- package/dist/services/client.d.ts +19 -105
- package/dist/services/database.d.ts +2 -2
- package/dist/services/helpers.d.ts +1 -19
- package/dist/services/indexes.d.ts +32 -0
- package/dist/services/query.d.ts +115 -0
- package/dist/services/schemas.d.ts +22 -0
- package/dist/services/streams.d.ts +34 -0
- package/package.json +9 -6
package/README.md
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
1
|
# EZ4: Database
|
|
2
2
|
|
|
3
3
|
It uses the power of [reflection](../reflection/) to provide an API which determines how to build and connect database components.
|
|
4
|
+
|
|
5
|
+
## Getting started
|
|
6
|
+
|
|
7
|
+
#### Install
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm install @ez4/database -D
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## License
|
|
14
|
+
|
|
15
|
+
MIT License
|
package/dist/errors/stream.d.ts
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
import { IncompleteTypeError } from '@ez4/common/library';
|
|
1
|
+
import { IncompleteTypeError, IncorrectTypeError, InvalidTypeError } from '@ez4/common/library';
|
|
2
2
|
export declare class IncompleteStreamError extends IncompleteTypeError {
|
|
3
3
|
constructor(properties: string[], fileName?: string);
|
|
4
4
|
}
|
|
5
|
+
export declare class InvalidStreamTypeError extends InvalidTypeError {
|
|
6
|
+
constructor(fileName?: string);
|
|
7
|
+
}
|
|
8
|
+
export declare class IncorrectStreamTypeError extends IncorrectTypeError {
|
|
9
|
+
streamType: string;
|
|
10
|
+
constructor(streamType: string, fileName?: string);
|
|
11
|
+
}
|
package/dist/library.cjs
CHANGED
|
@@ -1,65 +1,68 @@
|
|
|
1
|
-
"use strict";var
|
|
2
|
-
typeof t=="object"||typeof t=="function")for(let
|
|
3
|
-
|
|
4
|
-
IncompleteTableError:()=>g,IncorrectIndexesTypeError:()=>
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
super("Incomplete database service",t,r)}};var
|
|
1
|
+
"use strict";var C=Object.defineProperty;var ce=Object.getOwnPropertyDescriptor;var ue=Object.getOwnPropertyNames;var be=Object.prototype.hasOwnProperty;var fe=(e,t)=>{for(var r in t)C(e,r,{get:t[r],enumerable:!0})},Te=(e,t,r,a)=>{if(t&&
|
|
2
|
+
typeof t=="object"||typeof t=="function")for(let o of ue(t))!be.call(e,o)&&o!==r&&
|
|
3
|
+
C(e,o,{get:()=>t[o],enumerable:!(a=ce(t,o))||a.enumerable});return e};var de=e=>Te(C({},"__esModule",{value:!0}),e);var De={};fe(De,{IncompleteHandlerError:()=>A,IncompleteServiceError:()=>x,IncompleteStreamError:()=>j,
|
|
4
|
+
IncompleteTableError:()=>g,IncorrectIndexesTypeError:()=>M,IncorrectSchemaTypeError:()=>D,
|
|
5
|
+
IncorrectStreamTypeError:()=>P,InvalidIndexReferenceError:()=>I,InvalidIndexTypeError:()=>h,
|
|
6
|
+
InvalidIndexesTypeError:()=>S,InvalidSchemaTypeError:()=>v,InvalidStreamTypeError:()=>E,
|
|
7
|
+
ServiceType:()=>k,getDatabaseServices:()=>F,getDatabaseTable:()=>q,getTableSchema:()=>N,
|
|
8
|
+
isDatabaseService:()=>ye,registerTriggers:()=>ve});module.exports=de(De);var pe=require("@ez4/common/library"),me=require("@ez4/schema/library"),le=require("@ez4/project/library");var c=require("@ez4/common/library"),ne=require("@ez4/reflection");var k="@ez4/database",ye=e=>e.type===k;var U=require("@ez4/common/library"),x=class extends U.IncompleteTypeError{constructor(t,r){
|
|
9
|
+
super("Incomplete database service",t,r)}};var p=require("@ez4/common/library"),w=require("@ez4/reflection"),z=e=>(0,p.isClassDeclaration)(
|
|
10
|
+
e)&&(0,p.hasHeritageType)(e,"Database.Service"),$=e=>(0,p.isModelDeclaration)(e)&&
|
|
11
|
+
(0,p.hasHeritageType)(e,"Database.Table"),_=e=>(0,w.isTypeCallback)(e)||(0,w.isTypeFunction)(
|
|
12
|
+
e),B=e=>(0,p.hasHeritageType)(e,"Database.Indexes"),G=e=>(0,p.hasHeritageType)(e,
|
|
13
|
+
"Database.Schema"),J=e=>(0,p.hasHeritageType)(e,"Database.Stream");var d=require("@ez4/common/library"),y=require("@ez4/reflection");var K=require("@ez4/common/library"),g=class extends K.IncompleteTypeError{constructor(t,r){
|
|
10
14
|
super("Incomplete database table",t,r)}};var u=require("@ez4/common/library"),S=class extends u.InvalidTypeError{constructor(t){
|
|
11
|
-
super("Invalid table indexes type",void 0,"Database.Indexes",t)}},
|
|
12
|
-
super("Incorrect table indexes type",r,"Database.Indexes",
|
|
13
|
-
|
|
14
|
-
t follow one of the Index options.`,
|
|
15
|
-
super(`Invalid index reference, ${r} must be valid column.`,
|
|
16
|
-
|
|
17
|
-
(
|
|
18
|
-
|
|
19
|
-
e)
|
|
20
|
-
e)
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
(
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
return
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
return
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
let
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
(
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
e
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
n
|
|
56
|
-
|
|
57
|
-
(0,c.
|
|
58
|
-
t
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
getDatabaseServices,getDatabaseTable,getTableSchema,isDatabaseService,registerTriggers});
|
|
15
|
+
super("Invalid table indexes type",void 0,"Database.Indexes",t)}},M=class extends u.IncorrectTypeError{constructor(r,a){
|
|
16
|
+
super("Incorrect table indexes type",r,"Database.Indexes",a);this.schemaType=r}},
|
|
17
|
+
h=class extends u.TypeError{constructor(r,a){super(`Invalid index type, ${r} mus\
|
|
18
|
+
t follow one of the Index options.`,a);this.indexName=r}},I=class extends u.TypeError{constructor(r,a){
|
|
19
|
+
super(`Invalid index reference, ${r} must be valid column.`,a);this.indexName=r}};var R=require("@ez4/reflection"),W=require("@ez4/common/library"),H=require("@ez4/schema/library");var O=require("@ez4/common/library"),v=class extends O.InvalidTypeError{constructor(t){
|
|
20
|
+
super("Invalid table schema type",void 0,"Database.Schema",t)}},D=class extends O.IncorrectTypeError{constructor(r,a){
|
|
21
|
+
super("Incorrect table schema type",r,"Database.Schema",a);this.schemaType=r}};var N=(e,t,r,a)=>{if(!(0,R.isTypeReference)(e))return Q(e,t,r,a);let o=r[e.path];
|
|
22
|
+
return o?Q(o,t,r,a):null},Q=(e,t,r,a)=>(0,R.isTypeObject)(e)?(0,H.getObjectSchema)(
|
|
23
|
+
e,r):(0,W.isModelDeclaration)(e)?G(e)?(0,H.getObjectSchema)(e,r):(a.push(new D(e.
|
|
24
|
+
name,e.file)),null):(a.push(new v(t.file)),null);var l=require("@ez4/common/library"),b=require("@ez4/reflection");var Z=(e,t,r,a)=>{if(!(0,b.isTypeReference)(e))return X(e,t,a);let o=r[e.path];return o?
|
|
25
|
+
X(o,t,a):null},X=(e,t,r)=>(0,b.isTypeObject)(e)?Y(e,(0,l.getObjectMembers)(e),r):
|
|
26
|
+
(0,l.isModelDeclaration)(e)?B(e)?Y(e,(0,l.getModelMembers)(e),r):(r.push(new M(e.
|
|
27
|
+
name,e.file)),null):(r.push(new S(t.file)),null),Y=(e,t,r)=>{let a={};for(let o of t){
|
|
28
|
+
if(!(0,b.isModelProperty)(o)||o.inherited)continue;let n=o.name,i=(0,l.getPropertyString)(
|
|
29
|
+
o);switch(i){case"primary":case"regular":case"unique":case"ttl":a[n]=i;break;default:
|
|
30
|
+
return r.push(new h(n,e.file)),null}}return a};var m=require("@ez4/common/library"),T=require("@ez4/reflection");var f=require("@ez4/common/library"),j=class extends f.IncompleteTypeError{constructor(t,r){
|
|
31
|
+
super("Incomplete table stream",t,r)}},E=class extends f.InvalidTypeError{constructor(t){
|
|
32
|
+
super("Invalid table stream type",void 0,"Database.Stream",t)}},P=class extends f.IncorrectTypeError{constructor(r,a){
|
|
33
|
+
super("Incorrect table stream type",r,"Database.Stream",a);this.streamType=r}};var L=require("@ez4/common/library"),A=class extends L.IncompleteTypeError{constructor(t,r){
|
|
34
|
+
super("Incomplete stream handler",t,r)}};var ee=(e,t,r)=>{if(!_(e))return null;let a={},o=new Set(["name","file","change"]);
|
|
35
|
+
return e.description&&(a.description=e.description),(a.name=e.name)&&o.delete("n\
|
|
36
|
+
ame"),(a.file=e.file)&&o.delete("file"),e.parameters&&o.delete("change"),o.size===
|
|
37
|
+
0&&xe(a)?a:(r.push(new A([...o],e.file)),null)},xe=e=>!!e.name&&!!e.file;var ae=(e,t,r,a)=>{if(!(0,T.isTypeReference)(e))return re(e,t,r,a);let o=r[e.path];
|
|
38
|
+
return o?re(o,t,r,a):null},ge=e=>!!e.handler,re=(e,t,r,a)=>(0,T.isTypeObject)(e)?
|
|
39
|
+
te(e,(0,m.getObjectMembers)(e),r,a):(0,m.isModelDeclaration)(e)?J(e)?te(e,(0,m.getModelMembers)(
|
|
40
|
+
e),r,a):(a.push(new P(e.name,e.file)),null):(a.push(new E(t.file)),null),te=(e,t,r,a)=>{
|
|
41
|
+
let o={},n=new Set(["handler"]);for(let i of t)if(!(!(0,T.isModelProperty)(i)||i.
|
|
42
|
+
inherited))switch(i.name){case"handler":o.handler=ee(i.value,r,a);break;case"tim\
|
|
43
|
+
eout":case"memory":{let s=(0,m.getPropertyNumber)(i);s!=null&&(o[i.name]=s);break}case"\
|
|
44
|
+
variables":o.variables=(0,m.getLinkedVariables)(i,a);break}return ge(o)?o:(a.push(
|
|
45
|
+
new j([...n],e.file)),null)};var q=(e,t,r)=>{if(!(0,y.isTypeReference)(e))return oe(e,t,r);let a=t[e.path];return a?
|
|
46
|
+
oe(a,t,r):null},Se=e=>!!e.name&&!!e.schema&&!!e.indexes,oe=(e,t,r)=>$(e)?se(e,(0,d.getModelMembers)(
|
|
47
|
+
e),t,r):(0,y.isTypeObject)(e)?se(e,(0,d.getObjectMembers)(e),t,r):null,se=(e,t,r,a)=>{
|
|
48
|
+
let o={},n=new Set(["name","schema","indexes"]);for(let s of t)if(!(!(0,y.isModelProperty)(
|
|
49
|
+
s)||s.inherited))switch(s.name){case"name":(o.name=(0,d.getPropertyString)(s))&&
|
|
50
|
+
n.delete(s.name);break;case"indexes":{(o.indexes=Z(s.value,e,r,a))&&n.delete(s.name);
|
|
51
|
+
break}case"schema":{(o.schema=N(s.value,e,r,a))&&n.delete(s.name);break}case"str\
|
|
52
|
+
eam":{o.stream=ae(s.value,e,r,a);break}}if(!Se(o))return a.push(new g([...n],e.file)),
|
|
53
|
+
null;let i=Me(e,o.indexes,o.schema);return i.length?(a.push(...i),null):o},Me=(e,t,r)=>{
|
|
54
|
+
let a=r.properties,o=[];for(let n in t)for(let i of n.split(":"))a[i]||o.push(new I(
|
|
55
|
+
n,e.file));return o};var F=e=>{let t={},r=[];for(let a in e){let o=e[a];if(!z(o))continue;let n={type:k},
|
|
56
|
+
i=new Set(["tables"]);n.name=o.name;for(let s of(0,c.getModelMembers)(o))if(!(!(0,ne.isModelProperty)(
|
|
57
|
+
s)||s.inherited))switch(s.name){case"tables":(n.tables=Ie(s,e,r))&&i.delete(s.name);
|
|
58
|
+
break;case"variables":n.variables=(0,c.getLinkedVariables)(s,r);break;case"servi\
|
|
59
|
+
ces":n.services=(0,c.getLinkedServices)(s,e,r);break}if(!he(n)){r.push(new x([...i],
|
|
60
|
+
o.file));continue}t[o.name]=n}return{services:t,errors:r}},he=e=>!!e.name&&!!e.tables,
|
|
61
|
+
Ie=(e,t,r)=>{let a=(0,c.getPropertyTuple)(e)??[],o=[];for(let n of a){let i=q(n,
|
|
62
|
+
t,r);i&&o.push(i)}return o};var ie=e=>z(e)?e.name:null;var V=!1,ve=()=>(V||((0,pe.registerTriggers)(),(0,me.registerTriggers)(),(0,le.createTrigger)(
|
|
63
|
+
"@ez4/database",{"metadata:getServices":F,"metadata:getLinkedService":ie}),V=!0),
|
|
64
|
+
V);0&&(module.exports={IncompleteHandlerError,IncompleteServiceError,IncompleteStreamError,
|
|
65
|
+
IncompleteTableError,IncorrectIndexesTypeError,IncorrectSchemaTypeError,IncorrectStreamTypeError,
|
|
66
|
+
InvalidIndexReferenceError,InvalidIndexTypeError,InvalidIndexesTypeError,InvalidSchemaTypeError,
|
|
67
|
+
InvalidStreamTypeError,ServiceType,getDatabaseServices,getDatabaseTable,getTableSchema,
|
|
68
|
+
isDatabaseService,registerTriggers});
|
package/dist/library.mjs
CHANGED
|
@@ -1,56 +1,62 @@
|
|
|
1
|
-
import{registerTriggers as
|
|
2
|
-
import{createTrigger as
|
|
3
|
-
import{isModelProperty as
|
|
4
|
-
super("Incomplete database service",t,r)}};import{
|
|
5
|
-
import{
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
super(
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
null},
|
|
21
|
-
(
|
|
22
|
-
import{isModelProperty as
|
|
23
|
-
|
|
24
|
-
null):(r.push(new
|
|
25
|
-
continue;let
|
|
26
|
-
ttl":
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
super("Incomplete stream
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
push(new
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
[
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
1
|
+
import{registerTriggers as Ve}from"@ez4/common/library";import{registerTriggers as Ue}from"@ez4/schema/library";
|
|
2
|
+
import{createTrigger as $e}from"@ez4/project/library";import{getLinkedServices as Oe,getLinkedVariables as Re,getModelMembers as Ce,getPropertyTuple as He}from"@ez4/common/library";
|
|
3
|
+
import{isModelProperty as Ne}from"@ez4/reflection";var h="@ez4/database",_e=e=>e.type===h;import{IncompleteTypeError as G}from"@ez4/common/library";var m=class extends G{constructor(t,r){
|
|
4
|
+
super("Incomplete database service",t,r)}};import{hasHeritageType as p,isClassDeclaration as J,isModelDeclaration as K}from"@ez4/common/library";
|
|
5
|
+
import{isTypeCallback as Q,isTypeFunction as W}from"@ez4/reflection";var l=e=>J(
|
|
6
|
+
e)&&p(e,"Database.Service"),v=e=>K(e)&&p(e,"Database.Table"),D=e=>Q(e)||W(e),j=e=>p(
|
|
7
|
+
e,"Database.Indexes"),E=e=>p(e,"Database.Schema"),P=e=>p(e,"Database.Stream");import{getModelMembers as De,getObjectMembers as je,getPropertyString as Ee}from"@ez4/common/library";
|
|
8
|
+
import{isModelProperty as Pe,isTypeObject as Ae,isTypeReference as ke}from"@ez4/reflection";import{IncompleteTypeError as X}from"@ez4/common/library";var c=class extends X{constructor(t,r){
|
|
9
|
+
super("Incomplete database table",t,r)}};import{IncorrectTypeError as Y,InvalidTypeError as Z,TypeError as A}from"@ez4/common/library";
|
|
10
|
+
var u=class extends Z{constructor(t){super("Invalid table indexes type",void 0,"\
|
|
11
|
+
Database.Indexes",t)}},b=class extends Y{constructor(r,a){super("Incorrect table\
|
|
12
|
+
indexes type",r,"Database.Indexes",a);this.schemaType=r}},f=class extends A{constructor(r,a){
|
|
13
|
+
super(`Invalid index type, ${r} must follow one of the Index options.`,a);this.indexName=
|
|
14
|
+
r}},T=class extends A{constructor(r,a){super(`Invalid index reference, ${r} must\
|
|
15
|
+
be valid column.`,a);this.indexName=r}};import{isTypeObject as re,isTypeReference as te}from"@ez4/reflection";import{isModelDeclaration as ae}from"@ez4/common/library";
|
|
16
|
+
import{getObjectSchema as k}from"@ez4/schema/library";import{IncorrectTypeError as L,InvalidTypeError as ee}from"@ez4/common/library";
|
|
17
|
+
var d=class extends ee{constructor(t){super("Invalid table schema type",void 0,"\
|
|
18
|
+
Database.Schema",t)}},y=class extends L{constructor(r,a){super("Incorrect table \
|
|
19
|
+
schema type",r,"Database.Schema",a);this.schemaType=r}};var z=(e,t,r,a)=>{if(!te(e))return w(e,t,r,a);let o=r[e.path];return o?w(o,t,r,a):
|
|
20
|
+
null},w=(e,t,r,a)=>re(e)?k(e,r):ae(e)?E(e)?k(e,r):(a.push(new y(e.name,e.file)),
|
|
21
|
+
null):(a.push(new d(t.file)),null);import{isModelDeclaration as oe,getModelMembers as se,getObjectMembers as ne,getPropertyString as ie}from"@ez4/common/library";
|
|
22
|
+
import{isModelProperty as pe,isTypeObject as me,isTypeReference as le}from"@ez4/reflection";var C=(e,t,r,a)=>{if(!le(e))return O(e,t,a);let o=r[e.path];return o?O(o,t,a):null},
|
|
23
|
+
O=(e,t,r)=>me(e)?R(e,ne(e),r):oe(e)?j(e)?R(e,se(e),r):(r.push(new b(e.name,e.file)),
|
|
24
|
+
null):(r.push(new u(t.file)),null),R=(e,t,r)=>{let a={};for(let o of t){if(!pe(o)||
|
|
25
|
+
o.inherited)continue;let n=o.name,i=ie(o);switch(i){case"primary":case"regular":case"\
|
|
26
|
+
unique":case"ttl":a[n]=i;break;default:return r.push(new f(n,e.file)),null}}return a};import{getLinkedVariables as de,getModelMembers as ye,getObjectMembers as xe,getPropertyNumber as ge,
|
|
27
|
+
isModelDeclaration as Se}from"@ez4/common/library";import{isModelProperty as Me,
|
|
28
|
+
isTypeObject as he,isTypeReference as Ie}from"@ez4/reflection";import{IncompleteTypeError as ce,IncorrectTypeError as ue,InvalidTypeError as be}from"@ez4/common/library";
|
|
29
|
+
var x=class extends ce{constructor(t,r){super("Incomplete table stream",t,r)}},g=class extends be{constructor(t){
|
|
30
|
+
super("Invalid table stream type",void 0,"Database.Stream",t)}},S=class extends ue{constructor(r,a){
|
|
31
|
+
super("Incorrect table stream type",r,"Database.Stream",a);this.streamType=r}};import{IncompleteTypeError as fe}from"@ez4/common/library";var M=class extends fe{constructor(t,r){
|
|
32
|
+
super("Incomplete stream handler",t,r)}};var H=(e,t,r)=>{if(!D(e))return null;let a={},o=new Set(["name","file","change"]);
|
|
33
|
+
return e.description&&(a.description=e.description),(a.name=e.name)&&o.delete("n\
|
|
34
|
+
ame"),(a.file=e.file)&&o.delete("file"),e.parameters&&o.delete("change"),o.size===
|
|
35
|
+
0&&Te(a)?a:(r.push(new M([...o],e.file)),null)},Te=e=>!!e.name&&!!e.file;var F=(e,t,r,a)=>{if(!Ie(e))return N(e,t,r,a);let o=r[e.path];return o?N(o,t,r,a):
|
|
36
|
+
null},ve=e=>!!e.handler,N=(e,t,r,a)=>he(e)?q(e,xe(e),r,a):Se(e)?P(e)?q(e,ye(e),r,
|
|
37
|
+
a):(a.push(new S(e.name,e.file)),null):(a.push(new g(t.file)),null),q=(e,t,r,a)=>{
|
|
38
|
+
let o={},n=new Set(["handler"]);for(let i of t)if(!(!Me(i)||i.inherited))switch(i.
|
|
39
|
+
name){case"handler":o.handler=H(i.value,r,a);break;case"timeout":case"memory":{let s=ge(
|
|
40
|
+
i);s!=null&&(o[i.name]=s);break}case"variables":o.variables=de(i,a);break}return ve(
|
|
41
|
+
o)?o:(a.push(new x([...n],e.file)),null)};var $=(e,t,r)=>{if(!ke(e))return V(e,t,r);let a=t[e.path];return a?V(a,t,r):null},
|
|
42
|
+
we=e=>!!e.name&&!!e.schema&&!!e.indexes,V=(e,t,r)=>v(e)?U(e,De(e),t,r):Ae(e)?U(e,
|
|
43
|
+
je(e),t,r):null,U=(e,t,r,a)=>{let o={},n=new Set(["name","schema","indexes"]);for(let s of t)
|
|
44
|
+
if(!(!Pe(s)||s.inherited))switch(s.name){case"name":(o.name=Ee(s))&&n.delete(s.name);
|
|
45
|
+
break;case"indexes":{(o.indexes=C(s.value,e,r,a))&&n.delete(s.name);break}case"s\
|
|
46
|
+
chema":{(o.schema=z(s.value,e,r,a))&&n.delete(s.name);break}case"stream":{o.stream=
|
|
47
|
+
F(s.value,e,r,a);break}}if(!we(o))return a.push(new c([...n],e.file)),null;let i=ze(
|
|
48
|
+
e,o.indexes,o.schema);return i.length?(a.push(...i),null):o},ze=(e,t,r)=>{let a=r.
|
|
49
|
+
properties,o=[];for(let n in t)for(let i of n.split(":"))a[i]||o.push(new T(n,e.
|
|
50
|
+
file));return o};var _=e=>{let t={},r=[];for(let a in e){let o=e[a];if(!l(o))continue;let n={type:h},
|
|
51
|
+
i=new Set(["tables"]);n.name=o.name;for(let s of Ce(o))if(!(!Ne(s)||s.inherited))
|
|
52
|
+
switch(s.name){case"tables":(n.tables=Fe(s,e,r))&&i.delete(s.name);break;case"va\
|
|
53
|
+
riables":n.variables=Re(s,r);break;case"services":n.services=Oe(s,e,r);break}if(!qe(
|
|
54
|
+
n)){r.push(new m([...i],o.file));continue}t[o.name]=n}return{services:t,errors:r}},
|
|
55
|
+
qe=e=>!!e.name&&!!e.tables,Fe=(e,t,r)=>{let a=He(e)??[],o=[];for(let n of a){let i=$(
|
|
56
|
+
n,t,r);i&&o.push(i)}return o};var B=e=>l(e)?e.name:null;var I=!1,Zr=()=>(I||(Ve(),Ue(),$e("@ez4/database",{"metadata:getServices":_,"met\
|
|
57
|
+
adata:getLinkedService":B}),I=!0),I);export{M as IncompleteHandlerError,m as IncompleteServiceError,x as IncompleteStreamError,
|
|
58
|
+
c as IncompleteTableError,b as IncorrectIndexesTypeError,y as IncorrectSchemaTypeError,
|
|
59
|
+
S as IncorrectStreamTypeError,T as InvalidIndexReferenceError,f as InvalidIndexTypeError,
|
|
60
|
+
u as InvalidIndexesTypeError,d as InvalidSchemaTypeError,g as InvalidStreamTypeError,
|
|
61
|
+
h as ServiceType,_ as getDatabaseServices,$ as getDatabaseTable,z as getTableSchema,
|
|
62
|
+
_e as isDatabaseService,Zr as registerTriggers};
|
package/dist/main.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var
|
|
2
|
-
typeof t=="object"||typeof t=="function")for(let e of
|
|
3
|
-
|
|
4
|
-
e))(
|
|
1
|
+
"use strict";var s=Object.defineProperty;var i=Object.getOwnPropertyDescriptor;var T=Object.getOwnPropertyNames;var x=Object.prototype.hasOwnProperty;var d=(r,t)=>{for(var n in t)s(r,n,{get:t[n],enumerable:!0})},y=(r,t,n,a)=>{if(t&&
|
|
2
|
+
typeof t=="object"||typeof t=="function")for(let e of T(t))!x.call(r,e)&&e!==n&&
|
|
3
|
+
s(r,e,{get:()=>t[e],enumerable:!(a=i(t,e))||a.enumerable});return r};var c=r=>y(s({},"__esModule",{value:!0}),r);var l={};d(l,{Database:()=>o,Index:()=>m,StreamType:()=>p});module.exports=c(l);var o;(r=>{})(o||={});var m=(e=>(e.Primary="primary",e.Regular="regular",e.Unique="unique",e.TTL="ttl",
|
|
4
|
+
e))(m||{});var p=(a=>(a.Insert="insert",a.Update="update",a.Delete="delete",a))(p||{});0&&(module.exports={Database,Index,StreamType});
|
package/dist/main.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
export * from './services/query.js';
|
|
1
2
|
export * from './services/client.js';
|
|
2
|
-
export * from './services/helpers.js';
|
|
3
3
|
export * from './services/database.js';
|
|
4
4
|
export * from './services/indexes.js';
|
|
5
|
-
export * from './services/
|
|
5
|
+
export * from './services/schemas.js';
|
|
6
|
+
export * from './services/streams.js';
|
package/dist/main.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var r;(
|
|
2
|
-
e))(a||{});var
|
|
1
|
+
var r;(s=>{})(r||={});var a=(e=>(e.Primary="primary",e.Regular="regular",e.Unique="unique",e.TTL="ttl",
|
|
2
|
+
e))(a||{});var n=(t=>(t.Insert="insert",t.Update="update",t.Delete="delete",t))(n||{});export{r as Database,a as Index,n as StreamType};
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
import type { AllType, SourceMap } from '@ez4/reflection';
|
|
1
|
+
import type { AllType, SourceMap, TypeModel, TypeObject } from '@ez4/reflection';
|
|
2
2
|
import type { TableStream } from '../types/stream.js';
|
|
3
|
-
|
|
3
|
+
type TypeParent = TypeModel | TypeObject;
|
|
4
|
+
export declare const getTableStream: (type: AllType, parent: TypeParent, reflection: SourceMap, errorList: Error[]) => TableStream | null;
|
|
5
|
+
export {};
|
package/dist/metadata/utils.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { AllType, TypeCallback, TypeClass, TypeFunction, TypeModel } from '@ez4/reflection';
|
|
2
2
|
export declare const isDatabaseService: (type: AllType) => type is TypeClass;
|
|
3
3
|
export declare const isDatabaseTable: (type: AllType) => type is TypeModel;
|
|
4
|
-
export declare const isTableSchema: (type: TypeModel) => boolean;
|
|
5
|
-
export declare const isTableIndexes: (type: TypeModel) => boolean;
|
|
6
|
-
export declare const isTableStream: (type: AllType) => type is TypeModel;
|
|
7
4
|
export declare const isStreamHandler: (type: AllType) => type is TypeCallback | TypeFunction;
|
|
5
|
+
export declare const isTableIndexes: (type: TypeModel) => boolean;
|
|
6
|
+
export declare const isTableSchema: (type: TypeModel) => boolean;
|
|
7
|
+
export declare const isTableStream: (type: TypeModel) => boolean;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { TableSchemas } from './
|
|
1
|
+
import type { TableIndexes } from './indexes.js';
|
|
2
|
+
import type { TableSchemas } from './schemas.js';
|
|
3
3
|
import type { Database } from './database.js';
|
|
4
|
+
import type { Query } from './query.js';
|
|
4
5
|
/**
|
|
5
6
|
* Database client.
|
|
6
7
|
*/
|
|
@@ -14,110 +15,23 @@ export type Client<T extends Database.Service<any>> = ClientTables<T> & {
|
|
|
14
15
|
*/
|
|
15
16
|
rawQuery(query: string, values?: unknown[]): Promise<Record<string, unknown>[]>;
|
|
16
17
|
};
|
|
18
|
+
/**
|
|
19
|
+
* Client tables.
|
|
20
|
+
*/
|
|
17
21
|
export type ClientTables<T extends Database.Service<any>> = {
|
|
18
|
-
[P in keyof TableSchemas<T>]: TableSchemas<T>[P] extends Database.Schema ? Table<TableSchemas<T>[P]> : never;
|
|
22
|
+
[P in keyof TableSchemas<T>]: TableSchemas<T>[P] extends Database.Schema ? Table<TableSchemas<T>[P], P extends keyof TableIndexes<T> ? TableIndexes<T>[P] extends string ? TableIndexes<T>[P] : never : never> : never;
|
|
19
23
|
};
|
|
20
|
-
|
|
24
|
+
/**
|
|
25
|
+
* Client table.
|
|
26
|
+
*/
|
|
27
|
+
export interface Table<T extends Database.Schema, I extends string | never> {
|
|
21
28
|
insertOne(query: Query.InsertOneInput<T>): Promise<Query.InsertOneResult>;
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
data: T;
|
|
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
|
-
};
|
|
42
|
-
type UpdateManyInput<T extends Database.Schema, S extends Database.Schema> = {
|
|
43
|
-
select?: S;
|
|
44
|
-
data: DeepPartial<T>;
|
|
45
|
-
where?: WhereInput<T>;
|
|
46
|
-
cursor?: number | string;
|
|
47
|
-
limit?: number;
|
|
48
|
-
};
|
|
49
|
-
type FindManyInput<T extends Database.Schema, S extends Database.Schema> = {
|
|
50
|
-
select: S;
|
|
51
|
-
where?: WhereInput<T>;
|
|
52
|
-
cursor?: number | string;
|
|
53
|
-
limit?: number;
|
|
54
|
-
};
|
|
55
|
-
type DeleteManyInput<T extends Database.Schema, S extends Database.Schema> = {
|
|
56
|
-
select?: S;
|
|
57
|
-
where?: WhereInput<T>;
|
|
58
|
-
cursor?: number | string;
|
|
59
|
-
limit?: number;
|
|
60
|
-
};
|
|
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;
|
|
64
|
-
type UpdateManyResult<T extends Database.Schema, S extends AnyObject> = Record<T, S>[];
|
|
65
|
-
type FindManyResult<T extends Database.Schema, S extends AnyObject> = {
|
|
66
|
-
records: Record<T, S>[];
|
|
67
|
-
cursor?: number | string;
|
|
68
|
-
};
|
|
69
|
-
type DeleteManyResult<T extends Database.Schema, S extends AnyObject> = Record<T, S>[];
|
|
70
|
-
type Record<T extends Database.Schema, S extends AnyObject> = PartialObject<T, S, false>;
|
|
71
|
-
type SelectInput<T extends Database.Schema> = PartialProperties<T>;
|
|
72
|
-
type WhereInput<T extends Database.Schema> = WhereFields<T> & WhereNot<T> & WhereAnd<T> & WhereOr<T>;
|
|
73
|
-
type WhereFields<T extends Database.Schema> = {
|
|
74
|
-
[P in keyof T]?: T[P] extends AnyObject ? WhereFields<T[P]> : T[P] | WhereOperations<T[P]>;
|
|
75
|
-
};
|
|
76
|
-
type WhereNot<T extends Database.Schema> = {
|
|
77
|
-
NOT?: WhereInput<T> | WhereAnd<T> | WhereOr<T>;
|
|
78
|
-
};
|
|
79
|
-
type WhereAnd<T extends Database.Schema> = {
|
|
80
|
-
AND?: (WhereInput<T> | WhereOr<T> | WhereNot<T>)[];
|
|
81
|
-
};
|
|
82
|
-
type WhereOr<T extends Database.Schema> = {
|
|
83
|
-
OR?: (WhereInput<T> | WhereAnd<T> | WhereNot<T>)[];
|
|
84
|
-
};
|
|
85
|
-
type WhereOperations<T> = WhereNegate<T> | WhereEqual<T> | WhereGreaterThan<T> | WhereGreaterThanOrEqual<T> | WhereLessThan<T> | WhereLessThanOrEqual<T> | WhereIn<T> | WhereBetween<T> | WhereIsMissing | WhereIsNull | WhereStartsWith | WhereContains;
|
|
86
|
-
type WhereOperators = keyof (WhereNegate<any> & WhereEqual<any> & WhereGreaterThan<any> & WhereGreaterThanOrEqual<any> & WhereLessThan<any> & WhereLessThanOrEqual<any> & WhereIn<any> & WhereBetween<any> & WhereIsMissing & WhereIsNull & WhereStartsWith & WhereContains);
|
|
87
|
-
type WhereNegate<T> = {
|
|
88
|
-
not: T | WhereOperations<T>;
|
|
89
|
-
};
|
|
90
|
-
type WhereEqual<T> = {
|
|
91
|
-
equal: T;
|
|
92
|
-
};
|
|
93
|
-
type WhereGreaterThan<T> = {
|
|
94
|
-
gt: T;
|
|
95
|
-
};
|
|
96
|
-
type WhereGreaterThanOrEqual<T> = {
|
|
97
|
-
gte: T;
|
|
98
|
-
};
|
|
99
|
-
type WhereLessThan<T> = {
|
|
100
|
-
lt: T;
|
|
101
|
-
};
|
|
102
|
-
type WhereLessThanOrEqual<T> = {
|
|
103
|
-
lte: T;
|
|
104
|
-
};
|
|
105
|
-
type WhereIn<T> = {
|
|
106
|
-
isIn: T[];
|
|
107
|
-
};
|
|
108
|
-
type WhereBetween<T> = {
|
|
109
|
-
isBetween: [T, T];
|
|
110
|
-
};
|
|
111
|
-
type WhereIsMissing = {
|
|
112
|
-
isMissing: boolean;
|
|
113
|
-
};
|
|
114
|
-
type WhereIsNull = {
|
|
115
|
-
isNull: boolean;
|
|
116
|
-
};
|
|
117
|
-
type WhereStartsWith = {
|
|
118
|
-
startsWith: string;
|
|
119
|
-
};
|
|
120
|
-
type WhereContains = {
|
|
121
|
-
contains: string;
|
|
122
|
-
};
|
|
29
|
+
updateOne<S extends Query.SelectInput<T>>(query: Query.UpdateOneInput<T, S, I>): Promise<Query.UpdateOneResult<T, S>>;
|
|
30
|
+
findOne<S extends Query.SelectInput<T>>(query: Query.FindOneInput<T, S, I>): Promise<Query.FindOneResult<T, S>>;
|
|
31
|
+
upsertOne<S extends Query.SelectInput<T>>(query: Query.UpsertOneInput<T, S, I>): Promise<Query.UpsertOneResult<T, S>>;
|
|
32
|
+
deleteOne<S extends Query.SelectInput<T>>(query: Query.DeleteOneInput<T, S, I>): Promise<Query.DeleteOneResult<T, S>>;
|
|
33
|
+
insertMany(query: Query.InsertManyInput<T>): Promise<Query.InsertManyResult>;
|
|
34
|
+
updateMany<S extends Query.SelectInput<T>>(query: Query.UpdateManyInput<T, S>): Promise<Query.UpdateManyResult<T, S>>;
|
|
35
|
+
findMany<S extends Query.SelectInput<T>>(query: Query.FindManyInput<T, S>): Promise<Query.FindManyResult<T, S>>;
|
|
36
|
+
deleteMany<S extends Query.SelectInput<T>>(query: Query.DeleteManyInput<T, S>): Promise<Query.DeleteManyResult<T, S>>;
|
|
123
37
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { Service } from '@ez4/common';
|
|
2
2
|
import type { LinkedVariables } from '@ez4/project/library';
|
|
3
|
+
import type { StreamChange } from './streams.js';
|
|
3
4
|
import type { TableTypes } from './helpers.js';
|
|
4
|
-
import type { StreamChange } from './stream.js';
|
|
5
|
-
import type { Index } from './indexes.js';
|
|
6
5
|
import type { Client } from './client.js';
|
|
6
|
+
import type { Index } from './indexes.js';
|
|
7
7
|
/**
|
|
8
8
|
* Provide all contracts for a self-managed database service.
|
|
9
9
|
*/
|
|
@@ -4,27 +4,9 @@ import type { Database } from './database.js';
|
|
|
4
4
|
* Given an array of schemas `T`, it returns an union of `Database.Table` for each schema.
|
|
5
5
|
*/
|
|
6
6
|
export type TableTypes<T extends Database.Schema[]> = IsAny<T> extends true ? any : IsArrayEmpty<T> extends true ? Database.Table<Database.Schema> : Database.Table<T[0]> | TableTypes<ArrayRest<T>>;
|
|
7
|
-
/**
|
|
8
|
-
* Given a database service `T`, it returns a map containing all its tables and schemas.
|
|
9
|
-
*/
|
|
10
|
-
export type TableSchemas<T extends Database.Service<any>> = MergeTables<ServiceTables<T>>;
|
|
11
7
|
/**
|
|
12
8
|
* Given a database service `T`, it returns all its table types.
|
|
13
9
|
*/
|
|
14
|
-
type
|
|
10
|
+
export type DatabaseTables<T> = T extends {
|
|
15
11
|
tables: infer U;
|
|
16
12
|
} ? U : [];
|
|
17
|
-
/**
|
|
18
|
-
* Given a list of database tables `T`, it returns an object containing all table names and schemas.
|
|
19
|
-
*/
|
|
20
|
-
type MergeTables<T extends Database.Table[]> = IsArrayEmpty<T> extends true ? {} : TableRecord<T[0]> & MergeTables<ArrayRest<T>>;
|
|
21
|
-
/**
|
|
22
|
-
* Given a database table `T`, it returns a table record containing its `name` and `schema`.
|
|
23
|
-
*/
|
|
24
|
-
type TableRecord<T> = T extends {
|
|
25
|
-
name: infer N;
|
|
26
|
-
schema: infer S;
|
|
27
|
-
} ? N extends string ? {
|
|
28
|
-
[P in N]: S;
|
|
29
|
-
} : {} : {};
|
|
30
|
-
export {};
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import type { ArrayRest, IsArrayEmpty } from '@ez4/utils';
|
|
2
|
+
import type { DatabaseTables } from './helpers.js';
|
|
3
|
+
import type { Database } from './database.js';
|
|
1
4
|
/**
|
|
2
5
|
* All supported index types.
|
|
3
6
|
*/
|
|
@@ -7,3 +10,32 @@ export declare const enum Index {
|
|
|
7
10
|
Unique = "unique",
|
|
8
11
|
TTL = "ttl"
|
|
9
12
|
}
|
|
13
|
+
/**
|
|
14
|
+
* Given an index name `T`, it produces the decomposed index names.
|
|
15
|
+
*/
|
|
16
|
+
export type DecomposeIndexName<T> = T extends `${infer L}:${infer R}` ? L | DecomposeIndexName<R> : T;
|
|
17
|
+
/**
|
|
18
|
+
* Given an index object `T`, it produces an index object containing only unique indexes.
|
|
19
|
+
*/
|
|
20
|
+
export type UniqueIndexes<T> = {
|
|
21
|
+
[P in keyof T as T[P] extends Index.Primary | Index.Unique ? P : never]: T[P];
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Given a database service `T`, it produces an object containing all tables with indexes.
|
|
25
|
+
*/
|
|
26
|
+
export type TableIndexes<T extends Database.Service<any>> = MergeIndexes<DatabaseTables<T>>;
|
|
27
|
+
/**
|
|
28
|
+
* Given a list of tables with indexes `T`, it produces an object containing all primary
|
|
29
|
+
* indexes mapped by table name.
|
|
30
|
+
*/
|
|
31
|
+
type MergeIndexes<T extends Database.Table[]> = IsArrayEmpty<T> extends true ? {} : TableIndex<T[0]> & MergeIndexes<ArrayRest<T>>;
|
|
32
|
+
/**
|
|
33
|
+
* Given a database table `T`, it produces an object containing all the primary index names.
|
|
34
|
+
*/
|
|
35
|
+
type TableIndex<T> = T extends {
|
|
36
|
+
name: infer N;
|
|
37
|
+
indexes: infer I;
|
|
38
|
+
} ? N extends string ? {
|
|
39
|
+
[P in N]: DecomposeIndexName<keyof UniqueIndexes<I>>;
|
|
40
|
+
} : {} : {};
|
|
41
|
+
export {};
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import type { AnyObject, PartialProperties, PartialObject, DeepPartial } from '@ez4/utils';
|
|
2
|
+
import type { Database } from './database.js';
|
|
3
|
+
export declare namespace Query {
|
|
4
|
+
type InsertOneInput<T extends Database.Schema> = {
|
|
5
|
+
data: T;
|
|
6
|
+
};
|
|
7
|
+
type UpdateOneInput<T extends Database.Schema, S extends Database.Schema, I extends string | never> = {
|
|
8
|
+
select?: S;
|
|
9
|
+
data: DeepPartial<T>;
|
|
10
|
+
where: WhereInput<T, I>;
|
|
11
|
+
};
|
|
12
|
+
type FindOneInput<T extends Database.Schema, S extends Database.Schema, I extends string | never> = {
|
|
13
|
+
select: S;
|
|
14
|
+
where: WhereInput<T, I>;
|
|
15
|
+
};
|
|
16
|
+
type UpsertOneInput<T extends Database.Schema, S extends Database.Schema, I extends string | never> = {
|
|
17
|
+
select?: S;
|
|
18
|
+
insert: T;
|
|
19
|
+
update: DeepPartial<T>;
|
|
20
|
+
where: WhereInput<T, I>;
|
|
21
|
+
};
|
|
22
|
+
type DeleteOneInput<T extends Database.Schema, S extends Database.Schema, I extends string | never> = {
|
|
23
|
+
select?: S;
|
|
24
|
+
where: WhereInput<T, I>;
|
|
25
|
+
};
|
|
26
|
+
type InsertManyInput<T extends Database.Schema> = {
|
|
27
|
+
data: T[];
|
|
28
|
+
};
|
|
29
|
+
type UpdateManyInput<T extends Database.Schema, S extends Database.Schema> = {
|
|
30
|
+
select?: S;
|
|
31
|
+
data: DeepPartial<T>;
|
|
32
|
+
where?: WhereInput<T>;
|
|
33
|
+
limit?: number;
|
|
34
|
+
};
|
|
35
|
+
type FindManyInput<T extends Database.Schema, S extends Database.Schema> = {
|
|
36
|
+
select: S;
|
|
37
|
+
where?: WhereInput<T>;
|
|
38
|
+
cursor?: number | string;
|
|
39
|
+
limit?: number;
|
|
40
|
+
};
|
|
41
|
+
type DeleteManyInput<T extends Database.Schema, S extends Database.Schema> = {
|
|
42
|
+
select?: S;
|
|
43
|
+
where?: WhereInput<T>;
|
|
44
|
+
limit?: number;
|
|
45
|
+
};
|
|
46
|
+
type InsertOneResult = void;
|
|
47
|
+
type UpdateOneResult<T extends Database.Schema, S extends AnyObject> = FindOneResult<T, S> | undefined;
|
|
48
|
+
type FindOneResult<T extends Database.Schema, S extends AnyObject> = Record<T, S> | undefined;
|
|
49
|
+
type UpsertOneResult<T extends Database.Schema, S extends AnyObject> = FindOneResult<T, S> | undefined;
|
|
50
|
+
type DeleteOneResult<T extends Database.Schema, S extends AnyObject> = FindOneResult<T, S> | undefined;
|
|
51
|
+
type InsertManyResult = void;
|
|
52
|
+
type UpdateManyResult<T extends Database.Schema, S extends AnyObject> = Record<T, S>[];
|
|
53
|
+
type FindManyResult<T extends Database.Schema, S extends AnyObject> = {
|
|
54
|
+
records: Record<T, S>[];
|
|
55
|
+
cursor?: number | string;
|
|
56
|
+
};
|
|
57
|
+
type DeleteManyResult<T extends Database.Schema, S extends AnyObject> = Record<T, S>[];
|
|
58
|
+
type Record<T extends Database.Schema, S extends AnyObject> = PartialObject<T, S, false>;
|
|
59
|
+
type SelectInput<T extends Database.Schema> = PartialProperties<T>;
|
|
60
|
+
type WhereInput<T extends Database.Schema, I extends string | never = never> = WhereFields<T, I> & WhereNot<T, I> & WhereAnd<T, I> & WhereOr<T, I>;
|
|
61
|
+
type WhereRequiredFields<T extends Database.Schema, I extends string | never> = {
|
|
62
|
+
[P in I]: P extends keyof T ? T[P] extends AnyObject ? WhereFields<T[P], I> : T[P] | WhereOperations<T[P]> : never;
|
|
63
|
+
};
|
|
64
|
+
type WhereOptionalFields<T extends Database.Schema, I extends string | never> = {
|
|
65
|
+
[P in Exclude<keyof T, I>]?: T[P] extends AnyObject ? WhereFields<T[P], I> : T[P] | WhereOperations<T[P]>;
|
|
66
|
+
};
|
|
67
|
+
type WhereFields<T extends Database.Schema, I extends string | never> = WhereRequiredFields<T, I> & WhereOptionalFields<T, I>;
|
|
68
|
+
type WhereNot<T extends Database.Schema, I extends string | never> = {
|
|
69
|
+
NOT?: WhereInput<T, I> | WhereAnd<T, I> | WhereOr<T, I>;
|
|
70
|
+
};
|
|
71
|
+
type WhereAnd<T extends Database.Schema, I extends string | never> = {
|
|
72
|
+
AND?: (WhereInput<T, I> | WhereOr<T, I> | WhereNot<T, I>)[];
|
|
73
|
+
};
|
|
74
|
+
type WhereOr<T extends Database.Schema, I extends string | never> = {
|
|
75
|
+
OR?: (WhereInput<T, I> | WhereAnd<T, I> | WhereNot<T, I>)[];
|
|
76
|
+
};
|
|
77
|
+
type WhereOperations<T> = WhereNegate<T> | WhereEqual<T> | WhereGreaterThan<T> | WhereGreaterThanOrEqual<T> | WhereLessThan<T> | WhereLessThanOrEqual<T> | WhereIn<T> | WhereBetween<T> | WhereIsMissing | WhereIsNull | WhereStartsWith | WhereContains;
|
|
78
|
+
type WhereOperators = keyof (WhereNegate<any> & WhereEqual<any> & WhereGreaterThan<any> & WhereGreaterThanOrEqual<any> & WhereLessThan<any> & WhereLessThanOrEqual<any> & WhereIn<any> & WhereBetween<any> & WhereIsMissing & WhereIsNull & WhereStartsWith & WhereContains);
|
|
79
|
+
type WhereNegate<T> = {
|
|
80
|
+
not: T | WhereOperations<T>;
|
|
81
|
+
};
|
|
82
|
+
type WhereEqual<T> = {
|
|
83
|
+
equal: T;
|
|
84
|
+
};
|
|
85
|
+
type WhereGreaterThan<T> = {
|
|
86
|
+
gt: T;
|
|
87
|
+
};
|
|
88
|
+
type WhereGreaterThanOrEqual<T> = {
|
|
89
|
+
gte: T;
|
|
90
|
+
};
|
|
91
|
+
type WhereLessThan<T> = {
|
|
92
|
+
lt: T;
|
|
93
|
+
};
|
|
94
|
+
type WhereLessThanOrEqual<T> = {
|
|
95
|
+
lte: T;
|
|
96
|
+
};
|
|
97
|
+
type WhereIn<T> = {
|
|
98
|
+
isIn: T[];
|
|
99
|
+
};
|
|
100
|
+
type WhereBetween<T> = {
|
|
101
|
+
isBetween: [T, T];
|
|
102
|
+
};
|
|
103
|
+
type WhereIsMissing = {
|
|
104
|
+
isMissing: boolean;
|
|
105
|
+
};
|
|
106
|
+
type WhereIsNull = {
|
|
107
|
+
isNull: boolean;
|
|
108
|
+
};
|
|
109
|
+
type WhereStartsWith = {
|
|
110
|
+
startsWith: string;
|
|
111
|
+
};
|
|
112
|
+
type WhereContains = {
|
|
113
|
+
contains: string;
|
|
114
|
+
};
|
|
115
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { ArrayRest, IsArrayEmpty } from '@ez4/utils';
|
|
2
|
+
import type { DatabaseTables } from './helpers.js';
|
|
3
|
+
import type { Database } from './database.js';
|
|
4
|
+
/**
|
|
5
|
+
* Given a database service `T`, it produces an object containing all tables with schemas.
|
|
6
|
+
*/
|
|
7
|
+
export type TableSchemas<T extends Database.Service<any>> = MergeTables<DatabaseTables<T>>;
|
|
8
|
+
/**
|
|
9
|
+
* Given a list of tables with schema `T`, it produces an object containing all schemas
|
|
10
|
+
* mapped by table name.
|
|
11
|
+
*/
|
|
12
|
+
type MergeTables<T extends Database.Table[]> = IsArrayEmpty<T> extends true ? {} : TableSchema<T[0]> & MergeTables<ArrayRest<T>>;
|
|
13
|
+
/**
|
|
14
|
+
* Given a database table `T`, it produces an object containing the `schema`.
|
|
15
|
+
*/
|
|
16
|
+
type TableSchema<T> = T extends {
|
|
17
|
+
name: infer N;
|
|
18
|
+
schema: infer S;
|
|
19
|
+
} ? N extends string ? {
|
|
20
|
+
[P in N]: S;
|
|
21
|
+
} : {} : {};
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stream change for `insert`, `update` or `delete` operations.
|
|
3
|
+
*/
|
|
4
|
+
export type StreamChange<T> = StreamInsertChange<T> | StreamUpdateChange<T> | StreamDeleteChange<T>;
|
|
5
|
+
/**
|
|
6
|
+
* Stream change for an `insert` operation.
|
|
7
|
+
*/
|
|
8
|
+
export type StreamInsertChange<T> = {
|
|
9
|
+
type: StreamType.Insert;
|
|
10
|
+
record: T;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Stream change for an `update` operation.
|
|
14
|
+
*/
|
|
15
|
+
export type StreamUpdateChange<T> = {
|
|
16
|
+
type: StreamType.Update;
|
|
17
|
+
oldRecord: T;
|
|
18
|
+
newRecord: T;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Stream change for an `delete` operation.
|
|
22
|
+
*/
|
|
23
|
+
export type StreamDeleteChange<T> = {
|
|
24
|
+
type: StreamType.Delete;
|
|
25
|
+
record: T;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Stream change types.
|
|
29
|
+
*/
|
|
30
|
+
export declare const enum StreamType {
|
|
31
|
+
Insert = "insert",
|
|
32
|
+
Update = "update",
|
|
33
|
+
Delete = "delete"
|
|
34
|
+
}
|
package/package.json
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ez4/database",
|
|
3
3
|
"description": "EZ4: Components to build database services",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.4.0",
|
|
5
5
|
"author": "Silas B.",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"type": "module",
|
|
8
|
+
"engines": {
|
|
9
|
+
"node": ">=20.15.0"
|
|
10
|
+
},
|
|
8
11
|
"exports": {
|
|
9
12
|
".": {
|
|
10
13
|
"types": "./dist/main.d.ts",
|
|
@@ -31,10 +34,10 @@
|
|
|
31
34
|
"live:publish": "npm run test && npm publish --access public"
|
|
32
35
|
},
|
|
33
36
|
"dependencies": {
|
|
34
|
-
"@ez4/common": "^0.
|
|
35
|
-
"@ez4/project": "^0.
|
|
36
|
-
"@ez4/reflection": "^0.
|
|
37
|
-
"@ez4/schema": "^0.
|
|
38
|
-
"@ez4/utils": "^0.
|
|
37
|
+
"@ez4/common": "^0.4.0",
|
|
38
|
+
"@ez4/project": "^0.4.0",
|
|
39
|
+
"@ez4/reflection": "^0.4.0",
|
|
40
|
+
"@ez4/schema": "^0.4.0",
|
|
41
|
+
"@ez4/utils": "^0.4.0"
|
|
39
42
|
}
|
|
40
43
|
}
|