@ez4/database 0.19.0 → 0.21.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/errors/engine.d.ts +4 -0
- package/dist/errors/scalability.d.ts +4 -0
- package/dist/library.cjs +120 -107
- package/dist/library.d.ts +2 -0
- package/dist/library.mjs +118 -107
- package/dist/main.cjs +4 -4
- package/dist/metadata/scalability.d.ts +3 -0
- package/dist/services/database.d.ts +12 -1
- package/dist/services/engine.d.ts +4 -5
- package/dist/services/insensitive.d.ts +3 -4
- package/dist/services/order.d.ts +3 -5
- package/dist/services/pagination.d.ts +6 -7
- package/dist/services/query.d.ts +40 -38
- package/dist/services/relations.d.ts +6 -6
- package/dist/triggers/service.d.ts +1 -1
- package/dist/types/scalability.d.ts +4 -0
- package/dist/types/service.d.ts +2 -0
- package/dist/types/stream.d.ts +1 -1
- package/package.json +6 -6
package/dist/library.cjs
CHANGED
|
@@ -1,117 +1,130 @@
|
|
|
1
|
-
"use strict";var
|
|
2
|
-
typeof r=="object"||typeof r=="function")for(let a of
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
"use strict";var oe=Object.defineProperty;var We=Object.getOwnPropertyDescriptor;var Xe=Object.getOwnPropertyNames;var Ye=Object.prototype.hasOwnProperty;var Ze=(e,r)=>{for(var t in r)oe(e,t,{get:r[t],enumerable:!0})},Le=(e,r,t,n)=>{if(r&&
|
|
2
|
+
typeof r=="object"||typeof r=="function")for(let a of Xe(r))!Ye.call(e,a)&&a!==t&&
|
|
3
|
+
oe(e,a,{get:()=>r[a],enumerable:!(n=We(r,a))||n.enumerable});return e};var et=e=>Le(oe({},"__esModule",{value:!0}),e);var ut={};Ze(ut,{IncompleteEngineError:()=>U,IncompleteHandlerError:()=>J,IncompleteScalabilityError:()=>z,
|
|
4
|
+
IncompleteServiceError:()=>O,IncompleteStreamError:()=>Q,IncompleteTableError:()=>N,
|
|
5
|
+
IncorrectIndexesTypeError:()=>F,IncorrectRelationsTypeError:()=>R,IncorrectSchemaTypeError:()=>G,
|
|
6
|
+
IncorrectStreamTypeError:()=>_,InvalidIndexReferenceError:()=>V,InvalidIndexTypeError:()=>q,
|
|
7
|
+
InvalidIndexesTypeError:()=>H,InvalidRelationAliasError:()=>C,InvalidRelationColumnError:()=>M,
|
|
8
|
+
InvalidRelationTableError:()=>w,InvalidRelationTargetError:()=>A,InvalidRelationsTypeError:()=>k,
|
|
9
|
+
InvalidSchemaTypeError:()=>$,InvalidStreamTypeError:()=>B,ServiceType:()=>K,getDatabaseServices:()=>pe,
|
|
10
|
+
getDatabaseTable:()=>ie,getTableSchema:()=>se,isDatabaseService:()=>tt,registerTriggers:()=>dt});
|
|
11
|
+
module.exports=et(ut);var Be=require("@ez4/common/library"),_e=require("@ez4/schema/library"),Je=require("@ez4/project/library");var d=require("@ez4/common/library"),$e=require("@ez4/reflection");var K="@ez4/database",tt=e=>e.type===K;var me=require("@ez4/common/library"),O=class extends me.IncompleteTypeError{constructor(r,t){
|
|
12
|
+
super("Incomplete database service",r,t)}};var x=require("@ez4/common/library"),k=class extends x.InvalidTypeError{constructor(r){
|
|
13
|
+
super("Invalid table relations type",void 0,"Database.Relations",r)}},R=class extends x.IncorrectTypeError{constructor(t,n){
|
|
12
14
|
super("Incorrect table relations type",t,"Database.Relations",n);this.schemaType=
|
|
13
|
-
t}},
|
|
14
|
-
the pattern 'column@alias'.`,n);this.relationSource=t}},
|
|
15
|
-
super(`Relation table ${t} don't exists.`,n);this.relationTable=t}},
|
|
16
|
-
super(`Relation column ${t} don't exists.`,n);this.relationColumn=t}},
|
|
15
|
+
t}},A=class extends x.TypeError{constructor(t,n){super(`Target ${t} must follow \
|
|
16
|
+
the pattern 'column@alias'.`,n);this.relationSource=t}},w=class extends x.TypeError{constructor(t,n){
|
|
17
|
+
super(`Relation table ${t} don't exists.`,n);this.relationTable=t}},M=class extends x.TypeError{constructor(t,n){
|
|
18
|
+
super(`Relation column ${t} don't exists.`,n);this.relationColumn=t}},C=class extends x.TypeError{constructor(t,n){
|
|
17
19
|
super(`Relation alias ${t} can't override table columns.`,n);this.relationAlias=
|
|
18
|
-
t}};var
|
|
19
|
-
super("Incomplete database
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
e,"Database.
|
|
24
|
-
e,"Database.
|
|
25
|
-
e,
|
|
26
|
-
e,t)
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
name
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
(
|
|
33
|
-
(
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
(0,
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
file))
|
|
41
|
-
|
|
20
|
+
t}};var b=require("@ez4/common/library"),I=require("@ez4/reflection"),Z=require("@ez4/utils");var ce=require("@ez4/common/library"),z=class extends ce.IncompleteTypeError{constructor(r,t){
|
|
21
|
+
super("Incomplete database scalability",r,t)}};var u=require("@ez4/common/library"),W=require("@ez4/reflection"),X=e=>(0,u.isClassDeclaration)(
|
|
22
|
+
e)&&(0,u.hasHeritageType)(e,"Database.Service"),Y=e=>(0,u.isModelDeclaration)(e)&&
|
|
23
|
+
(0,u.hasHeritageType)(e,"Database.Engine"),de=e=>(0,u.isModelDeclaration)(e)&&(0,u.hasHeritageType)(
|
|
24
|
+
e,"Database.Table"),ue=e=>(0,W.isTypeCallback)(e)||(0,W.isTypeFunction)(e),be=e=>(0,u.hasHeritageType)(
|
|
25
|
+
e,"Database.Relations"),Te=e=>(0,u.hasHeritageType)(e,"Database.Indexes"),fe=e=>(0,u.hasHeritageType)(
|
|
26
|
+
e,"Database.Schema"),ye=e=>(0,u.hasHeritageType)(e,"Database.Stream");var Me=(e,r,t,n)=>{if(!(0,I.isTypeReference)(e))return xe(e,r,n);let a=(0,b.getReferenceType)(
|
|
27
|
+
e,t);return a?xe(a,r,n):null},rt=e=>(0,Z.isAnyNumber)(e.minCapacity)&&(0,Z.isAnyNumber)(
|
|
28
|
+
e.maxCapacity),xe=(e,r,t)=>Y(e)?ge(e,r,(0,b.getModelMembers)(e),t):(0,I.isTypeObject)(
|
|
29
|
+
e)?ge(e,r,(0,b.getObjectMembers)(e),t):null,ge=(e,r,t,n)=>{let a={},o=new Set(["\
|
|
30
|
+
minCapacity","maxCapacity"]);for(let s of t)if(!(!(0,I.isModelProperty)(s)||s.inherited))
|
|
31
|
+
switch(s.name){default:n.push(new b.InvalidServicePropertyError(r.name,s.name,e.
|
|
32
|
+
file));break;case"minCapacity":case"maxCapacity":let i=(0,b.getPropertyNumber)(s);
|
|
33
|
+
(0,Z.isAnyNumber)(i)&&(a[s.name]=i,o.delete(s.name));break}return rt(a)?a:(n.push(
|
|
34
|
+
new z([...o],e.file)),null)};var S=require("@ez4/reflection"),m=require("@ez4/common/library");var Ie=require("@ez4/common/library"),U=class extends Ie.IncompleteTypeError{constructor(r,t){
|
|
35
|
+
super("Incomplete database engine",r,t)}};var he=(e,r,t,n)=>{if(!(0,S.isTypeReference)(e))return Se(e,r,n);let a=(0,m.getReferenceType)(
|
|
36
|
+
e,t);return a?Se(a,r,n):null},nt=e=>!!e.name&&!!e.parametersMode&&!!e.transactionMode&&
|
|
37
|
+
!!e.insensitiveMode&&!!e.paginationMode&&!!e.orderMode,Se=(e,r,t)=>Y(e)?De(e,r,(0,m.getModelMembers)(
|
|
38
|
+
e),t):(0,S.isTypeObject)(e)?De(e,r,(0,m.getObjectMembers)(e),t):null,De=(e,r,t,n)=>{
|
|
39
|
+
let a={},o=new Set(["name","parametersMode","transactionMode","insensitiveMode",
|
|
40
|
+
"paginationMode","orderMode"]);for(let s of t)if(!(!(0,S.isModelProperty)(s)||s.
|
|
41
|
+
inherited))switch(s.name){default:n.push(new m.InvalidServicePropertyError(r.name,
|
|
42
|
+
s.name,e.file));break;case"name":(a.name=(0,m.getPropertyString)(s))&&o.delete(s.
|
|
43
|
+
name);break;case"parametersMode":(a.parametersMode=(0,m.getPropertyStringIn)(s,[
|
|
44
|
+
"index","both"]))&&o.delete(s.name);break;case"transactionMode":(a.transactionMode=
|
|
45
|
+
(0,m.getPropertyStringIn)(s,["static","interactive"]))&&o.delete(s.name);break;case"\
|
|
46
|
+
insensitiveMode":(a.insensitiveMode=(0,m.getPropertyStringIn)(s,["unsupported","\
|
|
47
|
+
enabled"]))&&o.delete(s.name);break;case"paginationMode":(a.paginationMode=(0,m.getPropertyStringIn)(
|
|
48
|
+
s,["cursor","offset"]))&&o.delete(s.name);break;case"orderMode":(a.orderMode=(0,m.getPropertyStringIn)(
|
|
49
|
+
s,["any","index"]))&&o.delete(s.name);break}return nt(a)?a:(n.push(new U([...o],
|
|
50
|
+
e.file)),null)};var y=require("@ez4/common/library"),j=require("@ez4/reflection");var ve=require("@ez4/common/library"),N=class extends ve.IncompleteTypeError{constructor(r,t){
|
|
51
|
+
super("Incomplete database table",r,t)}};var g=require("@ez4/common/library"),H=class extends g.InvalidTypeError{constructor(r){
|
|
52
|
+
super("Invalid table indexes type",void 0,"Database.Indexes",r)}},F=class extends g.IncorrectTypeError{constructor(t,n){
|
|
42
53
|
super("Incorrect table indexes type",t,"Database.Indexes",n);this.schemaType=t}},
|
|
43
|
-
|
|
44
|
-
t follow one of the Index options.`,n);this.indexName=t}},
|
|
45
|
-
super(`Invalid index reference, ${t} must be valid column.`,n);this.indexName=t}};var
|
|
46
|
-
e,t);return a?
|
|
47
|
-
e),t):(0,
|
|
48
|
-
new
|
|
49
|
-
if(!(0,
|
|
50
|
-
a),s=a.name;if(!o)return t.push(new
|
|
51
|
-
P]=o.split(":",2);n.push({sourceTable:
|
|
52
|
-
return n};var
|
|
53
|
-
e,t);return a?
|
|
54
|
-
e),t):(0,
|
|
55
|
-
new
|
|
56
|
-
if(!(0,h.isModelProperty)(a)||a.inherited)continue;let o=a.name,s=(0,
|
|
54
|
+
q=class extends g.TypeError{constructor(t,n){super(`Invalid index type, ${t} mus\
|
|
55
|
+
t follow one of the Index options.`,n);this.indexName=t}},V=class extends g.TypeError{constructor(t,n){
|
|
56
|
+
super(`Invalid index reference, ${t} must be valid column.`,n);this.indexName=t}};var T=require("@ez4/common/library"),D=require("@ez4/reflection");var Pe=(e,r,t,n)=>{if(!(0,D.isTypeReference)(e))return Ee(e,r,n);let a=(0,T.getReferenceType)(
|
|
57
|
+
e,t);return a?Ee(a,r,n):null},Ee=(e,r,t)=>(0,D.isTypeObject)(e)?je(e,(0,T.getObjectMembers)(
|
|
58
|
+
e),t):(0,T.isModelDeclaration)(e)?be(e)?je(e,(0,T.getModelMembers)(e),t):(t.push(
|
|
59
|
+
new R(e.name,e.file)),null):(t.push(new k(r.file)),null),je=(e,r,t)=>{let n=[];for(let a of r){
|
|
60
|
+
if(!(0,D.isModelProperty)(a)||a.inherited)continue;let o=(0,T.getPropertyString)(
|
|
61
|
+
a),s=a.name;if(!o)return t.push(new A(s,e.file)),null;let[i,p]=s.split("@",2),[l,
|
|
62
|
+
P]=o.split(":",2);n.push({sourceTable:l,sourceColumn:P,targetColumn:i,targetAlias:p})}
|
|
63
|
+
return n};var f=require("@ez4/common/library"),h=require("@ez4/reflection");var Re=(e,r,t,n)=>{if(!(0,h.isTypeReference)(e))return Oe(e,r,n);let a=(0,f.getReferenceType)(
|
|
64
|
+
e,t);return a?Oe(a,r,n):null},Oe=(e,r,t)=>(0,h.isTypeObject)(e)?ke(e,(0,f.getObjectMembers)(
|
|
65
|
+
e),t):(0,f.isModelDeclaration)(e)?Te(e)?ke(e,(0,f.getModelMembers)(e),t):(t.push(
|
|
66
|
+
new F(e.name,e.file)),null):(t.push(new H(r.file)),null),ke=(e,r,t)=>{let n=[];for(let a of r){
|
|
67
|
+
if(!(0,h.isModelProperty)(a)||a.inherited)continue;let o=a.name,s=(0,f.getPropertyString)(
|
|
57
68
|
a);switch(s){case"primary":case"secondary":case"unique":case"ttl":n.push({name:o,
|
|
58
|
-
columns:o.split(":"),type:s});break;default:return t.push(new
|
|
59
|
-
return n};var
|
|
60
|
-
super("Invalid table schema type",void 0,"Database.Schema",r)}},
|
|
61
|
-
super("Incorrect table schema type",t,"Database.Schema",n);this.schemaType=t}};var
|
|
62
|
-
e,t);return a?
|
|
63
|
-
e)?
|
|
64
|
-
|
|
65
|
-
null};var c=require("@ez4/common/library"),
|
|
66
|
-
super("Incomplete table stream",r,t)}},
|
|
67
|
-
super("Invalid table stream type",void 0,"Database.Stream",r)}},
|
|
68
|
-
super("Incorrect table stream type",t,"Database.Stream",n);this.streamType=t}};var
|
|
69
|
-
super("Incomplete stream handler",r,t)}};var
|
|
69
|
+
columns:o.split(":"),type:s});break;default:return t.push(new q(o,e.file)),null}}
|
|
70
|
+
return n};var ee=require("@ez4/common/library"),te=require("@ez4/schema/library"),re=require("@ez4/reflection");var L=require("@ez4/common/library"),$=class extends L.InvalidTypeError{constructor(r){
|
|
71
|
+
super("Invalid table schema type",void 0,"Database.Schema",r)}},G=class extends L.IncorrectTypeError{constructor(t,n){
|
|
72
|
+
super("Incorrect table schema type",t,"Database.Schema",n);this.schemaType=t}};var se=(e,r,t,n)=>{if(!(0,re.isTypeReference)(e))return Ae(e,r,t,n);let a=(0,ee.getReferenceType)(
|
|
73
|
+
e,t);return a?Ae(a,r,t,n):null},Ae=(e,r,t,n)=>(0,re.isTypeObject)(e)?we(e,t):(0,ee.isModelDeclaration)(
|
|
74
|
+
e)?fe(e)?we(e,t):(n.push(new G(e.name,e.file)),null):(n.push(new $(r.file)),null),
|
|
75
|
+
we=(e,r)=>{let t=(0,te.getObjectSchema)(e,r);return t&&(0,te.isObjectSchema)(t)?
|
|
76
|
+
t:null};var c=require("@ez4/common/library"),E=require("@ez4/reflection");var v=require("@ez4/common/library"),Q=class extends v.IncompleteTypeError{constructor(r,t){
|
|
77
|
+
super("Incomplete table stream",r,t)}},B=class extends v.InvalidTypeError{constructor(r){
|
|
78
|
+
super("Invalid table stream type",void 0,"Database.Stream",r)}},_=class extends v.IncorrectTypeError{constructor(t,n){
|
|
79
|
+
super("Incorrect table stream type",t,"Database.Stream",n);this.streamType=t}};var Ce=require("@ez4/common/library"),J=class extends Ce.IncompleteTypeError{constructor(r,t){
|
|
80
|
+
super("Incomplete stream handler",r,t)}};var ze=(e,r,t)=>{if(!ue(e))return null;let n={},a=new Set(["name","file","change"]);
|
|
70
81
|
return e.description&&(n.description=e.description),(n.name=e.name)&&a.delete("n\
|
|
71
82
|
ame"),(n.file=e.file)&&a.delete("file"),e.parameters&&a.delete("change"),a.size===
|
|
72
|
-
0&&
|
|
73
|
-
e,t);return a?
|
|
74
|
-
e)?
|
|
75
|
-
r,(0,c.getModelMembers)(e),t,n):(n.push(new
|
|
76
|
-
r.file)),null),
|
|
83
|
+
0&&at(n)?n:(t.push(new J([...a],e.file)),null)},at=e=>!!e.name&&!!e.file;var He=(e,r,t,n)=>{if(!(0,E.isTypeReference)(e))return Ue(e,r,t,n);let a=(0,c.getReferenceType)(
|
|
84
|
+
e,t);return a?Ue(a,r,t,n):null},ot=e=>!!e.handler,Ue=(e,r,t,n)=>(0,E.isTypeObject)(
|
|
85
|
+
e)?Ne(e,r,(0,c.getObjectMembers)(e),t,n):(0,c.isModelDeclaration)(e)?ye(e)?Ne(e,
|
|
86
|
+
r,(0,c.getModelMembers)(e),t,n):(n.push(new _(e.name,e.file)),null):(n.push(new B(
|
|
87
|
+
r.file)),null),Ne=(e,r,t,n,a)=>{let o={},s=new Set(["handler"]);for(let i of t)if(!(!(0,E.isModelProperty)(
|
|
77
88
|
i)||i.inherited))switch(i.name){default:a.push(new c.InvalidServicePropertyError(
|
|
78
|
-
r.name,i.name,e.file));break;case"handler":o.handler=
|
|
89
|
+
r.name,i.name,e.file));break;case"handler":o.handler=ze(i.value,n,a);break;case"\
|
|
79
90
|
listener":o.listener=(0,c.getServiceListener)(i.value,a);break;case"memory":case"\
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
[...s],e.file)),null)};var
|
|
83
|
-
e,t);return a?
|
|
84
|
-
e)?
|
|
85
|
-
e),t,n):null,
|
|
86
|
-
if(!(!(0,
|
|
87
|
-
r.name,p.name,e.file));break;case"name":(o.name=(0,
|
|
88
|
-
p.name);break;case"schema":(o.schema=
|
|
89
|
-
indexes":(o.indexes=
|
|
90
|
-
relations=
|
|
91
|
-
if(!
|
|
92
|
-
return i.length?(a.push(...i),null):o},
|
|
93
|
-
name:o,columns:s}of r)s.some(p=>!n[p])&&a.push(new
|
|
94
|
-
a))continue;let o={type:
|
|
95
|
-
a.name;for(let
|
|
96
|
-
switch(
|
|
97
|
-
break;case"
|
|
98
|
-
|
|
99
|
-
(
|
|
100
|
-
|
|
91
|
+
logRetention":case"timeout":o[i.name]=(0,c.getPropertyNumber)(i);break;case"vari\
|
|
92
|
+
ables":o.variables=(0,c.getLinkedVariableList)(i,a);break}return ot(o)?o:(a.push(
|
|
93
|
+
new Q([...s],e.file)),null)};var ie=(e,r,t,n)=>{if(!(0,j.isTypeReference)(e))return Fe(e,r,t,n);let a=(0,y.getReferenceType)(
|
|
94
|
+
e,t);return a?Fe(a,r,t,n):null},st=e=>!!e.name&&!!e.schema&&!!e.indexes,Fe=(e,r,t,n)=>de(
|
|
95
|
+
e)?qe(e,r,(0,y.getModelMembers)(e),t,n):(0,j.isTypeObject)(e)?qe(e,r,(0,y.getObjectMembers)(
|
|
96
|
+
e),t,n):null,qe=(e,r,t,n,a)=>{let o={},s=new Set(["name","schema","indexes"]);for(let p of t)
|
|
97
|
+
if(!(!(0,j.isModelProperty)(p)||p.inherited))switch(p.name){default:a.push(new y.InvalidServicePropertyError(
|
|
98
|
+
r.name,p.name,e.file));break;case"name":(o.name=(0,y.getPropertyString)(p))&&s.delete(
|
|
99
|
+
p.name);break;case"schema":(o.schema=se(p.value,e,n,a))&&s.delete(p.name);break;case"\
|
|
100
|
+
indexes":(o.indexes=Re(p.value,e,n,a))&&s.delete(p.name);break;case"relations":o.
|
|
101
|
+
relations=Pe(p.value,e,n,a);break;case"stream":o.stream=He(p.value,r,n,a);break}
|
|
102
|
+
if(!st(o))return a.push(new N([...s],e.file)),null;let i=it(e,o.indexes,o.schema);
|
|
103
|
+
return i.length?(a.push(...i),null):o},it=(e,r,t)=>{let n=t.properties,a=[];for(let{
|
|
104
|
+
name:o,columns:s}of r)s.some(p=>!n[p])&&a.push(new V(o,e.file));return a};var pe=e=>{let r={},t=[];for(let n in e){let a=e[n];if(!X(a)||(0,d.isExternalDeclaration)(
|
|
105
|
+
a))continue;let o={type:K,extras:{}},s=new Set(["engine","tables"]),i=a.file;o.name=
|
|
106
|
+
a.name;for(let l of(0,d.getModelMembers)(a))if(!(!(0,$e.isModelProperty)(l)||l.inherited))
|
|
107
|
+
switch(l.name){default:t.push(new d.InvalidServicePropertyError(o.name,l.name,i));
|
|
108
|
+
break;case"client":break;case"scalability":(o.scalability=Me(l.value,a,e,t))&&s.
|
|
109
|
+
delete(l.name);break;case"engine":(o.engine=he(l.value,a,e,t))&&s.delete(l.name);
|
|
110
|
+
break;case"tables":(o.tables=lt(l,a,e,t))&&s.delete(l.name);break;case"variables":
|
|
111
|
+
o.variables=(0,d.getLinkedVariableList)(l,t);break;case"services":o.services=(0,d.getLinkedServiceList)(
|
|
112
|
+
l,e,t);break}if(!pt(o)){t.push(new O([...s],i));continue}let p=mt(a,o.tables);if(p.
|
|
101
113
|
length){t.push(...p);continue}if(r[a.name]){t.push(new d.DuplicateServiceError(a.
|
|
102
|
-
name,i));continue}r[a.name]=o}return{services:r,errors:t}},
|
|
103
|
-
!!e.extras,
|
|
104
|
-
let i=
|
|
105
|
-
schema:o,indexes:s}of r){if(!a)continue;let i=o.properties;for(let p of a){let{sourceTable:
|
|
106
|
-
sourceColumn:P,targetColumn:
|
|
107
|
-
n.push(new
|
|
108
|
-
|
|
109
|
-
p.targetIndex=
|
|
110
|
-
reduce((r,t)=>({...r,[t.name]:t}),{});var
|
|
111
|
-
"@ez4/database",{"metadata:getServices":
|
|
112
|
-
IncompleteTableError,IncorrectIndexesTypeError,
|
|
113
|
-
IncorrectStreamTypeError,InvalidIndexReferenceError,
|
|
114
|
-
InvalidRelationAliasError,InvalidRelationColumnError,
|
|
115
|
-
InvalidRelationsTypeError,InvalidSchemaTypeError,
|
|
116
|
-
getDatabaseServices,getDatabaseTable,getTableSchema,
|
|
114
|
+
name,i));continue}r[a.name]=o}return{services:r,errors:t}},pt=e=>!!e.name&&!!e.tables&&
|
|
115
|
+
!!e.extras,lt=(e,r,t,n)=>{let a=(0,d.getPropertyTuple)(e)??[],o=[];for(let s of a){
|
|
116
|
+
let i=ie(s,r,t,n);i&&o.push(i)}return o},mt=(e,r)=>{let t=ct(r),n=[];for(let{relations:a,
|
|
117
|
+
schema:o,indexes:s}of r){if(!a)continue;let i=o.properties;for(let p of a){let{sourceTable:l,
|
|
118
|
+
sourceColumn:P,targetColumn:ne,targetAlias:le}=p;i[ne]||n.push(new M(ne,e.file)),
|
|
119
|
+
i[le]&&n.push(new C(le,e.file));let ae=t[l]?.schema.properties;ae||n.push(new w(
|
|
120
|
+
l,e.file)),ae&&!ae[P]&&n.push(new M(P,e.file));let Ke=t[l]?.indexes??[];p.sourceIndex=
|
|
121
|
+
Ve(Ke,P),p.targetIndex=Ve(s,ne)}}return n},Ve=(e,r)=>e.find(({name:t})=>t===r)?.
|
|
122
|
+
type,ct=e=>e.reduce((r,t)=>({...r,[t.name]:t}),{});var Ge=e=>X(e)?e.name:null;var Qe=!1,dt=()=>{Qe||((0,Be.registerTriggers)(),(0,_e.registerTriggers)(),(0,Je.createTrigger)(
|
|
123
|
+
"@ez4/database",{"metadata:getServices":pe,"metadata:getLinkedService":Ge}),Qe=!0)};0&&(module.exports={IncompleteEngineError,IncompleteHandlerError,IncompleteScalabilityError,
|
|
124
|
+
IncompleteServiceError,IncompleteStreamError,IncompleteTableError,IncorrectIndexesTypeError,
|
|
125
|
+
IncorrectRelationsTypeError,IncorrectSchemaTypeError,IncorrectStreamTypeError,InvalidIndexReferenceError,
|
|
126
|
+
InvalidIndexTypeError,InvalidIndexesTypeError,InvalidRelationAliasError,InvalidRelationColumnError,
|
|
127
|
+
InvalidRelationTableError,InvalidRelationTargetError,InvalidRelationsTypeError,InvalidSchemaTypeError,
|
|
128
|
+
InvalidStreamTypeError,ServiceType,getDatabaseServices,getDatabaseTable,getTableSchema,
|
|
129
|
+
isDatabaseService,registerTriggers});
|
|
117
130
|
//# sourceMappingURL=library.cjs.map
|
package/dist/library.d.ts
CHANGED
|
@@ -3,6 +3,8 @@ export * from './metadata/service.js';
|
|
|
3
3
|
export * from './metadata/table.js';
|
|
4
4
|
export * from './metadata/schema.js';
|
|
5
5
|
export * from './errors/service.js';
|
|
6
|
+
export * from './errors/scalability.js';
|
|
7
|
+
export * from './errors/engine.js';
|
|
6
8
|
export * from './errors/table.js';
|
|
7
9
|
export * from './errors/schema.js';
|
|
8
10
|
export * from './errors/relations.js';
|
package/dist/library.mjs
CHANGED
|
@@ -1,113 +1,124 @@
|
|
|
1
|
-
import{registerTriggers as
|
|
2
|
-
import{createTrigger as
|
|
3
|
-
getLinkedServiceList as
|
|
4
|
-
import{isModelProperty as
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import{registerTriggers as sr}from"@ez4/common/library";import{registerTriggers as ir}from"@ez4/schema/library";
|
|
2
|
+
import{createTrigger as pr}from"@ez4/project/library";import{DuplicateServiceError as Kt,InvalidServicePropertyError as Wt,isExternalDeclaration as Xt,
|
|
3
|
+
getLinkedServiceList as Yt,getLinkedVariableList as Zt,getPropertyTuple as Lt,getModelMembers as er}from"@ez4/common/library";
|
|
4
|
+
import{isModelProperty as tr}from"@ez4/reflection";var H="@ez4/database",lr=e=>e.type===H;import{IncompleteTypeError as Se}from"@ez4/common/library";var b=class extends Se{constructor(r,t){
|
|
5
|
+
super("Incomplete database service",r,t)}};import{IncorrectTypeError as De,InvalidTypeError as he,TypeError as M}from"@ez4/common/library";
|
|
6
|
+
var T=class extends he{constructor(r){super("Invalid table relations type",void 0,
|
|
7
|
+
"Database.Relations",r)}},f=class extends De{constructor(t,n){super("Incorrect t\
|
|
8
|
+
able relations type",t,"Database.Relations",n);this.schemaType=t}},y=class extends M{constructor(t,n){
|
|
8
9
|
super(`Target ${t} must follow the pattern 'column@alias'.`,n);this.relationSource=
|
|
9
|
-
t}},x=class extends
|
|
10
|
-
n);this.relationTable=t}},
|
|
11
|
-
umn ${t} don't exists.`,n);this.relationColumn=t}},g=class extends
|
|
10
|
+
t}},x=class extends M{constructor(t,n){super(`Relation table ${t} don't exists.`,
|
|
11
|
+
n);this.relationTable=t}},d=class extends M{constructor(t,n){super(`Relation col\
|
|
12
|
+
umn ${t} don't exists.`,n);this.relationColumn=t}},g=class extends M{constructor(t,n){
|
|
12
13
|
super(`Relation alias ${t} can't override table columns.`,n);this.relationAlias=
|
|
13
|
-
t}};import{
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
"
|
|
38
|
-
|
|
14
|
+
t}};import{InvalidServicePropertyError as Oe,getModelMembers as ke,getPropertyNumber as Re,
|
|
15
|
+
getObjectMembers as Ae,getReferenceType as we}from"@ez4/common/library";import{isModelProperty as Ce,
|
|
16
|
+
isTypeObject as ze,isTypeReference as Ue}from"@ez4/reflection";import{isAnyNumber as F}from"@ez4/utils";import{IncompleteTypeError as ve}from"@ez4/common/library";var I=class extends ve{constructor(r,t){
|
|
17
|
+
super("Incomplete database scalability",r,t)}};import{hasHeritageType as m,isClassDeclaration as Ee,isModelDeclaration as V}from"@ez4/common/library";
|
|
18
|
+
import{isTypeCallback as je,isTypeFunction as Pe}from"@ez4/reflection";var S=e=>Ee(
|
|
19
|
+
e)&&m(e,"Database.Service"),D=e=>V(e)&&m(e,"Database.Engine"),$=e=>V(e)&&m(e,"Da\
|
|
20
|
+
tabase.Table"),G=e=>je(e)||Pe(e),Q=e=>m(e,"Database.Relations"),B=e=>m(e,"Databa\
|
|
21
|
+
se.Indexes"),_=e=>m(e,"Database.Schema"),J=e=>m(e,"Database.Stream");var X=(e,r,t,n)=>{if(!Ue(e))return K(e,r,n);let a=we(e,t);return a?K(a,r,n):null},
|
|
22
|
+
Ne=e=>F(e.minCapacity)&&F(e.maxCapacity),K=(e,r,t)=>D(e)?W(e,r,ke(e),t):ze(e)?W(
|
|
23
|
+
e,r,Ae(e),t):null,W=(e,r,t,n)=>{let a={},o=new Set(["minCapacity","maxCapacity"]);
|
|
24
|
+
for(let s of t)if(!(!Ce(s)||s.inherited))switch(s.name){default:n.push(new Oe(r.
|
|
25
|
+
name,s.name,e.file));break;case"minCapacity":case"maxCapacity":let i=Re(s);F(i)&&
|
|
26
|
+
(a[s.name]=i,o.delete(s.name));break}return Ne(a)?a:(n.push(new I([...o],e.file)),
|
|
27
|
+
null)};import{isModelProperty as Fe,isTypeObject as qe,isTypeReference as Ve}from"@ez4/reflection";
|
|
28
|
+
import{InvalidServicePropertyError as $e,getModelMembers as Ge,getObjectMembers as Qe,
|
|
29
|
+
getPropertyString as Be,getPropertyStringIn as u,getReferenceType as _e}from"@ez4/common/library";import{IncompleteTypeError as He}from"@ez4/common/library";var h=class extends He{constructor(r,t){
|
|
30
|
+
super("Incomplete database engine",r,t)}};var L=(e,r,t,n)=>{if(!Ve(e))return Y(e,r,n);let a=_e(e,t);return a?Y(a,r,n):null},
|
|
31
|
+
Je=e=>!!e.name&&!!e.parametersMode&&!!e.transactionMode&&!!e.insensitiveMode&&!!e.
|
|
32
|
+
paginationMode&&!!e.orderMode,Y=(e,r,t)=>D(e)?Z(e,r,Ge(e),t):qe(e)?Z(e,r,Qe(e),t):
|
|
33
|
+
null,Z=(e,r,t,n)=>{let a={},o=new Set(["name","parametersMode","transactionMode",
|
|
34
|
+
"insensitiveMode","paginationMode","orderMode"]);for(let s of t)if(!(!Fe(s)||s.inherited))
|
|
35
|
+
switch(s.name){default:n.push(new $e(r.name,s.name,e.file));break;case"name":(a.
|
|
36
|
+
name=Be(s))&&o.delete(s.name);break;case"parametersMode":(a.parametersMode=u(s,[
|
|
37
|
+
"index","both"]))&&o.delete(s.name);break;case"transactionMode":(a.transactionMode=
|
|
38
|
+
u(s,["static","interactive"]))&&o.delete(s.name);break;case"insensitiveMode":(a.
|
|
39
|
+
insensitiveMode=u(s,["unsupported","enabled"]))&&o.delete(s.name);break;case"pag\
|
|
40
|
+
inationMode":(a.paginationMode=u(s,["cursor","offset"]))&&o.delete(s.name);break;case"\
|
|
41
|
+
orderMode":(a.orderMode=u(s,["any","index"]))&&o.delete(s.name);break}return Je(
|
|
42
|
+
a)?a:(n.push(new h([...o],e.file)),null)};import{InvalidServicePropertyError as Ht,getModelMembers as Ft,getObjectMembers as qt,
|
|
43
|
+
getPropertyString as Vt,getReferenceType as $t}from"@ez4/common/library";import{
|
|
44
|
+
isModelProperty as Gt,isTypeObject as Qt,isTypeReference as Bt}from"@ez4/reflection";import{IncompleteTypeError as Ke}from"@ez4/common/library";var v=class extends Ke{constructor(r,t){
|
|
45
|
+
super("Incomplete database table",r,t)}};import{IncorrectTypeError as We,InvalidTypeError as Xe,TypeError as ee}from"@ez4/common/library";
|
|
46
|
+
var E=class extends Xe{constructor(r){super("Invalid table indexes type",void 0,
|
|
47
|
+
"Database.Indexes",r)}},j=class extends We{constructor(t,n){super("Incorrect tab\
|
|
48
|
+
le indexes type",t,"Database.Indexes",n);this.schemaType=t}},P=class extends ee{constructor(t,n){
|
|
39
49
|
super(`Invalid index type, ${t} must follow one of the Index options.`,n);this.indexName=
|
|
40
|
-
t}},
|
|
41
|
-
be valid column.`,n);this.indexName=t}};import{isModelDeclaration as
|
|
42
|
-
getReferenceType as
|
|
43
|
-
isTypeReference as
|
|
44
|
-
|
|
45
|
-
null):(t.push(new
|
|
46
|
-
a.inherited)continue;let o=
|
|
47
|
-
let[i,p]=s.split("@",2),[
|
|
48
|
-
targetColumn:i,targetAlias:p})}return n};import{isModelDeclaration as
|
|
49
|
-
getReferenceType as
|
|
50
|
-
isTypeReference as
|
|
51
|
-
|
|
52
|
-
null):(t.push(new
|
|
53
|
-
a)||a.inherited)continue;let o=a.name,s=
|
|
54
|
-
|
|
55
|
-
return t.push(new
|
|
56
|
-
import{getObjectSchema as
|
|
57
|
-
isTypeObject as
|
|
58
|
-
var
|
|
59
|
-
Database.Schema",r)}},
|
|
60
|
-
schema type",t,"Database.Schema",n);this.schemaType=t}};var
|
|
61
|
-
n):null},
|
|
62
|
-
null):(n.push(new
|
|
63
|
-
getModelMembers as
|
|
64
|
-
getReferenceType as
|
|
65
|
-
isTypeReference as
|
|
66
|
-
var
|
|
67
|
-
super("Invalid table stream type",void 0,"Database.Stream",r)}},
|
|
68
|
-
super("Incorrect table stream type",t,"Database.Stream",n);this.streamType=t}};import{IncompleteTypeError as
|
|
69
|
-
super("Incomplete stream handler",r,t)}};var
|
|
50
|
+
t}},O=class extends ee{constructor(t,n){super(`Invalid index reference, ${t} mus\
|
|
51
|
+
t be valid column.`,n);this.indexName=t}};import{isModelDeclaration as Ye,getModelMembers as Ze,getObjectMembers as Le,getPropertyString as et,
|
|
52
|
+
getReferenceType as tt}from"@ez4/common/library";import{isModelProperty as rt,isTypeObject as nt,
|
|
53
|
+
isTypeReference as at}from"@ez4/reflection";var ne=(e,r,t,n)=>{if(!at(e))return te(e,r,n);let a=tt(e,t);return a?te(a,r,n):null},
|
|
54
|
+
te=(e,r,t)=>nt(e)?re(e,Le(e),t):Ye(e)?Q(e)?re(e,Ze(e),t):(t.push(new f(e.name,e.
|
|
55
|
+
file)),null):(t.push(new T(r.file)),null),re=(e,r,t)=>{let n=[];for(let a of r){
|
|
56
|
+
if(!rt(a)||a.inherited)continue;let o=et(a),s=a.name;if(!o)return t.push(new y(s,
|
|
57
|
+
e.file)),null;let[i,p]=s.split("@",2),[l,c]=o.split(":",2);n.push({sourceTable:l,
|
|
58
|
+
sourceColumn:c,targetColumn:i,targetAlias:p})}return n};import{isModelDeclaration as ot,getModelMembers as st,getObjectMembers as it,getPropertyString as pt,
|
|
59
|
+
getReferenceType as lt}from"@ez4/common/library";import{isModelProperty as mt,isTypeObject as ct,
|
|
60
|
+
isTypeReference as dt}from"@ez4/reflection";var se=(e,r,t,n)=>{if(!dt(e))return ae(e,r,n);let a=lt(e,t);return a?ae(a,r,n):null},
|
|
61
|
+
ae=(e,r,t)=>ct(e)?oe(e,it(e),t):ot(e)?B(e)?oe(e,st(e),t):(t.push(new j(e.name,e.
|
|
62
|
+
file)),null):(t.push(new E(r.file)),null),oe=(e,r,t)=>{let n=[];for(let a of r){
|
|
63
|
+
if(!mt(a)||a.inherited)continue;let o=a.name,s=pt(a);switch(s){case"primary":case"\
|
|
64
|
+
secondary":case"unique":case"ttl":n.push({name:o,columns:o.split(":"),type:s});break;default:
|
|
65
|
+
return t.push(new P(o,e.file)),null}}return n};import{getReferenceType as Tt,isModelDeclaration as ft}from"@ez4/common/library";
|
|
66
|
+
import{getObjectSchema as yt,isObjectSchema as xt}from"@ez4/schema/library";import{
|
|
67
|
+
isTypeObject as gt,isTypeReference as Mt}from"@ez4/reflection";import{IncorrectTypeError as ut,InvalidTypeError as bt}from"@ez4/common/library";
|
|
68
|
+
var k=class extends bt{constructor(r){super("Invalid table schema type",void 0,"\
|
|
69
|
+
Database.Schema",r)}},R=class extends ut{constructor(t,n){super("Incorrect table\
|
|
70
|
+
schema type",t,"Database.Schema",n);this.schemaType=t}};var le=(e,r,t,n)=>{if(!Mt(e))return ie(e,r,t,n);let a=Tt(e,t);return a?ie(a,r,t,
|
|
71
|
+
n):null},ie=(e,r,t,n)=>gt(e)?pe(e,t):ft(e)?_(e)?pe(e,t):(n.push(new R(e.name,e.file)),
|
|
72
|
+
null):(n.push(new k(r.file)),null),pe=(e,r)=>{let t=yt(e,r);return t&&xt(t)?t:null};import{InvalidServicePropertyError as Et,isModelDeclaration as jt,getLinkedVariableList as Pt,
|
|
73
|
+
getModelMembers as Ot,getObjectMembers as kt,getPropertyNumber as Rt,getServiceListener as At,
|
|
74
|
+
getReferenceType as wt}from"@ez4/common/library";import{isModelProperty as Ct,isTypeObject as zt,
|
|
75
|
+
isTypeReference as Ut}from"@ez4/reflection";import{IncompleteTypeError as It,IncorrectTypeError as St,InvalidTypeError as Dt}from"@ez4/common/library";
|
|
76
|
+
var A=class extends It{constructor(r,t){super("Incomplete table stream",r,t)}},w=class extends Dt{constructor(r){
|
|
77
|
+
super("Invalid table stream type",void 0,"Database.Stream",r)}},C=class extends St{constructor(t,n){
|
|
78
|
+
super("Incorrect table stream type",t,"Database.Stream",n);this.streamType=t}};import{IncompleteTypeError as ht}from"@ez4/common/library";var z=class extends ht{constructor(r,t){
|
|
79
|
+
super("Incomplete stream handler",r,t)}};var me=(e,r,t)=>{if(!G(e))return null;let n={},a=new Set(["name","file","change"]);
|
|
70
80
|
return e.description&&(n.description=e.description),(n.name=e.name)&&a.delete("n\
|
|
71
81
|
ame"),(n.file=e.file)&&a.delete("file"),e.parameters&&a.delete("change"),a.size===
|
|
72
|
-
0&&
|
|
73
|
-
n):null},
|
|
74
|
-
r,
|
|
75
|
-
let o={},s=new Set(["handler"]);for(let i of t)if(!(!
|
|
76
|
-
name){default:a.push(new
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
a);break}return
|
|
80
|
-
n):null},
|
|
81
|
-
t,n):
|
|
82
|
-
chema","indexes"]);for(let p of t)if(!(!
|
|
83
|
-
a.push(new
|
|
84
|
-
name);break;case"schema":(o.schema=
|
|
85
|
-
indexes":(o.indexes=
|
|
86
|
-
relations=
|
|
87
|
-
o))return a.push(new
|
|
88
|
-
length?(a.push(...i),null):o},
|
|
89
|
-
columns:s}of r)s.some(p=>!n[p])&&a.push(new
|
|
90
|
-
type:
|
|
91
|
-
a))if(!(!
|
|
92
|
-
i));break;case"
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
82
|
+
0&&vt(n)?n:(t.push(new z([...a],e.file)),null)},vt=e=>!!e.name&&!!e.file;var ue=(e,r,t,n)=>{if(!Ut(e))return ce(e,r,t,n);let a=wt(e,t);return a?ce(a,r,t,
|
|
83
|
+
n):null},Nt=e=>!!e.handler,ce=(e,r,t,n)=>zt(e)?de(e,r,kt(e),t,n):jt(e)?J(e)?de(e,
|
|
84
|
+
r,Ot(e),t,n):(n.push(new C(e.name,e.file)),null):(n.push(new w(r.file)),null),de=(e,r,t,n,a)=>{
|
|
85
|
+
let o={},s=new Set(["handler"]);for(let i of t)if(!(!Ct(i)||i.inherited))switch(i.
|
|
86
|
+
name){default:a.push(new Et(r.name,i.name,e.file));break;case"handler":o.handler=
|
|
87
|
+
me(i.value,n,a);break;case"listener":o.listener=At(i.value,a);break;case"memory":case"\
|
|
88
|
+
logRetention":case"timeout":o[i.name]=Rt(i);break;case"variables":o.variables=Pt(
|
|
89
|
+
i,a);break}return Nt(o)?o:(a.push(new A([...s],e.file)),null)};var fe=(e,r,t,n)=>{if(!Bt(e))return be(e,r,t,n);let a=$t(e,t);return a?be(a,r,t,
|
|
90
|
+
n):null},_t=e=>!!e.name&&!!e.schema&&!!e.indexes,be=(e,r,t,n)=>$(e)?Te(e,r,Ft(e),
|
|
91
|
+
t,n):Qt(e)?Te(e,r,qt(e),t,n):null,Te=(e,r,t,n,a)=>{let o={},s=new Set(["name","s\
|
|
92
|
+
chema","indexes"]);for(let p of t)if(!(!Gt(p)||p.inherited))switch(p.name){default:
|
|
93
|
+
a.push(new Ht(r.name,p.name,e.file));break;case"name":(o.name=Vt(p))&&s.delete(p.
|
|
94
|
+
name);break;case"schema":(o.schema=le(p.value,e,n,a))&&s.delete(p.name);break;case"\
|
|
95
|
+
indexes":(o.indexes=se(p.value,e,n,a))&&s.delete(p.name);break;case"relations":o.
|
|
96
|
+
relations=ne(p.value,e,n,a);break;case"stream":o.stream=ue(p.value,r,n,a);break}
|
|
97
|
+
if(!_t(o))return a.push(new v([...s],e.file)),null;let i=Jt(e,o.indexes,o.schema);
|
|
98
|
+
return i.length?(a.push(...i),null):o},Jt=(e,r,t)=>{let n=t.properties,a=[];for(let{
|
|
99
|
+
name:o,columns:s}of r)s.some(p=>!n[p])&&a.push(new O(o,e.file));return a};var xe=e=>{let r={},t=[];for(let n in e){let a=e[n];if(!S(a)||Xt(a))continue;let o={
|
|
100
|
+
type:H,extras:{}},s=new Set(["engine","tables"]),i=a.file;o.name=a.name;for(let l of er(
|
|
101
|
+
a))if(!(!tr(l)||l.inherited))switch(l.name){default:t.push(new Wt(o.name,l.name,
|
|
102
|
+
i));break;case"client":break;case"scalability":(o.scalability=X(l.value,a,e,t))&&
|
|
103
|
+
s.delete(l.name);break;case"engine":(o.engine=L(l.value,a,e,t))&&s.delete(l.name);
|
|
104
|
+
break;case"tables":(o.tables=nr(l,a,e,t))&&s.delete(l.name);break;case"variables":
|
|
105
|
+
o.variables=Zt(l,t);break;case"services":o.services=Yt(l,e,t);break}if(!rr(o)){t.
|
|
106
|
+
push(new b([...s],i));continue}let p=ar(a,o.tables);if(p.length){t.push(...p);continue}
|
|
107
|
+
if(r[a.name]){t.push(new Kt(a.name,i));continue}r[a.name]=o}return{services:r,errors:t}},
|
|
108
|
+
rr=e=>!!e.name&&!!e.tables&&!!e.extras,nr=(e,r,t,n)=>{let a=Lt(e)??[],o=[];for(let s of a){
|
|
109
|
+
let i=fe(s,r,t,n);i&&o.push(i)}return o},ar=(e,r)=>{let t=or(r),n=[];for(let{relations:a,
|
|
110
|
+
schema:o,indexes:s}of r){if(!a)continue;let i=o.properties;for(let p of a){let{sourceTable:l,
|
|
111
|
+
sourceColumn:c,targetColumn:U,targetAlias:q}=p;i[U]||n.push(new d(U,e.file)),i[q]&&
|
|
112
|
+
n.push(new g(q,e.file));let N=t[l]?.schema.properties;N||n.push(new x(l,e.file)),
|
|
113
|
+
N&&!N[c]&&n.push(new d(c,e.file));let Ie=t[l]?.indexes??[];p.sourceIndex=ye(Ie,c),
|
|
114
|
+
p.targetIndex=ye(s,U)}}return n},ye=(e,r)=>e.find(({name:t})=>t===r)?.type,or=e=>e.
|
|
115
|
+
reduce((r,t)=>({...r,[t.name]:t}),{});var ge=e=>S(e)?e.name:null;var Me=!1,sa=()=>{Me||(sr(),ir(),pr("@ez4/database",{"metadata:getServices":xe,"\
|
|
116
|
+
metadata:getLinkedService":ge}),Me=!0)};export{h as IncompleteEngineError,z as IncompleteHandlerError,I as IncompleteScalabilityError,
|
|
117
|
+
b as IncompleteServiceError,A as IncompleteStreamError,v as IncompleteTableError,
|
|
118
|
+
j as IncorrectIndexesTypeError,f as IncorrectRelationsTypeError,R as IncorrectSchemaTypeError,
|
|
119
|
+
C as IncorrectStreamTypeError,O as InvalidIndexReferenceError,P as InvalidIndexTypeError,
|
|
120
|
+
E as InvalidIndexesTypeError,g as InvalidRelationAliasError,d as InvalidRelationColumnError,
|
|
121
|
+
x as InvalidRelationTableError,y as InvalidRelationTargetError,T as InvalidRelationsTypeError,
|
|
122
|
+
k as InvalidSchemaTypeError,w as InvalidStreamTypeError,H as ServiceType,xe as getDatabaseServices,
|
|
123
|
+
fe as getDatabaseTable,le as getTableSchema,lr as isDatabaseService,sa as registerTriggers};
|
|
113
124
|
//# sourceMappingURL=library.mjs.map
|
package/dist/main.cjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
"use strict";var s=Object.defineProperty;var
|
|
1
|
+
"use strict";var s=Object.defineProperty;var l=Object.getOwnPropertyDescriptor;var b=Object.getOwnPropertyNames;var I=Object.prototype.hasOwnProperty;var u=(a,n)=>{for(var e in n)s(a,e,{get:n[e],enumerable:!0})},g=(a,n,e,r)=>{if(n&&
|
|
2
2
|
typeof n=="object"||typeof n=="function")for(let t of b(n))!I.call(a,t)&&t!==e&&
|
|
3
|
-
s(a,t,{get:()=>n[t],enumerable:!(r=
|
|
4
|
-
PaginationMode:()=>d,ParametersMode:()=>o,StreamType:()=>
|
|
5
|
-
module.exports=
|
|
3
|
+
s(a,t,{get:()=>n[t],enumerable:!(r=l(n,t))||r.enumerable});return a};var f=a=>g(s({},"__esModule",{value:!0}),a);var S={};u(S,{Database:()=>T,Index:()=>y,InsensitiveMode:()=>p,Order:()=>m,OrderMode:()=>x,
|
|
4
|
+
PaginationMode:()=>d,ParametersMode:()=>o,StreamType:()=>c,TransactionMode:()=>i});
|
|
5
|
+
module.exports=f(S);var c=(r=>(r.Insert="insert",r.Update="update",r.Delete="delete",r))(c||{});var o=(e=>(e.NameAndIndex="both",e.OnlyIndex="index",e))(o||{});var i=(e=>(e.Interactive="interactive",e.Static="static",e))(i||{});var p=(e=>(e.Unsupported="unsupported",e.Enabled="enabled",e))(p||{});var d=(e=>(e.Cursor="cursor",e.Offset="offset",e))(d||{});var m=(e=>(e.Asc="asc",e.Desc="desc",e))(m||{}),x=(e=>(e.IndexColumns="index",e.
|
|
6
6
|
AnyColumns="any",e))(x||{});var T;(a=>{})(T||={});var y=(t=>(t.Primary="primary",t.Secondary="secondary",t.Unique="unique",t.TTL="\
|
|
7
7
|
ttl",t))(y||{});0&&(module.exports={Database,Index,InsensitiveMode,Order,OrderMode,PaginationMode,
|
|
8
8
|
ParametersMode,StreamType,TransactionMode});
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { AllType, SourceMap, TypeModel } from '@ez4/reflection';
|
|
2
|
+
import { DatabaseScalability } from '../types/scalability.js';
|
|
3
|
+
export declare const getDatabaseScalability: (type: AllType, parent: TypeModel, reflection: SourceMap, errorList: Error[]) => DatabaseScalability | null;
|
|
@@ -52,6 +52,13 @@ export declare namespace Database {
|
|
|
52
52
|
* Service engine.
|
|
53
53
|
*/
|
|
54
54
|
type Engine = DatabaseEngine;
|
|
55
|
+
/**
|
|
56
|
+
* Service scalability configuration.
|
|
57
|
+
*/
|
|
58
|
+
interface Scalability {
|
|
59
|
+
minCapacity: number;
|
|
60
|
+
maxCapacity: number;
|
|
61
|
+
}
|
|
55
62
|
/**
|
|
56
63
|
* Table stream.
|
|
57
64
|
*/
|
|
@@ -71,7 +78,7 @@ export declare namespace Database {
|
|
|
71
78
|
/**
|
|
72
79
|
* Log retention (in days) for the handler.
|
|
73
80
|
*/
|
|
74
|
-
|
|
81
|
+
logRetention?: number;
|
|
75
82
|
/**
|
|
76
83
|
* Max execution time (in seconds) for the handler.
|
|
77
84
|
*/
|
|
@@ -119,6 +126,10 @@ export declare namespace Database {
|
|
|
119
126
|
* Describe all available tables for the service.
|
|
120
127
|
*/
|
|
121
128
|
abstract tables: Table<any>[];
|
|
129
|
+
/**
|
|
130
|
+
* Scalability configuration.
|
|
131
|
+
*/
|
|
132
|
+
scalability: Scalability;
|
|
122
133
|
/**
|
|
123
134
|
* Service client.
|
|
124
135
|
*/
|
|
@@ -3,7 +3,6 @@ import type { TransactionMode } from './transaction.js';
|
|
|
3
3
|
import type { InsensitiveMode } from './insensitive.js';
|
|
4
4
|
import type { PaginationMode } from './pagination.js';
|
|
5
5
|
import type { OrderMode } from './order.js';
|
|
6
|
-
import type { TableMetadata } from './table.js';
|
|
7
6
|
import type { Database } from './database.js';
|
|
8
7
|
/**
|
|
9
8
|
* Database engine.
|
|
@@ -33,15 +32,15 @@ export declare namespace EngineUtils {
|
|
|
33
32
|
transactionMode: infer M;
|
|
34
33
|
} ? M : never;
|
|
35
34
|
/**
|
|
36
|
-
* Get the insensitive mode from the given
|
|
35
|
+
* Get the insensitive mode from the given database engine.
|
|
37
36
|
*/
|
|
38
|
-
type GetInsensitiveMode<
|
|
37
|
+
type GetInsensitiveMode<E extends DatabaseEngine> = E extends {
|
|
39
38
|
insensitiveMode: infer M;
|
|
40
39
|
} ? M : never;
|
|
41
40
|
/**
|
|
42
|
-
* Get the pagination mode from the given
|
|
41
|
+
* Get the pagination mode from the given database engine.
|
|
43
42
|
*/
|
|
44
|
-
type GetPaginationMode<
|
|
43
|
+
type GetPaginationMode<E extends DatabaseEngine> = E extends {
|
|
45
44
|
paginationMode: infer M;
|
|
46
45
|
} ? M : never;
|
|
47
46
|
/**
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { EngineUtils } from './engine.js';
|
|
1
|
+
import type { DatabaseEngine, EngineUtils } from './engine.js';
|
|
3
2
|
/**
|
|
4
3
|
* Insensitive mode.
|
|
5
4
|
*/
|
|
@@ -12,9 +11,9 @@ export declare const enum InsensitiveMode {
|
|
|
12
11
|
*/
|
|
13
12
|
export declare namespace InsensitiveUtils {
|
|
14
13
|
/**
|
|
15
|
-
* Get the insensitive input based on the given
|
|
14
|
+
* Get the insensitive input based on the given database engine.
|
|
16
15
|
*/
|
|
17
|
-
type Input<
|
|
16
|
+
type Input<E extends DatabaseEngine> = EngineUtils.GetInsensitiveMode<E> extends InsensitiveMode.Enabled ? {
|
|
18
17
|
insensitive?: boolean;
|
|
19
18
|
} : {};
|
|
20
19
|
}
|
package/dist/services/order.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import type { AnyObject } from '@ez4/utils';
|
|
2
1
|
import type { DecomposeIndexName } from './indexes.js';
|
|
3
|
-
import type {
|
|
2
|
+
import type { TableMetadata } from './table.js';
|
|
4
3
|
import type { Database } from './database.js';
|
|
5
4
|
/**
|
|
6
5
|
* Query order types.
|
|
@@ -33,8 +32,7 @@ export declare namespace OrderUtils {
|
|
|
33
32
|
[P in keyof T]?: Order;
|
|
34
33
|
};
|
|
35
34
|
/**
|
|
36
|
-
* Order input type based on the
|
|
35
|
+
* Order input type based on the table metadata.
|
|
37
36
|
*/
|
|
38
|
-
|
|
39
|
-
export {};
|
|
37
|
+
type Input<T extends TableMetadata> = T['engine']['orderMode'] extends OrderMode.IndexColumns ? IndexInput<T['indexes']> : AnyInput<T['schema']>;
|
|
40
38
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { EngineUtils } from './engine.js';
|
|
1
|
+
import type { DatabaseEngine, EngineUtils } from './engine.js';
|
|
3
2
|
/**
|
|
4
3
|
* Pagination mode.
|
|
5
4
|
*/
|
|
@@ -12,9 +11,9 @@ export declare const enum PaginationMode {
|
|
|
12
11
|
*/
|
|
13
12
|
export declare namespace PaginationUtils {
|
|
14
13
|
/**
|
|
15
|
-
* Get the pagination range based on the given
|
|
14
|
+
* Get the pagination range based on the given database engine.
|
|
16
15
|
*/
|
|
17
|
-
type Range<
|
|
16
|
+
type Range<E extends DatabaseEngine> = EngineUtils.GetPaginationMode<E> extends PaginationMode.Cursor ? {
|
|
18
17
|
cursor?: string;
|
|
19
18
|
limit?: number;
|
|
20
19
|
} : {
|
|
@@ -24,7 +23,7 @@ export declare namespace PaginationUtils {
|
|
|
24
23
|
/**
|
|
25
24
|
* Get the pagination begin based on the given table metadata.
|
|
26
25
|
*/
|
|
27
|
-
type Begin<
|
|
26
|
+
type Begin<E extends DatabaseEngine> = EngineUtils.GetPaginationMode<E> extends PaginationMode.Cursor ? {
|
|
28
27
|
cursor?: string;
|
|
29
28
|
} : {
|
|
30
29
|
skip?: number;
|
|
@@ -32,7 +31,7 @@ export declare namespace PaginationUtils {
|
|
|
32
31
|
/**
|
|
33
32
|
* Get the pagination end based on the given table metadata.
|
|
34
33
|
*/
|
|
35
|
-
type End<
|
|
34
|
+
type End<E extends DatabaseEngine> = EngineUtils.GetPaginationMode<E> extends PaginationMode.Cursor ? {
|
|
36
35
|
limit?: number;
|
|
37
36
|
} : {
|
|
38
37
|
take?: number;
|
|
@@ -40,7 +39,7 @@ export declare namespace PaginationUtils {
|
|
|
40
39
|
/**
|
|
41
40
|
* Get the pagination result based on the given table metadata.
|
|
42
41
|
*/
|
|
43
|
-
type Result<
|
|
42
|
+
type Result<E extends DatabaseEngine> = EngineUtils.GetPaginationMode<E> extends PaginationMode.Cursor ? {
|
|
44
43
|
cursor?: string;
|
|
45
44
|
} : {};
|
|
46
45
|
}
|
package/dist/services/query.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { DecomposeIndexName, PrimaryIndexes, UniqueIndexes } from './indexes.js';
|
|
2
|
+
import type { DatabaseEngine } from './engine.js';
|
|
2
3
|
import type { RelationMetadata } from './relations.js';
|
|
3
4
|
import type { InsensitiveUtils } from './insensitive.js';
|
|
4
5
|
import type { PaginationUtils } from './pagination.js';
|
|
@@ -16,46 +17,46 @@ export declare namespace Query {
|
|
|
16
17
|
};
|
|
17
18
|
export type UpdateOneInput<S extends AnyObject, T extends TableMetadata> = {
|
|
18
19
|
select?: StrictSelectInput<S, T>;
|
|
19
|
-
include?: StrictIncludeInput<T>;
|
|
20
|
+
include?: StrictIncludeInput<S, T>;
|
|
20
21
|
data: OptionalObject<UpdateDataInput<T>>;
|
|
21
22
|
where: WhereInput<T, true>;
|
|
22
23
|
};
|
|
23
24
|
export type FindOneInput<S extends AnyObject, T extends TableMetadata> = {
|
|
24
25
|
select: StrictSelectInput<S, T>;
|
|
25
|
-
include?: StrictIncludeInput<T>;
|
|
26
|
+
include?: StrictIncludeInput<S, T>;
|
|
26
27
|
where: WhereInput<T, true>;
|
|
27
28
|
};
|
|
28
29
|
export type UpsertOneInput<S extends AnyObject, T extends TableMetadata> = {
|
|
29
30
|
select?: StrictSelectInput<S, T>;
|
|
30
|
-
include?: StrictIncludeInput<T>;
|
|
31
|
+
include?: StrictIncludeInput<S, T>;
|
|
31
32
|
update: OptionalObject<UpdateDataInput<T>>;
|
|
32
33
|
insert: InsertDataInput<T>;
|
|
33
34
|
where: WhereInput<T, true>;
|
|
34
35
|
};
|
|
35
36
|
export type DeleteOneInput<S extends AnyObject, T extends TableMetadata> = {
|
|
36
37
|
select?: StrictSelectInput<S, T>;
|
|
37
|
-
include?: StrictIncludeInput<T>;
|
|
38
|
+
include?: StrictIncludeInput<S, T>;
|
|
38
39
|
where: WhereInput<T, true>;
|
|
39
40
|
};
|
|
40
41
|
export type InsertManyInput<T extends TableMetadata> = {
|
|
41
42
|
data: T['schema'][];
|
|
42
43
|
};
|
|
43
|
-
export type UpdateManyInput<S extends AnyObject, T extends TableMetadata> = PaginationUtils.End<T> & {
|
|
44
|
+
export type UpdateManyInput<S extends AnyObject, T extends TableMetadata> = PaginationUtils.End<T['engine']> & {
|
|
44
45
|
select?: StrictSelectInput<S, T>;
|
|
45
|
-
include?: StrictIncludeInput<T>;
|
|
46
|
+
include?: StrictIncludeInput<S, T>;
|
|
46
47
|
data: OptionalObject<UpdateDataInput<T>>;
|
|
47
48
|
where?: WhereInput<T>;
|
|
48
49
|
};
|
|
49
|
-
export type FindManyInput<S extends AnyObject, T extends TableMetadata, C extends boolean> = PaginationUtils.Range<T> & {
|
|
50
|
+
export type FindManyInput<S extends AnyObject, T extends TableMetadata, C extends boolean> = PaginationUtils.Range<T['engine']> & {
|
|
50
51
|
count?: C;
|
|
51
52
|
select: StrictSelectInput<S, T>;
|
|
52
|
-
include?: StrictIncludeInput<T>;
|
|
53
|
+
include?: StrictIncludeInput<S, T>;
|
|
53
54
|
where?: WhereInput<T>;
|
|
54
55
|
order?: OrderInput<T>;
|
|
55
56
|
};
|
|
56
|
-
export type DeleteManyInput<S extends AnyObject, T extends TableMetadata> = PaginationUtils.End<T> & {
|
|
57
|
+
export type DeleteManyInput<S extends AnyObject, T extends TableMetadata> = PaginationUtils.End<T['engine']> & {
|
|
57
58
|
select?: StrictSelectInput<S, T>;
|
|
58
|
-
include?: StrictIncludeInput<T>;
|
|
59
|
+
include?: StrictIncludeInput<S, T>;
|
|
59
60
|
where?: WhereInput<T>;
|
|
60
61
|
};
|
|
61
62
|
export type CountInput<T extends TableMetadata> = {
|
|
@@ -68,7 +69,7 @@ export declare namespace Query {
|
|
|
68
69
|
export type DeleteOneResult<S extends AnyObject, T extends TableMetadata> = S extends never ? void : Record<S, T> | undefined;
|
|
69
70
|
export type UpdateManyResult<S extends AnyObject, T extends TableMetadata> = S extends never ? void : Record<S, T>[];
|
|
70
71
|
export type InsertManyResult = void;
|
|
71
|
-
export type FindManyResult<S extends AnyObject, T extends TableMetadata, C extends boolean> = PaginationUtils.Result<T> & (C extends true ? {
|
|
72
|
+
export type FindManyResult<S extends AnyObject, T extends TableMetadata, C extends boolean> = PaginationUtils.Result<T['engine']> & (C extends true ? {
|
|
72
73
|
records: Record<S, T>[];
|
|
73
74
|
total: number;
|
|
74
75
|
} : {
|
|
@@ -78,34 +79,35 @@ export declare namespace Query {
|
|
|
78
79
|
export type Record<S extends AnyObject, T extends TableMetadata> = S extends never ? undefined : PartialObject<SelectFields<T['schema'], T['relations']>, S, false>;
|
|
79
80
|
export type SelectInput<T extends TableMetadata> = PartialProperties<SelectFields<T['schema'], T['relations']>>;
|
|
80
81
|
export type StrictSelectInput<S extends AnyObject, T extends TableMetadata> = StrictObject<S, FlatObject<SelectFields<T['schema'], T['relations']>>>;
|
|
81
|
-
export type InsertDataInput<T extends TableMetadata> = Omit<IsObjectEmpty<T['relations']['changes']> extends true ? T['schema'] : T['schema'] & T['relations']['changes'],
|
|
82
|
-
export type UpdateDataInput<T extends TableMetadata> = AtomicDataInput<Omit<IsObjectEmpty<T['relations']['changes']> extends true ? T['schema'] : T['schema'] & FlatObject<T['relations']['changes']>,
|
|
83
|
-
export type OrderInput<T extends TableMetadata
|
|
84
|
-
export type StrictIncludeInput<T extends TableMetadata> = IsObjectEmpty<T['relations']['filters']> extends true ? never : {
|
|
85
|
-
[P in keyof T['relations']['filters']]?:
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
82
|
+
export type InsertDataInput<T extends TableMetadata> = Omit<IsObjectEmpty<T['relations']['changes']> extends true ? T['schema'] : T['schema'] & T['relations']['changes'], T['relations']['indexes']>;
|
|
83
|
+
export type UpdateDataInput<T extends TableMetadata> = AtomicDataInput<Omit<IsObjectEmpty<T['relations']['changes']> extends true ? T['schema'] : T['schema'] & FlatObject<T['relations']['changes']>, T['relations']['indexes']>>;
|
|
84
|
+
export type OrderInput<T extends TableMetadata> = OrderUtils.Input<T>;
|
|
85
|
+
export type StrictIncludeInput<S extends AnyObject, T extends TableMetadata> = IsObjectEmpty<T['relations']['filters']> extends true ? never : {
|
|
86
|
+
[P in keyof T['relations']['filters']]?: P extends keyof S ? StrictIncludeRelation<T['relations']['filters'][P], T['engine']> : never;
|
|
87
|
+
};
|
|
88
|
+
export type StrictIncludeOrder<V extends AnyObject> = OrderUtils.AnyInput<V>;
|
|
89
|
+
export type StrictIncludeRelation<V extends AnyObject, E extends DatabaseEngine> = PaginationUtils.Range<E> & {
|
|
90
|
+
where?: WhereRelationField<V, E>;
|
|
91
|
+
order?: StrictIncludeOrder<V>;
|
|
89
92
|
};
|
|
90
93
|
export type WhereInput<T extends TableMetadata, I extends boolean = false> = WhereInputFilters<T, I extends true ? T['indexes'] : {}> & {
|
|
91
94
|
NOT?: WhereInput<T>;
|
|
92
95
|
AND?: WhereInput<T>[];
|
|
93
96
|
OR?: WhereInput<T>[];
|
|
94
97
|
};
|
|
95
|
-
type IndexFields<R extends RelationMetadata> = string extends R['indexes'] ? never : R['indexes'];
|
|
96
98
|
type SelectFields<T extends Database.Schema, R extends RelationMetadata> = IsObjectEmpty<R['selects']> extends true ? T : T & R['selects'];
|
|
97
|
-
type WhereOperations<V,
|
|
98
|
-
type WhereField<V,
|
|
99
|
-
type WhereObjectField<V extends AnyObject,
|
|
100
|
-
[P in keyof V]?: WhereField<V[P],
|
|
99
|
+
type WhereOperations<V, E extends DatabaseEngine> = WhereNegate<V> | WhereEqual<V> | WhereGreaterThan<V> | WhereGreaterThanOrEqual<V> | WhereLessThan<V> | WhereLessThanOrEqual<V> | WhereIn<V> | WhereBetween<V> | WhereIsMissing | WhereIsNull | WhereStartsWith<E> | WhereContains<V, E>;
|
|
100
|
+
type WhereField<V, E extends DatabaseEngine> = IsObject<V> extends false ? V | WhereOperations<V, E> : IsNullable<V> extends true ? null | WhereObjectField<NonNullable<V>, E> : WhereObjectField<NonNullable<V>, E>;
|
|
101
|
+
type WhereObjectField<V extends AnyObject, E extends DatabaseEngine> = {
|
|
102
|
+
[P in keyof V]?: WhereField<V[P], E>;
|
|
101
103
|
};
|
|
102
|
-
type WhereRelationField<V extends AnyObject,
|
|
103
|
-
NOT?: WhereRelationField<V,
|
|
104
|
-
AND?: WhereRelationField<V,
|
|
105
|
-
OR?: WhereRelationField<V,
|
|
104
|
+
type WhereRelationField<V extends AnyObject, E extends DatabaseEngine> = WhereObjectField<V, E> & {
|
|
105
|
+
NOT?: WhereRelationField<V, E>;
|
|
106
|
+
AND?: WhereRelationField<V, E>[];
|
|
107
|
+
OR?: WhereRelationField<V, E>[];
|
|
106
108
|
};
|
|
107
|
-
type WhereRelationFilters<V extends AnyObject,
|
|
108
|
-
[P in keyof V]?: IsObject<V[P]> extends true ? IsObjectEmpty<V[P]> extends false ? null | WhereRelationField<V[P],
|
|
109
|
+
type WhereRelationFilters<V extends AnyObject, E extends DatabaseEngine> = {
|
|
110
|
+
[P in keyof V]?: IsObject<V[P]> extends true ? IsObjectEmpty<V[P]> extends false ? null | WhereRelationField<V[P], E> : null | {} : never;
|
|
109
111
|
};
|
|
110
112
|
type WhereIndexFields<I extends Database.Indexes> = PrimaryIndexes<I> & UniqueIndexes<I>;
|
|
111
113
|
type WhereRequiredFilters<V extends AnyObject, I extends Database.Indexes> = {
|
|
@@ -114,13 +116,13 @@ export declare namespace Query {
|
|
|
114
116
|
};
|
|
115
117
|
}[keyof WhereIndexFields<I>];
|
|
116
118
|
type WhereOptionalFilters<V extends AnyObject, T extends TableMetadata, I extends Database.Indexes> = {
|
|
117
|
-
[P in Exclude<keyof V, keyof WhereIndexFields<I>>]?: WhereField<V[P], T>;
|
|
119
|
+
[P in Exclude<keyof V, keyof WhereIndexFields<I>>]?: WhereField<V[P], T['engine']>;
|
|
118
120
|
};
|
|
119
|
-
type WhereCommonFilters<V extends AnyObject, T extends TableMetadata, I extends Database.Indexes> = IsObjectEmpty<I> extends true ? WhereObjectField<V, T> : WhereRequiredFilters<V, I> & WhereOptionalFilters<V, T, I>;
|
|
120
|
-
type WhereInputFilters<T extends TableMetadata, I extends Database.Indexes> = WhereCommonFilters<T['schema'], T, I> & WhereRelationFilters<T['relations']['filters'], T>;
|
|
121
|
-
export type WhereOperators = keyof (WhereNegate<any
|
|
122
|
-
type WhereNegate<V
|
|
123
|
-
not: V
|
|
121
|
+
type WhereCommonFilters<V extends AnyObject, T extends TableMetadata, I extends Database.Indexes> = IsObjectEmpty<I> extends true ? WhereObjectField<V, T['engine']> : WhereRequiredFilters<V, I> & WhereOptionalFilters<V, T, I>;
|
|
122
|
+
type WhereInputFilters<T extends TableMetadata, I extends Database.Indexes> = WhereCommonFilters<T['schema'], T, I> & WhereRelationFilters<T['relations']['filters'], T['engine']>;
|
|
123
|
+
export type WhereOperators = keyof (WhereNegate<any> & WhereEqual<any> & WhereGreaterThan<any> & WhereGreaterThanOrEqual<any> & WhereLessThan<any> & WhereLessThanOrEqual<any> & WhereIn<any> & WhereBetween<any> & WhereIsMissing & WhereIsNull & WhereStartsWith<never> & WhereContains<any, never>);
|
|
124
|
+
type WhereNegate<V> = {
|
|
125
|
+
not: V;
|
|
124
126
|
};
|
|
125
127
|
type WhereEqual<V> = {
|
|
126
128
|
equal: V;
|
|
@@ -149,10 +151,10 @@ export declare namespace Query {
|
|
|
149
151
|
type WhereIsNull = {
|
|
150
152
|
isNull: boolean;
|
|
151
153
|
};
|
|
152
|
-
type WhereStartsWith<
|
|
154
|
+
type WhereStartsWith<E extends DatabaseEngine> = InsensitiveUtils.Input<E> & {
|
|
153
155
|
startsWith: string;
|
|
154
156
|
};
|
|
155
|
-
type WhereContains<V,
|
|
157
|
+
type WhereContains<V, E extends DatabaseEngine> = (V extends string ? InsensitiveUtils.Input<E> : {}) & {
|
|
156
158
|
contains: IsObject<V> extends true ? Partial<V> : V;
|
|
157
159
|
};
|
|
158
160
|
export type AtomicOperators = keyof (AtomicIncrement & AtomicDecrement & AtomicMultiply & AtomicDivide);
|
|
@@ -6,10 +6,10 @@ import type { TableSchemas } from './schemas.js';
|
|
|
6
6
|
* Internal relation type.
|
|
7
7
|
*/
|
|
8
8
|
export type RelationMetadata = {
|
|
9
|
-
indexes: string;
|
|
10
9
|
filters: Record<string, {}>;
|
|
11
10
|
selects: Record<string, {}>;
|
|
12
11
|
changes: Record<string, {}>;
|
|
12
|
+
indexes: string;
|
|
13
13
|
};
|
|
14
14
|
/**
|
|
15
15
|
* Given a relation source name `T`, it produces the source table name.
|
|
@@ -44,23 +44,23 @@ type TableRelation<T, S extends Record<string, Database.Schema>, I extends Recor
|
|
|
44
44
|
relations: infer R;
|
|
45
45
|
} ? N extends string ? R extends AnyObject ? {
|
|
46
46
|
[P in N]: {
|
|
47
|
-
indexes:
|
|
47
|
+
indexes: RelationIndexes<PropertyType<N, I>, R>;
|
|
48
48
|
filters: FilterableRelationSchemas<S, R>;
|
|
49
49
|
changes: RequiredRelationSchemas<PropertyType<N, S>, S, I, R, true> & OptionalRelationSchemas<PropertyType<N, S>, S, I, R, true>;
|
|
50
50
|
selects: RequiredRelationSchemas<PropertyType<N, S>, S, I, R, false> & OptionalRelationSchemas<PropertyType<N, S>, S, I, R, false>;
|
|
51
51
|
};
|
|
52
52
|
} : {} : {} : {};
|
|
53
53
|
/**
|
|
54
|
-
* Produce an object containing all
|
|
54
|
+
* Produce an object containing all relation indexes.
|
|
55
55
|
*/
|
|
56
|
-
type
|
|
57
|
-
[C in keyof R as
|
|
56
|
+
type RelationIndexes<I extends Database.Indexes, R extends AnyObject> = keyof {
|
|
57
|
+
[C in keyof R as RelationTargetColumn<C> extends keyof PrimaryIndexes<I> ? never : RelationTargetColumn<C>]: never;
|
|
58
58
|
};
|
|
59
59
|
/**
|
|
60
60
|
* Produce an object containing all filterable relation schemas.
|
|
61
61
|
*/
|
|
62
62
|
type FilterableRelationSchemas<S extends Record<string, Database.Schema>, R extends AnyObject> = {
|
|
63
|
-
[C in keyof R as RelationTargetAlias<C>]: Omit<PropertyType<RelationSourceTable<R[C]>, S>,
|
|
63
|
+
[C in keyof R as RelationTargetAlias<C>]: Omit<PropertyType<RelationSourceTable<R[C]>, S>, RelationSourceColumn<R[C]>>;
|
|
64
64
|
};
|
|
65
65
|
/**
|
|
66
66
|
* Produce an object containing only required relation schemas.
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { TypeClass } from '@ez4/reflection';
|
|
2
|
-
export declare const getLinkedService: (
|
|
2
|
+
export declare const getLinkedService: (declaration: TypeClass) => string | null;
|
package/dist/types/service.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import type { ServiceMetadata } from '@ez4/project/library';
|
|
2
|
+
import type { DatabaseScalability } from './scalability.js';
|
|
2
3
|
import type { DatabaseEngine } from './engine.js';
|
|
3
4
|
import type { DatabaseTable } from './table.js';
|
|
4
5
|
export declare const ServiceType = "@ez4/database";
|
|
5
6
|
export type DatabaseService = ServiceMetadata & {
|
|
6
7
|
type: typeof ServiceType;
|
|
8
|
+
scalability?: DatabaseScalability | null;
|
|
7
9
|
engine: DatabaseEngine;
|
|
8
10
|
tables: DatabaseTable[];
|
|
9
11
|
name: string;
|
package/dist/types/stream.d.ts
CHANGED
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.21.0",
|
|
5
5
|
"author": "Silas B.",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"type": "module",
|
|
@@ -42,10 +42,10 @@
|
|
|
42
42
|
"live:publish": "npm run test && npm publish --access public"
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@ez4/common": "^0.
|
|
46
|
-
"@ez4/project": "^0.
|
|
47
|
-
"@ez4/reflection": "^0.
|
|
48
|
-
"@ez4/schema": "^0.
|
|
49
|
-
"@ez4/utils": "^0.
|
|
45
|
+
"@ez4/common": "^0.21.0",
|
|
46
|
+
"@ez4/project": "^0.21.0",
|
|
47
|
+
"@ez4/reflection": "^0.21.0",
|
|
48
|
+
"@ez4/schema": "^0.21.0",
|
|
49
|
+
"@ez4/utils": "^0.21.0"
|
|
50
50
|
}
|
|
51
51
|
}
|