@ez4/database 0.33.0 → 0.35.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/dist/library.cjs +17 -17
- package/dist/library.mjs +17 -17
- package/dist/main.cjs +8 -8
- package/dist/main.d.ts +2 -2
- package/dist/main.mjs +4 -4
- package/dist/services/client.d.ts +1 -1
- package/dist/services/common.d.ts +25 -0
- package/dist/services/contract.d.ts +61 -0
- package/dist/services/engine.d.ts +1 -1
- package/dist/services/indexes.d.ts +16 -10
- package/dist/services/order.d.ts +1 -1
- package/dist/services/parameters.d.ts +1 -1
- package/dist/services/query.d.ts +3 -3
- package/dist/services/relations.d.ts +33 -27
- package/dist/services/scalability.d.ts +7 -0
- package/dist/services/schemas.d.ts +10 -4
- package/dist/services/streams.d.ts +42 -10
- package/dist/services/table.d.ts +36 -4
- package/dist/services/transaction.d.ts +1 -1
- package/package.json +6 -6
package/dist/library.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";var X=Object.defineProperty;var Xe=Object.getOwnPropertyDescriptor;var Ye=Object.getOwnPropertyNames;var Ze=Object.prototype.hasOwnProperty;var a=(e,t)=>X(e,"name",{value:t,configurable:!0});var Le=(e,t)=>{for(var r in t)X(e,r,{get:t[r],enumerable:!0})},er=(e,t,r,n)=>{if(t&&
|
|
2
2
|
typeof t=="object"||typeof t=="function")for(let o of Ye(t))!Ze.call(e,o)&&o!==r&&
|
|
3
|
-
X(e,o,{get:()=>t[o],enumerable:!(n=Xe(t,o))||n.enumerable});return e};var rr=e=>er(X({},"__esModule",{value:!0}),e);var
|
|
3
|
+
X(e,o,{get:()=>t[o],enumerable:!(n=Xe(t,o))||n.enumerable});return e};var rr=e=>er(X({},"__esModule",{value:!0}),e);var br={};Le(br,{IncompleteEngineError:()=>F,IncompleteHandlerError:()=>W,IncompleteScalabilityError:()=>H,
|
|
4
4
|
IncompleteServiceError:()=>j,IncompleteStreamError:()=>J,IncompleteTableError:()=>U,
|
|
5
5
|
IncorrectIndexesTypeError:()=>$,IncorrectRelationsTypeError:()=>R,IncorrectSchemaTypeError:()=>G,
|
|
6
6
|
IncorrectStreamTypeError:()=>Q,Index:()=>Oe,InvalidIndexReferenceError:()=>_,InvalidIndexTypeError:()=>q,
|
|
@@ -8,7 +8,7 @@ InvalidIndexesTypeError:()=>V,InvalidRelationAliasError:()=>N,InvalidRelationCol
|
|
|
8
8
|
InvalidRelationTableError:()=>C,InvalidRelationTargetError:()=>z,InvalidRelationsTypeError:()=>A,
|
|
9
9
|
InvalidSchemaTypeError:()=>B,InvalidStreamTypeError:()=>K,ServiceType:()=>Y,getDatabaseServices:()=>me,
|
|
10
10
|
getDatabaseTable:()=>pe,getTableSchema:()=>ie,isDatabaseService:()=>tr,registerTriggers:()=>fr});
|
|
11
|
-
module.exports=rr(
|
|
11
|
+
module.exports=rr(br);var Je=require("@ez4/common/library"),Ke=require("@ez4/schema/library"),Qe=require("@ez4/project/library");var f=require("@ez4/common/library"),Be=require("@ez4/reflection");var Y="@ez4/database",tr=a(e=>e.type===Y,"isDatabaseService");var le=require("@ez4/common/library");var j=class extends le.IncompleteTypeError{static{a(this,"IncompleteServiceError")}constructor(t,r){
|
|
12
12
|
super("Incomplete database service",t,r)}};var g=require("@ez4/common/library");var A=class extends g.InvalidTypeError{static{a(this,"InvalidRelationsTypeError")}constructor(t){
|
|
13
13
|
super("Invalid table relations type",void 0,"Database.Relations",t)}},R=class extends g.IncorrectTypeError{constructor(r,n){
|
|
14
14
|
super("Incorrect table relations type",r,"Database.Relations",n);this.schemaType=
|
|
@@ -20,22 +20,22 @@ super(`Relation table ${r} don't exists.`,n);this.relationTable=r}static{a(this,
|
|
|
20
20
|
`Relation column ${r} don't exists.`,n);this.relationColumn=r}static{a(this,"Inv\
|
|
21
21
|
alidRelationColumnError")}},N=class extends g.TypeError{constructor(r,n){super(`\
|
|
22
22
|
Relation alias ${r} can't override table columns.`,n);this.relationAlias=r}static{
|
|
23
|
-
a(this,"InvalidRelationAliasError")}};var
|
|
24
|
-
rror")}constructor(t,r){super("Incomplete database scalability",t,r)}};var
|
|
25
|
-
e"),"isDatabaseService"),ee=a(e=>(0,
|
|
26
|
-
e,"Database.Engine"),"isDatabaseEngine"),fe=a(e=>(0,
|
|
27
|
-
e,"Database.Table"),"isDatabaseTable"),
|
|
28
|
-
e),"isStreamHandler"),
|
|
29
|
-
ableRelations"),Te=a(e=>(0,
|
|
30
|
-
xes"),ye=a(e=>(0,
|
|
31
|
-
e,"Database.Stream"),"isTableStream");var Se=a((e,t,r,n)=>{if(!(0,I.isTypeReference)(e))return ge(e,t,n);let o=(0,
|
|
23
|
+
a(this,"InvalidRelationAliasError")}};var u=require("@ez4/common/library"),I=require("@ez4/reflection"),re=require("@ez4/utils");var de=require("@ez4/common/library");var H=class extends de.IncompleteTypeError{static{a(this,"IncompleteScalabilityE\
|
|
24
|
+
rror")}constructor(t,r){super("Incomplete database scalability",t,r)}};var b=require("@ez4/common/library"),Z=require("@ez4/reflection");var L=a(e=>(0,b.isClassDeclaration)(e)&&(0,b.hasHeritageType)(e,"Database.Servic\
|
|
25
|
+
e"),"isDatabaseService"),ee=a(e=>(0,b.isModelDeclaration)(e)&&(0,b.hasHeritageType)(
|
|
26
|
+
e,"Database.Engine"),"isDatabaseEngine"),fe=a(e=>(0,b.isModelDeclaration)(e)&&(0,b.hasHeritageType)(
|
|
27
|
+
e,"Database.Table"),"isDatabaseTable"),be=a(e=>(0,Z.isTypeCallback)(e)||(0,Z.isTypeFunction)(
|
|
28
|
+
e),"isStreamHandler"),ue=a(e=>(0,b.hasHeritageType)(e,"Database.Relations"),"isT\
|
|
29
|
+
ableRelations"),Te=a(e=>(0,b.hasHeritageType)(e,"Database.Indexes"),"isTableInde\
|
|
30
|
+
xes"),ye=a(e=>(0,b.hasHeritageType)(e,"Database.Schema"),"isTableSchema"),xe=a(e=>(0,b.hasHeritageType)(
|
|
31
|
+
e,"Database.Stream"),"isTableStream");var Se=a((e,t,r,n)=>{if(!(0,I.isTypeReference)(e))return ge(e,t,n);let o=(0,u.getReferenceType)(
|
|
32
32
|
e,r);if(o)return ge(o,t,n)},"getDatabaseScalability"),or=a(e=>(0,re.isAnyNumber)(
|
|
33
33
|
e.minCapacity)&&(0,re.isAnyNumber)(e.maxCapacity),"isValidScalability"),ge=a((e,t,r)=>{
|
|
34
|
-
if(ee(e))return Me(e,t,(0,
|
|
35
|
-
e,t,(0,
|
|
34
|
+
if(ee(e))return Me(e,t,(0,u.getModelMembers)(e),r);if((0,I.isTypeObject)(e))return Me(
|
|
35
|
+
e,t,(0,u.getObjectMembers)(e),r)},"getTypeScalability"),Me=a((e,t,r,n)=>{let o={},
|
|
36
36
|
s=new Set(["minCapacity","maxCapacity"]);for(let i of r)if(!(!(0,I.isModelProperty)(
|
|
37
|
-
i)||i.inherited))switch(i.name){default:n.push(new
|
|
38
|
-
t.name,i.name,e.file));break;case"minCapacity":case"maxCapacity":let p=(0,
|
|
37
|
+
i)||i.inherited))switch(i.name){default:n.push(new u.InvalidServicePropertyError(
|
|
38
|
+
t.name,i.name,e.file));break;case"minCapacity":case"maxCapacity":let p=(0,u.getPropertyNumber)(
|
|
39
39
|
i);(0,re.isAnyNumber)(p)&&(o[i.name]=p,s.delete(i.name));break}if(!or(o)){n.push(
|
|
40
40
|
new H([...s],e.file));return}return o},"getTypeFromMembers");var h=require("@ez4/reflection"),l=require("@ez4/common/library");var Ie=require("@ez4/common/library");var F=class extends Ie.IncompleteTypeError{static{a(this,"IncompleteEngineError")}constructor(t,r){
|
|
41
41
|
super("Incomplete database engine",t,r)}};var ve=a((e,t,r,n)=>{if(!(0,h.isTypeReference)(e))return he(e,t,n);let o=(0,l.getReferenceType)(
|
|
@@ -66,7 +66,7 @@ super(`Invalid index reference, ${r} must be valid column.`,n);this.indexName=r}
|
|
|
66
66
|
a(this,"InvalidIndexReferenceError")}};var T=require("@ez4/common/library"),D=require("@ez4/reflection");var we=a((e,t,r,n)=>{if(!(0,D.isTypeReference)(e))return Pe(e,t,n);let o=(0,T.getReferenceType)(
|
|
67
67
|
e,r);if(o)return Pe(o,t,n)},"getTableRelations"),Pe=a((e,t,r)=>{if((0,D.isTypeObject)(
|
|
68
68
|
e))return ke(e,(0,T.getObjectMembers)(e),r);if(!(0,T.isModelDeclaration)(e)){r.push(
|
|
69
|
-
new A(t.file));return}if(!
|
|
69
|
+
new A(t.file));return}if(!ue(e)){r.push(new R(e.name,e.file));return}return ke(e,
|
|
70
70
|
(0,T.getModelMembers)(e),r)},"getTypeRelations"),ke=a((e,t,r)=>{let n=[];for(let o of t){
|
|
71
71
|
if(!(0,D.isModelProperty)(o)||o.inherited)continue;let s=(0,T.getPropertyString)(
|
|
72
72
|
o),i=o.name;if(!s){r.push(new z(i,e.file));return}let[p,m]=i.split("@",2),[c,O]=s.
|
|
@@ -94,7 +94,7 @@ a(this,"InvalidStreamTypeError")}constructor(t){super("Invalid table stream type
|
|
|
94
94
|
void 0,"Database.Stream",t)}},Q=class extends P.IncorrectTypeError{constructor(r,n){
|
|
95
95
|
super("Incorrect table stream type",r,"Database.Stream",n);this.streamType=r}static{
|
|
96
96
|
a(this,"IncorrectStreamTypeError")}};var Ne=require("@ez4/common/library");var W=class extends Ne.IncompleteTypeError{static{a(this,"IncompleteHandlerError")}constructor(t,r){
|
|
97
|
-
super("Incomplete stream handler",t,r)}};var He=a((e,t,r)=>{if(!
|
|
97
|
+
super("Incomplete stream handler",t,r)}};var He=a((e,t,r)=>{if(!be(e))return;let{description:n,module:o}=e,s={...n&&{description:n},
|
|
98
98
|
...o&&{module:o}},i=new Set(["name","file","change"]);if((s.name=e.name)&&i.delete(
|
|
99
99
|
"name"),(s.file=e.file)&&i.delete("file"),e.parameters&&i.delete("change"),i.size===
|
|
100
100
|
0&&ar(s))return s;r.push(new W([...i],e.file))},"getStreamHandler"),ar=a(e=>!!e.
|
package/dist/library.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
var Ie=Object.defineProperty;var n=(e,t)=>Ie(e,"name",{value:t,configurable:!0});import{registerTriggers as mt}from"@ez4/common/library";import{registerTriggers as ct}from"@ez4/schema/library";
|
|
2
2
|
import{tryCreateTrigger as lt}from"@ez4/project/library";import{DuplicateServiceError as Yr,InvalidServicePropertyError as Zr,isExternalDeclaration as Lr,
|
|
3
3
|
getLinkedServiceList as et,getLinkedVariableList as rt,getPropertyTuple as tt,getModelMembers as ot}from"@ez4/common/library";
|
|
4
|
-
import{isModelProperty as nt}from"@ez4/reflection";var U="@ez4/database",ft=n(e=>e.type===U,"isDatabaseService");import{IncompleteTypeError as he}from"@ez4/common/library";var
|
|
4
|
+
import{isModelProperty as nt}from"@ez4/reflection";var U="@ez4/database",ft=n(e=>e.type===U,"isDatabaseService");import{IncompleteTypeError as he}from"@ez4/common/library";var u=class extends he{static{n(this,"IncompleteServiceError")}constructor(t,r){
|
|
5
5
|
super("Incomplete database service",t,r)}};import{IncorrectTypeError as De,InvalidTypeError as ve,TypeError as S}from"@ez4/common/library";var T=class extends ve{static{n(this,"InvalidRelationsTypeError")}constructor(t){
|
|
6
6
|
super("Invalid table relations type",void 0,"Database.Relations",t)}},y=class extends De{constructor(r,a){
|
|
7
7
|
super("Incorrect table relations type",r,"Database.Relations",a);this.schemaType=
|
|
@@ -9,7 +9,7 @@ r}static{n(this,"IncorrectRelationsTypeError")}},x=class extends S{constructor(r
|
|
|
9
9
|
super(`Target ${r} must follow the pattern 'column@alias'.`,a);this.relationSource=
|
|
10
10
|
r}static{n(this,"InvalidRelationTargetError")}},g=class extends S{constructor(r,a){
|
|
11
11
|
super(`Relation table ${r} don't exists.`,a);this.relationTable=r}static{n(this,
|
|
12
|
-
"InvalidRelationTableError")}},
|
|
12
|
+
"InvalidRelationTableError")}},b=class extends S{constructor(r,a){super(`Relatio\
|
|
13
13
|
n column ${r} don't exists.`,a);this.relationColumn=r}static{n(this,"InvalidRela\
|
|
14
14
|
tionColumnError")}},M=class extends S{constructor(r,a){super(`Relation alias ${r}\
|
|
15
15
|
can't override table columns.`,a);this.relationAlias=r}static{n(this,"InvalidRe\
|
|
@@ -66,8 +66,8 @@ o.inherited)continue;let s=rr(o),i=o.name;if(!s){r.push(new x(i,e.file));return}
|
|
|
66
66
|
let[p,m]=i.split("@",2),[c,f]=s.split(":",2);a.push({sourceTable:c,sourceColumn:f,
|
|
67
67
|
targetColumn:p,targetAlias:m})}return a},"getTypeFromMembers");import{isModelDeclaration as ir,getModelMembers as pr,getObjectMembers as mr,getPropertyString as cr,
|
|
68
68
|
getReferenceType as lr}from"@ez4/common/library";import{isModelProperty as dr,isTypeObject as fr,
|
|
69
|
-
isTypeReference as
|
|
70
|
-
"ttl",o))(sr||{});var ie=n((e,t,r,a)=>{if(!
|
|
69
|
+
isTypeReference as br}from"@ez4/reflection";var sr=(o=>(o.Primary="primary",o.Secondary="secondary",o.Unique="unique",o.TTL=
|
|
70
|
+
"ttl",o))(sr||{});var ie=n((e,t,r,a)=>{if(!br(e))return ae(e,t,a);let o=lr(e,r);if(o)return ae(o,t,
|
|
71
71
|
a)},"getTableIndexes"),ae=n((e,t,r)=>{if(fr(e))return se(e,mr(e),r);if(!ir(e)){r.
|
|
72
72
|
push(new P(t.file));return}if(!J(e)){r.push(new k(e.name,e.file));return}return se(
|
|
73
73
|
e,pr(e),r)},"getTypeIndexes"),se=n((e,t,r)=>{let a=[];for(let o of t){if(!dr(o)||
|
|
@@ -75,8 +75,8 @@ o.inherited)continue;let s=o.name,i=cr(o);switch(i){case"primary":case"secondary
|
|
|
75
75
|
unique":case"ttl":a.push({name:s,columns:s.split(":"),type:i});break;default:r.push(
|
|
76
76
|
new w(s,e.file));return}}return a},"getTypeFromMembers");import{createSchemaContext as yr,getObjectSchema as xr,isObjectSchema as gr}from"@ez4/schema/library";
|
|
77
77
|
import{getReferenceType as Mr,isModelDeclaration as Sr}from"@ez4/common/library";
|
|
78
|
-
import{isTypeObject as Ir,isTypeReference as hr}from"@ez4/reflection";import{IncorrectTypeError as
|
|
79
|
-
"Invalid table schema type",void 0,"Database.Schema",t)}},A=class extends
|
|
78
|
+
import{isTypeObject as Ir,isTypeReference as hr}from"@ez4/reflection";import{IncorrectTypeError as ur,InvalidTypeError as Tr}from"@ez4/common/library";var j=class extends Tr{static{n(this,"InvalidSchemaTypeError")}constructor(t){super(
|
|
79
|
+
"Invalid table schema type",void 0,"Database.Schema",t)}},A=class extends ur{constructor(r,a){
|
|
80
80
|
super("Incorrect table schema type",r,"Database.Schema",a);this.schemaType=r}static{
|
|
81
81
|
n(this,"IncorrectSchemaTypeError")}};var ce=n((e,t,r,a)=>{if(!hr(e))return pe(e,t,r,a);let o=Mr(e,r);if(o)return pe(o,
|
|
82
82
|
t,r,a)},"getTableSchema"),pe=n((e,t,r,a)=>{if(Ir(e))return me(e,r);if(!Sr(e)){a.
|
|
@@ -95,7 +95,7 @@ super("Incomplete stream handler",t,r)}};var le=n((e,t,r)=>{if(!B(e))return;let{
|
|
|
95
95
|
...o&&{module:o}},i=new Set(["name","file","change"]);if((s.name=e.name)&&i.delete(
|
|
96
96
|
"name"),(s.file=e.file)&&i.delete("file"),e.parameters&&i.delete("change"),i.size===
|
|
97
97
|
0&&kr(s))return s;r.push(new N([...i],e.file))},"getStreamHandler"),kr=n(e=>!!e.
|
|
98
|
-
name&&!!e.file,"isValidHandler");var
|
|
98
|
+
name&&!!e.file,"isValidHandler");var be=n((e,t,r,a)=>{if(!Ur(e))return de(e,t,r,a);let o=Nr(e,r);if(o)return de(o,
|
|
99
99
|
t,r,a)},"getTableStream"),Vr=n(e=>!!e.handler,"isValidStream"),de=n((e,t,r,a)=>{
|
|
100
100
|
if(Fr(e))return fe(e,t,Rr(e),r,a);if(!Or(e)){a.push(new z(t.file));return}if(!Q(
|
|
101
101
|
e)){a.push(new C(e.name,e.file));return}return fe(e,t,Ar(e),r,a)},"getTypeStream"),
|
|
@@ -104,15 +104,15 @@ inherited))switch(p.name){default:o.push(new wr(t.name,p.name,e.file));break;cas
|
|
|
104
104
|
handler":s.handler=le(p.value,a,o);break;case"listener":s.listener=Cr(p.value,o);
|
|
105
105
|
break;case"memory":case"logRetention":case"timeout":s[p.name]=zr(p);break;case"v\
|
|
106
106
|
ariables":s.variables=jr(p,o);break}if(Vr(s))return s;o.push(new R([...i],e.file))},
|
|
107
|
-
"getTypeFromMembers");var ye=n((e,t,r,a)=>{if(!Qr(e))return
|
|
107
|
+
"getTypeFromMembers");var ye=n((e,t,r,a)=>{if(!Qr(e))return ue(e,t,r,a);let o=Gr(e,r);if(o)return ue(o,
|
|
108
108
|
t,r,a)},"getDatabaseTable"),Wr=n(e=>!!e.name&&!!e.schema&&!!e.indexes,"isValidTa\
|
|
109
|
-
ble"),
|
|
109
|
+
ble"),ue=n((e,t,r,a)=>{if(_(e))return Te(e,t,qr(e),r,a);if(Kr(e))return Te(e,t,_r(
|
|
110
110
|
e),r,a)},"getTypeTable"),Te=n((e,t,r,a,o)=>{let s={},i=new Set(["name","schema",
|
|
111
111
|
"indexes"]);for(let m of r)if(!(!Jr(m)||m.inherited))switch(m.name){default:o.push(
|
|
112
112
|
new $r(t.name,m.name,e.file));break;case"name":(s.name=Br(m))&&i.delete(m.name);
|
|
113
113
|
break;case"schema":(s.schema=ce(m.value,e,a,o))&&i.delete(m.name);break;case"ind\
|
|
114
114
|
exes":(s.indexes=ie(m.value,e,a,o))&&i.delete(m.name);break;case"relations":s.relations=
|
|
115
|
-
ne(m.value,e,a,o);break;case"stream":s.stream=
|
|
115
|
+
ne(m.value,e,a,o);break;case"stream":s.stream=be(m.value,t,a,o);break}if(!Wr(s)){
|
|
116
116
|
o.push(new E([...i],e.file));return}let p=Xr(e,s.indexes,s.schema);if(p.length){
|
|
117
117
|
o.push(...p);return}return s},"getTypeFromMembers"),Xr=n((e,t,r)=>{let a=r.properties,
|
|
118
118
|
o=[];for(let{name:s,columns:i}of t)i.some(m=>!a[m])&&o.push(new O(s,e.file));return o},
|
|
@@ -123,24 +123,24 @@ p));break;case"client":break;case"scalability":(s.scalability=Y(c.value,o,e,r))&
|
|
|
123
123
|
i.delete(c.name);break;case"engine":(s.engine=ee(c.value,o,e,r))&&i.delete(c.name);
|
|
124
124
|
break;case"tables":(s.tables=st(c,o,e,r))&&i.delete(c.name);break;case"variables":
|
|
125
125
|
s.variables=rt(c,r);break;case"services":s.services=et(c,e,r);break}if(!at(s)){r.
|
|
126
|
-
push(new
|
|
126
|
+
push(new u([...i],p));continue}let m=it(o,s.tables);if(m.length){r.push(...m);continue}
|
|
127
127
|
if(t[o.name]){r.push(new Yr(o.name,p));continue}t[o.name]=s}return{services:t,errors:r}},
|
|
128
128
|
"getDatabaseServices"),at=n(e=>!!e.name&&!!e.tables&&!!e.context,"isValidService"),
|
|
129
129
|
st=n((e,t,r,a)=>{let o=tt(e)??[],s=[];for(let i of o){let p=ye(i,t,r,a);p&&s.push(
|
|
130
130
|
p)}return s},"getAllTables"),it=n((e,t)=>{let r=pt(t),a=[];for(let{relations:o,schema:s,
|
|
131
131
|
indexes:i}of t){if(!o)continue;let p=s.properties;for(let m of o){let{sourceTable:c,
|
|
132
|
-
sourceColumn:f,targetColumn:H,targetAlias:$}=m;p[H]||a.push(new
|
|
132
|
+
sourceColumn:f,targetColumn:H,targetAlias:$}=m;p[H]||a.push(new b(H,e.file)),p[$]&&
|
|
133
133
|
a.push(new M($,e.file));let F=r[c]?.schema.properties;F||a.push(new g(c,e.file)),
|
|
134
|
-
F&&!F[f]&&a.push(new
|
|
134
|
+
F&&!F[f]&&a.push(new b(f,e.file));let Se=r[c]?.indexes??[];m.sourceIndex=xe(Se,f),
|
|
135
135
|
m.targetIndex=xe(i,H)}}return a},"validateRelations"),xe=n((e,t)=>e.find(({name:r})=>r===
|
|
136
136
|
t)?.type,"getIndexType"),pt=n(e=>e.reduce((t,r)=>({...t,[r.name]:r}),{}),"getTab\
|
|
137
|
-
leMap");var Me=n(e=>h(e)?e.name:null,"getLinkedService");var
|
|
137
|
+
leMap");var Me=n(e=>h(e)?e.name:null,"getLinkedService");var un=n(()=>{mt(),ct(),lt("@ez4/database",{"metadata:getServices":ge,"metadata:\
|
|
138
138
|
getLinkedService":Me})},"registerTriggers");export{v as IncompleteEngineError,N as IncompleteHandlerError,I as IncompleteScalabilityError,
|
|
139
|
-
|
|
139
|
+
u as IncompleteServiceError,R as IncompleteStreamError,E as IncompleteTableError,
|
|
140
140
|
k as IncorrectIndexesTypeError,y as IncorrectRelationsTypeError,A as IncorrectSchemaTypeError,
|
|
141
141
|
C as IncorrectStreamTypeError,sr as Index,O as InvalidIndexReferenceError,w as InvalidIndexTypeError,
|
|
142
|
-
P as InvalidIndexesTypeError,M as InvalidRelationAliasError,
|
|
142
|
+
P as InvalidIndexesTypeError,M as InvalidRelationAliasError,b as InvalidRelationColumnError,
|
|
143
143
|
g as InvalidRelationTableError,x as InvalidRelationTargetError,T as InvalidRelationsTypeError,
|
|
144
144
|
j as InvalidSchemaTypeError,z as InvalidStreamTypeError,U as ServiceType,ge as getDatabaseServices,
|
|
145
|
-
ye as getDatabaseTable,ce as getTableSchema,ft as isDatabaseService,
|
|
145
|
+
ye as getDatabaseTable,ce as getTableSchema,ft as isDatabaseService,un as registerTriggers};
|
|
146
146
|
//# sourceMappingURL=library.mjs.map
|
package/dist/main.cjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
"use strict";var o=Object.defineProperty;var b=Object.getOwnPropertyDescriptor;var
|
|
2
|
-
typeof
|
|
3
|
-
o(
|
|
4
|
-
OrderMode:()=>
|
|
5
|
-
module.exports=f(D);var
|
|
6
|
-
AnyColumns="any",e))(
|
|
7
|
-
ttl",t))(
|
|
8
|
-
ParametersMode,
|
|
1
|
+
"use strict";var o=Object.defineProperty;var b=Object.getOwnPropertyDescriptor;var I=Object.getOwnPropertyNames;var u=Object.prototype.hasOwnProperty;var S=(n,a)=>{for(var e in a)o(n,e,{get:a[e],enumerable:!0})},g=(n,a,e,r)=>{if(a&&
|
|
2
|
+
typeof a=="object"||typeof a=="function")for(let t of I(a))!u.call(n,t)&&t!==e&&
|
|
3
|
+
o(n,t,{get:()=>a[t],enumerable:!(r=b(a,t))||r.enumerable});return n};var f=n=>g(o({},"__esModule",{value:!0}),n);var D={};S(D,{Database:()=>y,Index:()=>c,InsensitiveMode:()=>m,LockMode:()=>x,Order:()=>l,
|
|
4
|
+
OrderMode:()=>T,PaginationMode:()=>d,ParametersMode:()=>p,StreamChangeType:()=>s,
|
|
5
|
+
TransactionMode:()=>i});module.exports=f(D);var s=(r=>(r.Insert="insert",r.Update="update",r.Delete="delete",r))(s||{});var p=(e=>(e.NameAndIndex="both",e.OnlyIndex="index",e))(p||{});var i=(e=>(e.Interactive="interactive",e.Static="static",e))(i||{});var m=(e=>(e.Unsupported="unsupported",e.Enabled="enabled",e))(m||{});var d=(e=>(e.Cursor="cursor",e.Offset="offset",e))(d||{});var l=(e=>(e.Asc="asc",e.Desc="desc",e))(l||{}),T=(e=>(e.IndexColumns="index",e.
|
|
6
|
+
AnyColumns="any",e))(T||{});var x=(e=>(e.Unsupported="unsupported",e.Supported="supported",e))(x||{});var y;(n=>{})(y||={});var c=(t=>(t.Primary="primary",t.Secondary="secondary",t.Unique="unique",t.TTL="\
|
|
7
|
+
ttl",t))(c||{});0&&(module.exports={Database,Index,InsensitiveMode,LockMode,Order,OrderMode,PaginationMode,
|
|
8
|
+
ParametersMode,StreamChangeType,TransactionMode});
|
|
9
9
|
//# sourceMappingURL=main.cjs.map
|
package/dist/main.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export
|
|
1
|
+
export { StreamAnyChange, StreamDeleteChange, StreamInsertChange, StreamUpdateChange, StreamChangeType } from './services/streams';
|
|
2
2
|
export { Client } from './services/client';
|
|
3
3
|
export { RelationMetadata } from './services/relations';
|
|
4
4
|
export { TableMetadata, Table } from './services/table';
|
|
@@ -9,6 +9,6 @@ export { PaginationMode, PaginationModeUtils } from './services/pagination';
|
|
|
9
9
|
export { Order, OrderMode, OrderModeUtils } from './services/order';
|
|
10
10
|
export { LockMode, LockModeUtils } from './services/lock';
|
|
11
11
|
export { EngineUtils } from './services/engine';
|
|
12
|
-
export { Database } from './services/
|
|
12
|
+
export { Database } from './services/contract';
|
|
13
13
|
export { Index } from './services/indexes';
|
|
14
14
|
export { Query } from './services/query';
|
package/dist/main.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
var
|
|
2
|
-
AnyColumns="any",e))(
|
|
3
|
-
ttl",t))(
|
|
4
|
-
|
|
1
|
+
var n=(a=>(a.Insert="insert",a.Update="update",a.Delete="delete",a))(n||{});var r=(e=>(e.NameAndIndex="both",e.OnlyIndex="index",e))(r||{});var o=(e=>(e.Interactive="interactive",e.Static="static",e))(o||{});var s=(e=>(e.Unsupported="unsupported",e.Enabled="enabled",e))(s||{});var p=(e=>(e.Cursor="cursor",e.Offset="offset",e))(p||{});var i=(e=>(e.Asc="asc",e.Desc="desc",e))(i||{}),m=(e=>(e.IndexColumns="index",e.
|
|
2
|
+
AnyColumns="any",e))(m||{});var d=(e=>(e.Unsupported="unsupported",e.Supported="supported",e))(d||{});var l;(x=>{})(l||={});var T=(t=>(t.Primary="primary",t.Secondary="secondary",t.Unique="unique",t.TTL="\
|
|
3
|
+
ttl",t))(T||{});export{l as Database,T as Index,s as InsensitiveMode,d as LockMode,i as Order,m as OrderMode,
|
|
4
|
+
p as PaginationMode,r as ParametersMode,n as StreamChangeType,o as TransactionMode};
|
|
5
5
|
//# sourceMappingURL=main.mjs.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ParametersModeUtils } from './parameters';
|
|
2
2
|
import type { TransactionModeUtils } from './transaction';
|
|
3
3
|
import type { TableClients } from './table';
|
|
4
|
-
import type { Database } from './
|
|
4
|
+
import type { Database } from './contract';
|
|
5
5
|
/**
|
|
6
6
|
* Database client.
|
|
7
7
|
*/
|
|
@@ -0,0 +1,25 @@
|
|
|
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;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { Service as CommonService } from '@ez4/common';
|
|
2
|
+
import type { TableStreamHandler, TableStreamIncoming, TableStreamListener, TableStreamRequest } from './common';
|
|
3
|
+
import type { DatabaseScalability } from './scalability';
|
|
4
|
+
import type { TableRelations } from './relations';
|
|
5
|
+
import type { DatabaseEngine } from './engine';
|
|
6
|
+
import type { TableIndexes } from './indexes';
|
|
7
|
+
import type { TableStream } from './streams';
|
|
8
|
+
import type { TableSchema } from './schemas';
|
|
9
|
+
import type { DatabaseTable } from './table';
|
|
10
|
+
import type { Client } from './client';
|
|
11
|
+
/**
|
|
12
|
+
* Provide all contracts for a self-managed database service.
|
|
13
|
+
*/
|
|
14
|
+
export declare namespace Database {
|
|
15
|
+
type Schema = TableSchema;
|
|
16
|
+
type Relations = TableRelations;
|
|
17
|
+
type Indexes = TableIndexes;
|
|
18
|
+
type Incoming<T extends Schema> = TableStreamIncoming<T>;
|
|
19
|
+
type Request = TableStreamRequest;
|
|
20
|
+
type Listener<T extends Schema> = TableStreamListener<T>;
|
|
21
|
+
type Handler<T extends Schema> = TableStreamHandler<T>;
|
|
22
|
+
type Stream<T extends Schema = Schema> = TableStream<T>;
|
|
23
|
+
type Table<T extends Schema = Schema> = DatabaseTable<T>;
|
|
24
|
+
type Scalability = DatabaseScalability;
|
|
25
|
+
type Engine = DatabaseEngine;
|
|
26
|
+
type ServiceEvent<T extends Schema = Schema> = CommonService.BeginEvent<Request> | CommonService.ReadyEvent<Incoming<T>> | CommonService.DoneEvent<Incoming<T>> | CommonService.ErrorEvent<Request | Incoming<T>> | CommonService.EndEvent<Request>;
|
|
27
|
+
/**
|
|
28
|
+
* Database Table definition.
|
|
29
|
+
*/
|
|
30
|
+
type UseTable<T extends DatabaseTable<any>> = T;
|
|
31
|
+
/**
|
|
32
|
+
* Database Engine definition.
|
|
33
|
+
*/
|
|
34
|
+
type UseEngine<T extends DatabaseEngine> = T;
|
|
35
|
+
/**
|
|
36
|
+
* Database Scalability definition.
|
|
37
|
+
*/
|
|
38
|
+
type UseScalability<T extends DatabaseScalability> = T;
|
|
39
|
+
/**
|
|
40
|
+
* Database service.
|
|
41
|
+
*/
|
|
42
|
+
abstract class Service implements CommonService.Provider {
|
|
43
|
+
/**
|
|
44
|
+
* Determines which database engine to use.
|
|
45
|
+
* Check the provider package to know all the possible values.
|
|
46
|
+
*/
|
|
47
|
+
abstract readonly engine: Engine;
|
|
48
|
+
/**
|
|
49
|
+
* Describe all available tables for the service.
|
|
50
|
+
*/
|
|
51
|
+
abstract readonly tables: Table<any>[];
|
|
52
|
+
/**
|
|
53
|
+
* Scalability configuration.
|
|
54
|
+
*/
|
|
55
|
+
readonly scalability: Scalability;
|
|
56
|
+
/**
|
|
57
|
+
* Service client.
|
|
58
|
+
*/
|
|
59
|
+
readonly client: Client<Service>;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -2,7 +2,7 @@ import type { ParametersMode } from './parameters';
|
|
|
2
2
|
import type { TransactionMode } from './transaction';
|
|
3
3
|
import type { InsensitiveMode } from './insensitive';
|
|
4
4
|
import type { PaginationMode } from './pagination';
|
|
5
|
-
import type { Database } from './
|
|
5
|
+
import type { Database } from './contract';
|
|
6
6
|
import type { OrderMode } from './order';
|
|
7
7
|
import type { LockMode } from './lock';
|
|
8
8
|
/**
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import type { ArrayRest, IsArrayEmpty } from '@ez4/utils';
|
|
2
|
-
import type {
|
|
2
|
+
import type { DatabaseTable, DatabaseTables } from './table';
|
|
3
|
+
import type { TableSchema } from './schemas';
|
|
4
|
+
import type { Database } from './contract';
|
|
5
|
+
/**
|
|
6
|
+
* Database table indexes.
|
|
7
|
+
*/
|
|
8
|
+
export type TableIndexes = {};
|
|
3
9
|
/**
|
|
4
10
|
* All supported index types.
|
|
5
11
|
*/
|
|
@@ -16,33 +22,33 @@ export type DecomposeIndexName<T> = T extends `${infer L}:${infer R}` ? L | Deco
|
|
|
16
22
|
/**
|
|
17
23
|
* Given an index object `T`, it produces an object containing only primary indexes.
|
|
18
24
|
*/
|
|
19
|
-
export type PrimaryIndexes<T extends
|
|
25
|
+
export type PrimaryIndexes<T extends TableIndexes> = {
|
|
20
26
|
[P in keyof T as Index.Primary extends T[P] ? P : never]: T[P];
|
|
21
27
|
};
|
|
22
28
|
/**
|
|
23
29
|
* Given an index object `T`, it produces an object containing only unique indexes.
|
|
24
30
|
*/
|
|
25
|
-
export type UniqueIndexes<T extends
|
|
31
|
+
export type UniqueIndexes<T extends TableIndexes> = {
|
|
26
32
|
[P in keyof T as Index.Unique extends T[P] ? P : never]: T[P];
|
|
27
33
|
};
|
|
28
34
|
/**
|
|
29
35
|
* Given an index object `T`, it produces an object containing only secondary indexes.
|
|
30
36
|
*/
|
|
31
|
-
export type SecondaryIndexes<T extends
|
|
37
|
+
export type SecondaryIndexes<T extends TableIndexes> = {
|
|
32
38
|
[P in keyof T as Index.Secondary | Index.TTL extends T[P] ? P : never]: T[P];
|
|
33
39
|
};
|
|
34
40
|
/**
|
|
35
41
|
* Given an index object `T`, it produces the primary decomposed index names.
|
|
36
42
|
*/
|
|
37
|
-
export type DecomposePrimaryIndexNames<T extends
|
|
43
|
+
export type DecomposePrimaryIndexNames<T extends TableIndexes> = DecomposeIndexName<keyof PrimaryIndexes<T>>;
|
|
38
44
|
/**
|
|
39
45
|
* Given an index object `T`, it produces the unique decomposed index names.
|
|
40
46
|
*/
|
|
41
|
-
export type DecomposeUniqueIndexNames<T extends
|
|
47
|
+
export type DecomposeUniqueIndexNames<T extends TableIndexes> = DecomposeIndexName<keyof UniqueIndexes<T>>;
|
|
42
48
|
/**
|
|
43
49
|
* Given an index object `T`, it produces the secondary decomposed index names.
|
|
44
50
|
*/
|
|
45
|
-
export type DecomposeSecondaryIndexNames<T extends
|
|
51
|
+
export type DecomposeSecondaryIndexNames<T extends TableIndexes> = DecomposeIndexName<keyof SecondaryIndexes<T>>;
|
|
46
52
|
/**
|
|
47
53
|
* Given a database service `T`, it produces an object with all tables containing indexes.
|
|
48
54
|
*/
|
|
@@ -51,14 +57,14 @@ export type IndexedTables<T extends Database.Service> = MergeIndexes<DatabaseTab
|
|
|
51
57
|
* Given a list of tables with indexes `T`, it produces another object containing all the
|
|
52
58
|
* table indexes.
|
|
53
59
|
*/
|
|
54
|
-
type MergeIndexes<T extends
|
|
60
|
+
type MergeIndexes<T extends DatabaseTable<TableSchema>[]> = IsArrayEmpty<T> extends false ? ExtractIndexes<T[0]> & MergeIndexes<ArrayRest<T>> : {};
|
|
55
61
|
/**
|
|
56
62
|
* Given a database table `T`, it produces an object containing all the table indexes.
|
|
57
63
|
*/
|
|
58
|
-
type
|
|
64
|
+
type ExtractIndexes<T> = T extends {
|
|
59
65
|
name: infer N;
|
|
60
66
|
indexes: infer I;
|
|
61
|
-
} ? N extends string ? I extends
|
|
67
|
+
} ? N extends string ? I extends TableIndexes ? {
|
|
62
68
|
[P in N]: I;
|
|
63
69
|
} : {} : {} : {};
|
|
64
70
|
export {};
|
package/dist/services/order.d.ts
CHANGED
package/dist/services/query.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ import type { PaginationModeUtils } from './pagination';
|
|
|
6
6
|
import type { OrderModeUtils } from './order';
|
|
7
7
|
import type { LockModeUtils } from './lock';
|
|
8
8
|
import type { TableMetadata } from './table';
|
|
9
|
-
import type { Database } from './
|
|
9
|
+
import type { Database } from './contract';
|
|
10
10
|
import type { AnyObject, PartialProperties, PartialObject, FlatObject, OptionalObject, StrictObject, IsNullable, IsUndefined, IsObjectEmpty, IsObject, IsArray, Prettify } from '@ez4/utils';
|
|
11
11
|
/**
|
|
12
12
|
* Query builder types.
|
|
@@ -146,10 +146,10 @@ export declare namespace Query {
|
|
|
146
146
|
lte: V;
|
|
147
147
|
};
|
|
148
148
|
type WhereIn<V> = {
|
|
149
|
-
isIn: IsArray<V> extends true ? V : IsObject<V> extends true ? V : V[];
|
|
149
|
+
isIn: IsArray<V> extends true ? V : IsObject<V> extends true ? V : Exclude<V, undefined>[];
|
|
150
150
|
};
|
|
151
151
|
type WhereBetween<V> = {
|
|
152
|
-
isBetween: [V, V];
|
|
152
|
+
isBetween: [Exclude<V, undefined>, Exclude<V, undefined>];
|
|
153
153
|
};
|
|
154
154
|
type WhereIsMissing = {
|
|
155
155
|
isMissing: boolean;
|
|
@@ -1,7 +1,13 @@
|
|
|
1
|
-
import type { AnyObject, ArrayRest, PropertyType,
|
|
2
|
-
import type { IndexedTables, PrimaryIndexes, UniqueIndexes } from './indexes';
|
|
3
|
-
import type {
|
|
4
|
-
import type { TableSchemas } from './schemas';
|
|
1
|
+
import type { AnyObject, ArrayRest, PropertyType, Exclusive, IsArrayEmpty, IsUndefined, MergeObject, Prettify } from '@ez4/utils';
|
|
2
|
+
import type { TableIndexes, IndexedTables, PrimaryIndexes, UniqueIndexes } from './indexes';
|
|
3
|
+
import type { DatabaseTable, DatabaseTables } from './table';
|
|
4
|
+
import type { TableSchema, TableSchemas } from './schemas';
|
|
5
|
+
import type { Database } from './contract';
|
|
6
|
+
/**
|
|
7
|
+
* Database table relations.
|
|
8
|
+
*/
|
|
9
|
+
export interface TableRelations {
|
|
10
|
+
}
|
|
5
11
|
/**
|
|
6
12
|
* Internal relation type.
|
|
7
13
|
*/
|
|
@@ -37,11 +43,11 @@ export type RelationTables<T extends Database.Service> = MergeRelations<Database
|
|
|
37
43
|
* Given a list of tables with relations `T`, it produces an object containing all the
|
|
38
44
|
* relation tables.
|
|
39
45
|
*/
|
|
40
|
-
type MergeRelations<T extends
|
|
46
|
+
type MergeRelations<T extends DatabaseTable<TableSchema>[], C extends DatabaseTable<TableSchema>[], S extends Record<string, TableSchema>, I extends Record<string, TableIndexes>> = IsArrayEmpty<C> extends false ? ExtractRelations<T, C[0], S, I> & MergeRelations<T, ArrayRest<C>, S, I> : {};
|
|
41
47
|
/**
|
|
42
48
|
* Given a database table `T`, it produces an object containing all its relations.
|
|
43
49
|
*/
|
|
44
|
-
type
|
|
50
|
+
type ExtractRelations<T extends DatabaseTable<TableSchema>[], C extends DatabaseTable<TableSchema>, S extends Record<string, TableSchema>, I extends Record<string, TableIndexes>> = C extends {
|
|
45
51
|
name: infer N;
|
|
46
52
|
} ? N extends string ? C extends {
|
|
47
53
|
relations: infer R;
|
|
@@ -67,53 +73,53 @@ type TableRelation<T extends Database.Table[], C extends Database.Table, S exten
|
|
|
67
73
|
/**
|
|
68
74
|
* Check whether the given column is a primary index.
|
|
69
75
|
*/
|
|
70
|
-
type IsPrimarySourceIndex<C, I extends Record<string,
|
|
76
|
+
type IsPrimarySourceIndex<C, I extends Record<string, TableIndexes>> = RelationSourceColumn<C> extends keyof PrimaryIndexes<PropertyType<RelationSourceTable<C>, I>> ? true : false;
|
|
71
77
|
/**
|
|
72
78
|
* Check whether the given column is a unique index.
|
|
73
79
|
*/
|
|
74
|
-
type IsUniqueSourceIndex<C, I extends Record<string,
|
|
80
|
+
type IsUniqueSourceIndex<C, I extends Record<string, TableIndexes>> = RelationSourceColumn<C> extends keyof UniqueIndexes<PropertyType<RelationSourceTable<C>, I>> ? true : false;
|
|
75
81
|
/**
|
|
76
82
|
* Check whether the given column is a primary target index.
|
|
77
83
|
*/
|
|
78
|
-
type IsPrimaryTargetIndex<V, I extends
|
|
84
|
+
type IsPrimaryTargetIndex<V, I extends TableIndexes> = RelationTargetColumn<V> extends keyof PrimaryIndexes<I> ? true : false;
|
|
79
85
|
/**
|
|
80
86
|
* Check whether the given column is a unique target index.
|
|
81
87
|
*/
|
|
82
|
-
export type IsUniqueTargetIndex<V, I extends
|
|
88
|
+
export type IsUniqueTargetIndex<V, I extends TableIndexes> = RelationTargetColumn<V> extends keyof UniqueIndexes<I> ? true : false;
|
|
83
89
|
/**
|
|
84
90
|
* Check whether the given column is a secondary target index.
|
|
85
91
|
*/
|
|
86
|
-
type IsSecondaryTargetIndex<V, I extends
|
|
92
|
+
type IsSecondaryTargetIndex<V, I extends TableIndexes> = RelationTargetColumn<V> extends keyof (PrimaryIndexes<I> & UniqueIndexes<I>) ? false : true;
|
|
87
93
|
/**
|
|
88
94
|
* Check whether a relation is optional or not.
|
|
89
95
|
*/
|
|
90
|
-
type IsOptionalRelation<C, V, T extends
|
|
96
|
+
type IsOptionalRelation<C, V, T extends TableSchema, I extends Record<string, TableIndexes>, E extends boolean> = IsPrimarySourceIndex<C, I> extends true ? IsUndefined<PropertyType<RelationTargetColumn<V>, T>> : IsUniqueSourceIndex<C, I> extends true ? true : E;
|
|
91
97
|
/**
|
|
92
98
|
* Produce an object containing all relation indexes.
|
|
93
99
|
*/
|
|
94
|
-
type RelationIndexes<N, I extends Record<string,
|
|
100
|
+
type RelationIndexes<N, I extends Record<string, TableIndexes>, R extends AnyObject> = keyof {
|
|
95
101
|
[P in keyof R as IsRelationIndex<N, R[P], P, I> extends true ? RelationTargetColumn<P> : never]: never;
|
|
96
102
|
};
|
|
97
103
|
/**
|
|
98
104
|
* Check whether the given source and target columns are used to index the relation.
|
|
99
105
|
*/
|
|
100
|
-
type IsRelationIndex<N, C, V, I extends Record<string,
|
|
106
|
+
type IsRelationIndex<N, C, V, I extends Record<string, TableIndexes>> = IsPrimarySourceIndex<C, I> extends false ? IsSecondaryTargetIndex<V, PropertyType<N, I>> extends false ? IsUniqueTargetIndex<V, PropertyType<N, I>> extends true ? IsUniqueSourceIndex<C, I> : false : true : true;
|
|
101
107
|
/**
|
|
102
108
|
* Produce an object containing relation schemas for filters.
|
|
103
109
|
*/
|
|
104
|
-
type FilterableRelationSchemas<S extends Record<string,
|
|
110
|
+
type FilterableRelationSchemas<S extends Record<string, TableSchema>, R extends AnyObject> = {
|
|
105
111
|
[P in keyof R as RelationTargetAlias<P>]: Omit<PropertyType<RelationSourceTable<R[P]>, S>, RelationSourceColumn<R[P]>>;
|
|
106
112
|
};
|
|
107
113
|
/**
|
|
108
114
|
* Produce an object containing relation schemas for updates.
|
|
109
115
|
*/
|
|
110
|
-
type UpdateRelationSchemas<N, S extends Record<string,
|
|
116
|
+
type UpdateRelationSchemas<N, S extends Record<string, TableSchema>, I extends Record<string, TableIndexes>, R extends AnyObject> = {
|
|
111
117
|
[P in keyof R as RelationTargetAlias<P>]?: ChangeRelationSchema<N, R[P], P, S, I>;
|
|
112
118
|
};
|
|
113
119
|
/**
|
|
114
120
|
* Produce an object containing relation schemas for inserts.
|
|
115
121
|
*/
|
|
116
|
-
type InsertRelationSchemas<N, T extends
|
|
122
|
+
type InsertRelationSchemas<N, T extends TableSchema, S extends Record<string, TableSchema>, I extends Record<string, TableIndexes>, R extends AnyObject> = {
|
|
117
123
|
[P in keyof R as IsOptionalRelation<R[P], P, T, I, true> extends true ? RelationTargetAlias<P> : never]?: ChangeRelationSchema<N, R[P], P, S, I>;
|
|
118
124
|
} & {
|
|
119
125
|
[P in keyof R as IsOptionalRelation<R[P], P, T, I, true> extends false ? RelationTargetAlias<P> : never]: ChangeRelationSchema<N, R[P], P, S, I>;
|
|
@@ -121,13 +127,13 @@ type InsertRelationSchemas<N, T extends Database.Schema, S extends Record<string
|
|
|
121
127
|
/**
|
|
122
128
|
* Produce an object containing relation schemas for selects.
|
|
123
129
|
*/
|
|
124
|
-
type SelectRelationSchemas<S extends Record<string,
|
|
130
|
+
type SelectRelationSchemas<S extends Record<string, TableSchema>, I extends Record<string, TableIndexes>, R extends AnyObject> = {
|
|
125
131
|
[P in keyof R as RelationTargetAlias<P>]?: SelectRelationSchema<R[P], S, I>;
|
|
126
132
|
};
|
|
127
133
|
/**
|
|
128
134
|
* Produce an object containing relation schemas for records.
|
|
129
135
|
*/
|
|
130
|
-
type RecordsRelationSchemas<T extends
|
|
136
|
+
type RecordsRelationSchemas<T extends TableSchema, S extends Record<string, TableSchema>, I extends Record<string, TableIndexes>, R extends AnyObject> = {
|
|
131
137
|
[P in keyof R as IsOptionalRelation<R[P], P, T, I, false> extends true ? RelationTargetAlias<P> : never]?: RecordRelationSchema<R[P], S, I>;
|
|
132
138
|
} & {
|
|
133
139
|
[P in keyof R as IsOptionalRelation<R[P], P, T, I, false> extends false ? RelationTargetAlias<P> : never]: RecordRelationSchema<R[P], S, I>;
|
|
@@ -135,7 +141,7 @@ type RecordsRelationSchemas<T extends Database.Schema, S extends Record<string,
|
|
|
135
141
|
/**
|
|
136
142
|
* Produce an object containing all nested relation schemas for select operations.
|
|
137
143
|
*/
|
|
138
|
-
type NestedSelectRelationSchemas<T extends
|
|
144
|
+
type NestedSelectRelationSchemas<T extends DatabaseTable<TableSchema>[], S extends Record<string, TableSchema>, I extends Record<string, TableIndexes>, R extends AnyObject> = {
|
|
139
145
|
[P in keyof R as RelationTargetAlias<P>]?: RelationSourceTable<R[P]> extends keyof MergeRelations<T, T, S, I> ? MergeRelations<T, T, S, I>[RelationSourceTable<R[P]>] extends {
|
|
140
146
|
selects: infer N;
|
|
141
147
|
} ? N : never : never;
|
|
@@ -143,7 +149,7 @@ type NestedSelectRelationSchemas<T extends Database.Table[], S extends Record<st
|
|
|
143
149
|
/**
|
|
144
150
|
* Produce an object containing all nested relation schemas for records.
|
|
145
151
|
*/
|
|
146
|
-
type NestedRecordsRelationSchemas<T extends
|
|
152
|
+
type NestedRecordsRelationSchemas<T extends DatabaseTable<TableSchema>[], S extends Record<string, TableSchema>, I extends Record<string, TableIndexes>, R extends AnyObject> = {
|
|
147
153
|
[P in keyof R as RelationTargetAlias<P>]?: RelationSourceTable<R[P]> extends keyof MergeRelations<T, T, S, I> ? MergeRelations<T, T, S, I>[RelationSourceTable<R[P]>] extends {
|
|
148
154
|
records: infer N;
|
|
149
155
|
} ? N : never : never;
|
|
@@ -151,29 +157,29 @@ type NestedRecordsRelationSchemas<T extends Database.Table[], S extends Record<s
|
|
|
151
157
|
/**
|
|
152
158
|
* Produce a type corresponding to the source column schema.
|
|
153
159
|
*/
|
|
154
|
-
type SourceColumnSchema<C, S extends Record<string,
|
|
160
|
+
type SourceColumnSchema<C, S extends Record<string, TableSchema>> = PropertyType<RelationSourceTable<C>, S>;
|
|
155
161
|
/**
|
|
156
162
|
* Produce a change relation schema according to its indexation.
|
|
157
163
|
*/
|
|
158
|
-
type ChangeRelationSchema<N, C, V, S extends Record<string,
|
|
164
|
+
type ChangeRelationSchema<N, C, V, S extends Record<string, TableSchema>, I extends Record<string, TableIndexes>> = IsPrimarySourceIndex<C, I> extends true ? Exclusive<SourceColumnSchema<C, S>, PrimaryKeyConnectionSchema<C, S, I>> : IsUniqueSourceIndex<C, I> extends true ? IsPrimaryTargetIndex<V, PropertyType<N, I>> extends true ? Exclusive<Omit<SourceColumnSchema<C, S>, RelationSourceColumn<C>>, UniqueKeyConnectionSchema<C, S, I>> : Exclusive<SourceColumnSchema<C, S>, UniqueKeyConnectionSchema<C, S, I>> : Exclusive<Omit<SourceColumnSchema<C, S>, RelationSourceColumn<C>>, PrimaryKeyConnectionSchema<C, S, I>>[];
|
|
159
165
|
/**
|
|
160
166
|
* Produce a select relation schema according to its indexation.
|
|
161
167
|
*/
|
|
162
|
-
type SelectRelationSchema<C, S extends Record<string,
|
|
168
|
+
type SelectRelationSchema<C, S extends Record<string, TableSchema>, I extends Record<string, TableIndexes>> = IsPrimarySourceIndex<C, I> extends true ? SourceColumnSchema<C, S> : IsUniqueSourceIndex<C, I> extends true ? SourceColumnSchema<C, S> : SourceColumnSchema<C, S>;
|
|
163
169
|
/**
|
|
164
170
|
* Produce a record relation schema according to its indexation.
|
|
165
171
|
*/
|
|
166
|
-
type RecordRelationSchema<C, S extends Record<string,
|
|
172
|
+
type RecordRelationSchema<C, S extends Record<string, TableSchema>, I extends Record<string, TableIndexes>> = IsPrimarySourceIndex<C, I> extends true ? SourceColumnSchema<C, S> : IsUniqueSourceIndex<C, I> extends true ? SourceColumnSchema<C, S> : SourceColumnSchema<C, S>[];
|
|
167
173
|
/**
|
|
168
174
|
* Produce a relation schema for connections using primary keys.
|
|
169
175
|
*/
|
|
170
|
-
type PrimaryKeyConnectionSchema<C, S extends Record<string,
|
|
176
|
+
type PrimaryKeyConnectionSchema<C, S extends Record<string, TableSchema>, I extends Record<string, TableIndexes>> = Prettify<{
|
|
171
177
|
[P in keyof PrimaryIndexes<PropertyType<RelationSourceTable<C>, I>>]: PropertyType<P, PropertyType<RelationSourceTable<C>, S>> | undefined | null;
|
|
172
178
|
}>;
|
|
173
179
|
/**
|
|
174
180
|
* Produce a relation schema for connections using unique keys.
|
|
175
181
|
*/
|
|
176
|
-
type UniqueKeyConnectionSchema<C, S extends Record<string,
|
|
182
|
+
type UniqueKeyConnectionSchema<C, S extends Record<string, TableSchema>, I extends Record<string, TableIndexes>> = Prettify<{
|
|
177
183
|
[P in keyof UniqueIndexes<PropertyType<RelationSourceTable<C>, I>> as P extends RelationSourceColumn<C> ? P : never]: PropertyType<P, PropertyType<RelationSourceTable<C>, S>> | undefined | null;
|
|
178
184
|
}>;
|
|
179
185
|
export {};
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import type { ArrayRest, IsArrayEmpty } from '@ez4/utils';
|
|
2
|
-
import type {
|
|
2
|
+
import type { DatabaseTable, DatabaseTables } from './table';
|
|
3
|
+
import type { Database } from './contract';
|
|
4
|
+
/**
|
|
5
|
+
* Table schema.
|
|
6
|
+
*/
|
|
7
|
+
export interface TableSchema {
|
|
8
|
+
}
|
|
3
9
|
/**
|
|
4
10
|
* Given a database service `T`, it produces an object containing all tables with schemas.
|
|
5
11
|
*/
|
|
@@ -7,14 +13,14 @@ export type TableSchemas<T extends Database.Service> = MergeTables<DatabaseTable
|
|
|
7
13
|
/**
|
|
8
14
|
* Given a list of tables with schema `T`, it produces an object containing all schemas.
|
|
9
15
|
*/
|
|
10
|
-
type MergeTables<T extends
|
|
16
|
+
type MergeTables<T extends DatabaseTable<TableSchema>[]> = IsArrayEmpty<T> extends false ? ExtractSchema<T[0]> & MergeTables<ArrayRest<T>> : {};
|
|
11
17
|
/**
|
|
12
18
|
* Given a database table `T`, it produces an object containing the table schema.
|
|
13
19
|
*/
|
|
14
|
-
type
|
|
20
|
+
type ExtractSchema<T> = T extends {
|
|
15
21
|
name: infer N;
|
|
16
22
|
schema: infer S;
|
|
17
|
-
} ? N extends string ? S extends
|
|
23
|
+
} ? N extends string ? S extends TableSchema ? {
|
|
18
24
|
[P in N]: S;
|
|
19
25
|
} : {} : {} : {};
|
|
20
26
|
export {};
|
|
@@ -1,15 +1,47 @@
|
|
|
1
|
+
import type { LinkedVariables } from '@ez4/project/library';
|
|
2
|
+
import type { TableStreamHandler, TableStreamListener } from './common';
|
|
3
|
+
import type { TableSchema } from './schemas';
|
|
1
4
|
/**
|
|
2
|
-
*
|
|
5
|
+
* Database table stream.
|
|
3
6
|
*/
|
|
4
|
-
export
|
|
7
|
+
export interface TableStream<T extends TableSchema> {
|
|
8
|
+
/**
|
|
9
|
+
* Stream listener.
|
|
10
|
+
*/
|
|
11
|
+
readonly listener?: TableStreamListener<T>;
|
|
12
|
+
/**
|
|
13
|
+
* Stream handler.
|
|
14
|
+
*/
|
|
15
|
+
readonly handler: TableStreamHandler<T>;
|
|
16
|
+
/**
|
|
17
|
+
* Variables associated to the handler.
|
|
18
|
+
*/
|
|
19
|
+
readonly variables?: LinkedVariables;
|
|
20
|
+
/**
|
|
21
|
+
* Log retention (in days) for the handler.
|
|
22
|
+
*/
|
|
23
|
+
readonly logRetention?: number;
|
|
24
|
+
/**
|
|
25
|
+
* Max execution time (in seconds) for the handler.
|
|
26
|
+
*/
|
|
27
|
+
readonly timeout?: number;
|
|
28
|
+
/**
|
|
29
|
+
* Amount of memory available for the handler.
|
|
30
|
+
*/
|
|
31
|
+
readonly memory?: number;
|
|
32
|
+
}
|
|
5
33
|
/**
|
|
6
34
|
* Stream change types.
|
|
7
35
|
*/
|
|
8
|
-
export declare const enum
|
|
36
|
+
export declare const enum StreamChangeType {
|
|
9
37
|
Insert = "insert",
|
|
10
38
|
Update = "update",
|
|
11
39
|
Delete = "delete"
|
|
12
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* Stream change for `insert`, `update` or `delete` operations.
|
|
43
|
+
*/
|
|
44
|
+
export type StreamAnyChange<T> = StreamInsertChange<T> | StreamUpdateChange<T> | StreamDeleteChange<T>;
|
|
13
45
|
/**
|
|
14
46
|
* Stream change for an `insert` operation.
|
|
15
47
|
*/
|
|
@@ -17,11 +49,11 @@ export type StreamInsertChange<T> = {
|
|
|
17
49
|
/**
|
|
18
50
|
* Change type.
|
|
19
51
|
*/
|
|
20
|
-
type:
|
|
52
|
+
readonly type: StreamChangeType.Insert;
|
|
21
53
|
/**
|
|
22
54
|
* Inserted record.
|
|
23
55
|
*/
|
|
24
|
-
record: T;
|
|
56
|
+
readonly record: T;
|
|
25
57
|
};
|
|
26
58
|
/**
|
|
27
59
|
* Stream change for an `update` operation.
|
|
@@ -30,15 +62,15 @@ export type StreamUpdateChange<T> = {
|
|
|
30
62
|
/**
|
|
31
63
|
* Change type.
|
|
32
64
|
*/
|
|
33
|
-
type:
|
|
65
|
+
readonly type: StreamChangeType.Update;
|
|
34
66
|
/**
|
|
35
67
|
* Previous record.
|
|
36
68
|
*/
|
|
37
|
-
oldRecord: T;
|
|
69
|
+
readonly oldRecord: T;
|
|
38
70
|
/**
|
|
39
71
|
* Current record.
|
|
40
72
|
*/
|
|
41
|
-
newRecord: T;
|
|
73
|
+
readonly newRecord: T;
|
|
42
74
|
};
|
|
43
75
|
/**
|
|
44
76
|
* Stream change for an `delete` operation.
|
|
@@ -47,9 +79,9 @@ export type StreamDeleteChange<T> = {
|
|
|
47
79
|
/**
|
|
48
80
|
* Change type.
|
|
49
81
|
*/
|
|
50
|
-
type:
|
|
82
|
+
readonly type: StreamChangeType.Delete;
|
|
51
83
|
/**
|
|
52
84
|
* Deleted record.
|
|
53
85
|
*/
|
|
54
|
-
record: T;
|
|
86
|
+
readonly record: T;
|
|
55
87
|
};
|
package/dist/services/table.d.ts
CHANGED
|
@@ -1,10 +1,42 @@
|
|
|
1
1
|
import type { AnyObject, PropertyExists } from '@ez4/utils';
|
|
2
|
-
import type { RelationMetadata, RelationTables } from './relations';
|
|
3
|
-
import type { IndexedTables } from './indexes';
|
|
4
|
-
import type { TableSchemas } from './schemas';
|
|
5
|
-
import type { Database } from './database';
|
|
2
|
+
import type { TableRelations, RelationMetadata, RelationTables } from './relations';
|
|
3
|
+
import type { TableIndexes, IndexedTables } from './indexes';
|
|
4
|
+
import type { TableSchema, TableSchemas } from './schemas';
|
|
6
5
|
import type { DatabaseEngine } from './engine';
|
|
6
|
+
import type { TableStream } from './streams';
|
|
7
|
+
import type { Database } from './contract';
|
|
7
8
|
import type { Query } from './query';
|
|
9
|
+
/**
|
|
10
|
+
* Database table.
|
|
11
|
+
*/
|
|
12
|
+
export interface DatabaseTable<T extends TableSchema> {
|
|
13
|
+
/**
|
|
14
|
+
* Table name.
|
|
15
|
+
*/
|
|
16
|
+
readonly name: string;
|
|
17
|
+
/**
|
|
18
|
+
* Table schema.
|
|
19
|
+
*/
|
|
20
|
+
readonly schema: T;
|
|
21
|
+
/**
|
|
22
|
+
* Table relations.
|
|
23
|
+
*/
|
|
24
|
+
readonly relations?: TableRelations;
|
|
25
|
+
/**
|
|
26
|
+
* Table indexes.
|
|
27
|
+
*/
|
|
28
|
+
readonly indexes: TableIndexes;
|
|
29
|
+
/**
|
|
30
|
+
* Table stream configuration.
|
|
31
|
+
*/
|
|
32
|
+
readonly stream?: TableStream<T>;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Given a database service `T`, it returns all its table.
|
|
36
|
+
*/
|
|
37
|
+
export type DatabaseTables<T> = T extends {
|
|
38
|
+
tables: infer U;
|
|
39
|
+
} ? U : [];
|
|
8
40
|
/**
|
|
9
41
|
* Given an indexed table `T` and a property `P`, it returns all the indexes corresponding
|
|
10
42
|
* to the given property.
|
|
@@ -3,7 +3,7 @@ import type { RelationTables } from './relations';
|
|
|
3
3
|
import type { IndexedTables } from './indexes';
|
|
4
4
|
import type { EngineUtils } from './engine';
|
|
5
5
|
import type { TableSchemas } from './schemas';
|
|
6
|
-
import type { Database } from './
|
|
6
|
+
import type { Database } from './contract';
|
|
7
7
|
import type { Client } from './client';
|
|
8
8
|
import type { Query } from './query';
|
|
9
9
|
/**
|
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.
|
|
4
|
+
"version": "0.35.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.
|
|
50
|
-
"@ez4/project": "^0.
|
|
51
|
-
"@ez4/reflection": "^0.
|
|
52
|
-
"@ez4/schema": "^0.
|
|
53
|
-
"@ez4/utils": "^0.
|
|
49
|
+
"@ez4/common": "^0.35.0",
|
|
50
|
+
"@ez4/project": "^0.35.0",
|
|
51
|
+
"@ez4/reflection": "^0.35.0",
|
|
52
|
+
"@ez4/schema": "^0.35.0",
|
|
53
|
+
"@ez4/utils": "^0.35.0"
|
|
54
54
|
}
|
|
55
55
|
}
|