@ez4/database 0.24.0 → 0.25.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 +62 -61
- package/dist/library.mjs +48 -48
- package/package.json +7 -7
package/dist/library.cjs
CHANGED
|
@@ -1,47 +1,47 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var X=Object.defineProperty;var Xe=Object.getOwnPropertyDescriptor;var Ye=Object.getOwnPropertyNames;var Ze=Object.prototype.hasOwnProperty;var o=(e,r)=>X(e,"name",{value:r,configurable:!0});var Le=(e,r)=>{for(var t in r)X(e,t,{get:r[t],enumerable:!0})},et=(e,r,t,n)=>{if(r&&
|
|
2
2
|
typeof r=="object"||typeof r=="function")for(let a of Ye(r))!Ze.call(e,a)&&a!==t&&
|
|
3
|
-
|
|
4
|
-
IncompleteServiceError:()=>
|
|
5
|
-
IncorrectIndexesTypeError:()=>
|
|
6
|
-
IncorrectStreamTypeError:()=>
|
|
7
|
-
InvalidIndexesTypeError:()=>
|
|
8
|
-
InvalidRelationTableError:()=>
|
|
9
|
-
InvalidSchemaTypeError:()=>
|
|
3
|
+
X(e,a,{get:()=>r[a],enumerable:!(n=Xe(r,a))||n.enumerable});return e};var tt=e=>et(X({},"__esModule",{value:!0}),e);var bt={};Le(bt,{IncompleteEngineError:()=>H,IncompleteHandlerError:()=>W,IncompleteScalabilityError:()=>N,
|
|
4
|
+
IncompleteServiceError:()=>R,IncompleteStreamError:()=>_,IncompleteTableError:()=>F,
|
|
5
|
+
IncorrectIndexesTypeError:()=>V,IncorrectRelationsTypeError:()=>w,IncorrectSchemaTypeError:()=>B,
|
|
6
|
+
IncorrectStreamTypeError:()=>K,InvalidIndexReferenceError:()=>G,InvalidIndexTypeError:()=>$,
|
|
7
|
+
InvalidIndexesTypeError:()=>q,InvalidRelationAliasError:()=>U,InvalidRelationColumnError:()=>I,
|
|
8
|
+
InvalidRelationTableError:()=>z,InvalidRelationTargetError:()=>C,InvalidRelationsTypeError:()=>A,
|
|
9
|
+
InvalidSchemaTypeError:()=>Q,InvalidStreamTypeError:()=>J,ServiceType:()=>Y,getDatabaseServices:()=>le,
|
|
10
10
|
getDatabaseTable:()=>pe,getTableSchema:()=>ie,isDatabaseService:()=>rt,registerTriggers:()=>ut});
|
|
11
|
-
module.exports=tt(bt);var _e=require("@ez4/common/library"),Je=require("@ez4/schema/library"),Ke=require("@ez4/project/library");var u=require("@ez4/common/library"),Ge=require("@ez4/reflection");var
|
|
12
|
-
super("Incomplete database service",r,t)}};var g=require("@ez4/common/library");var
|
|
13
|
-
super("Invalid table relations type",void 0,"Database.Relations",r)}},
|
|
11
|
+
module.exports=tt(bt);var _e=require("@ez4/common/library"),Je=require("@ez4/schema/library"),Ke=require("@ez4/project/library");var u=require("@ez4/common/library"),Ge=require("@ez4/reflection");var Y="@ez4/database",rt=o(e=>e.type===Y,"isDatabaseService");var ce=require("@ez4/common/library");var R=class extends ce.IncompleteTypeError{static{o(this,"IncompleteServiceError")}constructor(r,t){
|
|
12
|
+
super("Incomplete database service",r,t)}};var g=require("@ez4/common/library");var A=class extends g.InvalidTypeError{static{o(this,"InvalidRelationsTypeError")}constructor(r){
|
|
13
|
+
super("Invalid table relations type",void 0,"Database.Relations",r)}},w=class extends g.IncorrectTypeError{constructor(t,n){
|
|
14
14
|
super("Incorrect table relations type",t,"Database.Relations",n);this.schemaType=
|
|
15
|
-
t}static{o(this,"IncorrectRelationsTypeError")}},
|
|
15
|
+
t}static{o(this,"IncorrectRelationsTypeError")}},C=class extends g.TypeError{constructor(t,n){
|
|
16
16
|
super(`Target ${t} must follow the pattern 'column@alias'.`,n);this.relationSource=
|
|
17
|
-
t}static{o(this,"InvalidRelationTargetError")}},
|
|
17
|
+
t}static{o(this,"InvalidRelationTargetError")}},z=class extends g.TypeError{constructor(t,n){
|
|
18
18
|
super(`Relation table ${t} don't exists.`,n);this.relationTable=t}static{o(this,
|
|
19
19
|
"InvalidRelationTableError")}},I=class extends g.TypeError{constructor(t,n){super(
|
|
20
20
|
`Relation column ${t} don't exists.`,n);this.relationColumn=t}static{o(this,"Inv\
|
|
21
|
-
alidRelationColumnError")}},
|
|
21
|
+
alidRelationColumnError")}},U=class extends g.TypeError{constructor(t,n){super(`\
|
|
22
22
|
Relation alias ${t} can't override table columns.`,n);this.relationAlias=t}static{
|
|
23
|
-
o(this,"InvalidRelationAliasError")}};var T=require("@ez4/common/library"),S=require("@ez4/reflection"),
|
|
24
|
-
rror")}constructor(r,t){super("Incomplete database scalability",r,t)}};var b=require("@ez4/common/library"),
|
|
25
|
-
e"),"isDatabaseService"),
|
|
23
|
+
o(this,"InvalidRelationAliasError")}};var T=require("@ez4/common/library"),S=require("@ez4/reflection"),te=require("@ez4/utils");var de=require("@ez4/common/library");var N=class extends de.IncompleteTypeError{static{o(this,"IncompleteScalabilityE\
|
|
24
|
+
rror")}constructor(r,t){super("Incomplete database scalability",r,t)}};var b=require("@ez4/common/library"),Z=require("@ez4/reflection");var L=o(e=>(0,b.isClassDeclaration)(e)&&(0,b.hasHeritageType)(e,"Database.Servic\
|
|
25
|
+
e"),"isDatabaseService"),ee=o(e=>(0,b.isModelDeclaration)(e)&&(0,b.hasHeritageType)(
|
|
26
26
|
e,"Database.Engine"),"isDatabaseEngine"),ue=o(e=>(0,b.isModelDeclaration)(e)&&(0,b.hasHeritageType)(
|
|
27
|
-
e,"Database.Table"),"isDatabaseTable"),be=o(e=>(0,
|
|
27
|
+
e,"Database.Table"),"isDatabaseTable"),be=o(e=>(0,Z.isTypeCallback)(e)||(0,Z.isTypeFunction)(
|
|
28
28
|
e),"isStreamHandler"),Te=o(e=>(0,b.hasHeritageType)(e,"Database.Relations"),"isT\
|
|
29
29
|
ableRelations"),ye=o(e=>(0,b.hasHeritageType)(e,"Database.Indexes"),"isTableInde\
|
|
30
30
|
xes"),fe=o(e=>(0,b.hasHeritageType)(e,"Database.Schema"),"isTableSchema"),xe=o(e=>(0,b.hasHeritageType)(
|
|
31
31
|
e,"Database.Stream"),"isTableStream");var Ie=o((e,r,t,n)=>{if(!(0,S.isTypeReference)(e))return ge(e,r,n);let a=(0,T.getReferenceType)(
|
|
32
|
-
e,t);return a?ge(a,r,n):null},"getDatabaseScalability"),nt=o(e=>(0,
|
|
33
|
-
e.minCapacity)&&(0,
|
|
32
|
+
e,t);return a?ge(a,r,n):null},"getDatabaseScalability"),nt=o(e=>(0,te.isAnyNumber)(
|
|
33
|
+
e.minCapacity)&&(0,te.isAnyNumber)(e.maxCapacity),"isValidScalability"),ge=o((e,r,t)=>ee(
|
|
34
34
|
e)?Me(e,r,(0,T.getModelMembers)(e),t):(0,S.isTypeObject)(e)?Me(e,r,(0,T.getObjectMembers)(
|
|
35
35
|
e),t):null,"getTypeScalability"),Me=o((e,r,t,n)=>{let a={},s=new Set(["minCapaci\
|
|
36
36
|
ty","maxCapacity"]);for(let i of t)if(!(!(0,S.isModelProperty)(i)||i.inherited))
|
|
37
37
|
switch(i.name){default:n.push(new T.InvalidServicePropertyError(r.name,i.name,e.
|
|
38
38
|
file));break;case"minCapacity":case"maxCapacity":let p=(0,T.getPropertyNumber)(i);
|
|
39
|
-
(0,
|
|
40
|
-
new
|
|
39
|
+
(0,te.isAnyNumber)(p)&&(a[i.name]=p,s.delete(i.name));break}return nt(a)?a:(n.push(
|
|
40
|
+
new N([...s],e.file)),null)},"getTypeFromMembers");var D=require("@ez4/reflection"),c=require("@ez4/common/library");var Se=require("@ez4/common/library");var H=class extends Se.IncompleteTypeError{static{o(this,"IncompleteEngineError")}constructor(r,t){
|
|
41
41
|
super("Incomplete database engine",r,t)}};var ve=o((e,r,t,n)=>{if(!(0,D.isTypeReference)(e))return De(e,r,n);let a=(0,c.getReferenceType)(
|
|
42
42
|
e,t);return a?De(a,r,n):null},"getDatabaseEngine"),at=o(e=>!!e.name&&!!e.parametersMode&&
|
|
43
43
|
!!e.transactionMode&&!!e.insensitiveMode&&!!e.paginationMode&&!!e.orderMode,"isV\
|
|
44
|
-
alidEngine"),De=o((e,r,t)=>
|
|
44
|
+
alidEngine"),De=o((e,r,t)=>ee(e)?he(e,r,(0,c.getModelMembers)(e),t):(0,D.isTypeObject)(
|
|
45
45
|
e)?he(e,r,(0,c.getObjectMembers)(e),t):null,"getTypeEngine"),he=o((e,r,t,n)=>{let a={},
|
|
46
46
|
s=new Set(["name","parametersMode","transactionMode","insensitiveMode","paginati\
|
|
47
47
|
onMode","orderMode"]);for(let i of t)if(!(!(0,D.isModelProperty)(i)||i.inherited))
|
|
@@ -53,92 +53,93 @@ i,["static","interactive"]))&&s.delete(i.name);break;case"insensitiveMode":(a.in
|
|
|
53
53
|
(0,c.getPropertyStringIn)(i,["unsupported","enabled"]))&&s.delete(i.name);break;case"\
|
|
54
54
|
paginationMode":(a.paginationMode=(0,c.getPropertyStringIn)(i,["cursor","offset"]))&&
|
|
55
55
|
s.delete(i.name);break;case"orderMode":(a.orderMode=(0,c.getPropertyStringIn)(i,
|
|
56
|
-
["any","index"]))&&s.delete(i.name);break}return at(a)?a:(n.push(new
|
|
57
|
-
file)),null)},"getTypeFromMembers");var x=require("@ez4/common/library"),
|
|
58
|
-
super("Incomplete database table",r,t)}};var M=require("@ez4/common/library");var
|
|
59
|
-
super("Invalid table indexes type",void 0,"Database.Indexes",r)}},
|
|
56
|
+
["any","index"]))&&s.delete(i.name);break}return at(a)?a:(n.push(new H([...s],e.
|
|
57
|
+
file)),null)},"getTypeFromMembers");var x=require("@ez4/common/library"),O=require("@ez4/reflection");var Ee=require("@ez4/common/library");var F=class extends Ee.IncompleteTypeError{static{o(this,"IncompleteTableError")}constructor(r,t){
|
|
58
|
+
super("Incomplete database table",r,t)}};var M=require("@ez4/common/library");var q=class extends M.InvalidTypeError{static{o(this,"InvalidIndexesTypeError")}constructor(r){
|
|
59
|
+
super("Invalid table indexes type",void 0,"Database.Indexes",r)}},V=class extends M.IncorrectTypeError{constructor(t,n){
|
|
60
60
|
super("Incorrect table indexes type",t,"Database.Indexes",n);this.schemaType=t}static{
|
|
61
|
-
o(this,"IncorrectIndexesTypeError")}}
|
|
61
|
+
o(this,"IncorrectIndexesTypeError")}},$=class extends M.TypeError{constructor(t,n){
|
|
62
62
|
super(`Invalid index type, ${t} must follow one of the Index options.`,n);this.indexName=
|
|
63
|
-
t}static{o(this,"InvalidIndexTypeError")}}
|
|
63
|
+
t}static{o(this,"InvalidIndexTypeError")}},G=class extends M.TypeError{constructor(t,n){
|
|
64
64
|
super(`Invalid index reference, ${t} must be valid column.`,n);this.indexName=t}static{
|
|
65
65
|
o(this,"InvalidIndexReferenceError")}};var y=require("@ez4/common/library"),h=require("@ez4/reflection");var Oe=o((e,r,t,n)=>{if(!(0,h.isTypeReference)(e))return je(e,r,n);let a=(0,y.getReferenceType)(
|
|
66
66
|
e,t);return a?je(a,r,n):null},"getTableRelations"),je=o((e,r,t)=>(0,h.isTypeObject)(
|
|
67
67
|
e)?Pe(e,(0,y.getObjectMembers)(e),t):(0,y.isModelDeclaration)(e)?Te(e)?Pe(e,(0,y.getModelMembers)(
|
|
68
|
-
e),t):(t.push(new
|
|
68
|
+
e),t):(t.push(new w(e.name,e.file)),null):(t.push(new A(r.file)),null),"getTypeR\
|
|
69
69
|
elations"),Pe=o((e,r,t)=>{let n=[];for(let a of r){if(!(0,h.isModelProperty)(a)||
|
|
70
70
|
a.inherited)continue;let s=(0,y.getPropertyString)(a),i=a.name;if(!s)return t.push(
|
|
71
|
-
new
|
|
72
|
-
sourceColumn:
|
|
71
|
+
new C(i,e.file)),null;let[p,l]=i.split("@",2),[m,k]=s.split(":",2);n.push({sourceTable:m,
|
|
72
|
+
sourceColumn:k,targetColumn:p,targetAlias:l})}return n},"getTypeFromMembers");var f=require("@ez4/common/library"),v=require("@ez4/reflection");var Ae=o((e,r,t,n)=>{if(!(0,v.isTypeReference)(e))return ke(e,r,n);let a=(0,f.getReferenceType)(
|
|
73
73
|
e,t);return a?ke(a,r,n):null},"getTableIndexes"),ke=o((e,r,t)=>(0,v.isTypeObject)(
|
|
74
74
|
e)?Re(e,(0,f.getObjectMembers)(e),t):(0,f.isModelDeclaration)(e)?ye(e)?Re(e,(0,f.getModelMembers)(
|
|
75
|
-
e),t):(t.push(new
|
|
75
|
+
e),t):(t.push(new V(e.name,e.file)),null):(t.push(new q(r.file)),null),"getTypeI\
|
|
76
76
|
ndexes"),Re=o((e,r,t)=>{let n=[];for(let a of r){if(!(0,v.isModelProperty)(a)||a.
|
|
77
77
|
inherited)continue;let s=a.name,i=(0,f.getPropertyString)(a);switch(i){case"prim\
|
|
78
78
|
ary":case"secondary":case"unique":case"ttl":n.push({name:s,columns:s.split(":"),
|
|
79
|
-
type:i});break;default:return t.push(new
|
|
80
|
-
omMembers");var
|
|
81
|
-
super("Invalid table schema type",void 0,"Database.Schema",r)}},
|
|
79
|
+
type:i});break;default:return t.push(new $(s,e.file)),null}}return n},"getTypeFr\
|
|
80
|
+
omMembers");var E=require("@ez4/schema/library"),ne=require("@ez4/common/library"),ae=require("@ez4/reflection");var re=require("@ez4/common/library");var Q=class extends re.InvalidTypeError{static{o(this,"InvalidSchemaTypeError")}constructor(r){
|
|
81
|
+
super("Invalid table schema type",void 0,"Database.Schema",r)}},B=class extends re.IncorrectTypeError{constructor(t,n){
|
|
82
82
|
super("Incorrect table schema type",t,"Database.Schema",n);this.schemaType=t}static{
|
|
83
|
-
o(this,"IncorrectSchemaTypeError")}};var ie=o((e,r,t,n)=>{if(!(0,ae.isTypeReference)(e))return we(e,r,t,n);let a=(0,
|
|
83
|
+
o(this,"IncorrectSchemaTypeError")}};var ie=o((e,r,t,n)=>{if(!(0,ae.isTypeReference)(e))return we(e,r,t,n);let a=(0,ne.getReferenceType)(
|
|
84
84
|
e,t);return a?we(a,r,t,n):null},"getTableSchema"),we=o((e,r,t,n)=>(0,ae.isTypeObject)(
|
|
85
|
-
e)?Ce(e,t):(0,
|
|
86
|
-
null):(n.push(new
|
|
87
|
-
e,r);return t&&(0,
|
|
88
|
-
|
|
85
|
+
e)?Ce(e,t):(0,ne.isModelDeclaration)(e)?fe(e)?Ce(e,t):(n.push(new B(e.name,e.file)),
|
|
86
|
+
null):(n.push(new Q(r.file)),null),"getTypeSchema"),Ce=o((e,r)=>{let t=(0,E.getObjectSchema)(
|
|
87
|
+
e,r,(0,E.createSchemaContext)({nullish:!0}));return t&&(0,E.isObjectSchema)(t)?t:
|
|
88
|
+
null},"getSchema");var d=require("@ez4/common/library"),P=require("@ez4/reflection");var j=require("@ez4/common/library");var _=class extends j.IncompleteTypeError{static{o(this,"IncompleteStreamError")}constructor(r,t){
|
|
89
|
+
super("Incomplete table stream",r,t)}},J=class extends j.InvalidTypeError{static{
|
|
89
90
|
o(this,"InvalidStreamTypeError")}constructor(r){super("Invalid table stream type",
|
|
90
|
-
void 0,"Database.Stream",r)}},
|
|
91
|
+
void 0,"Database.Stream",r)}},K=class extends j.IncorrectTypeError{constructor(t,n){
|
|
91
92
|
super("Incorrect table stream type",t,"Database.Stream",n);this.streamType=t}static{
|
|
92
|
-
o(this,"IncorrectStreamTypeError")}};var ze=require("@ez4/common/library");var
|
|
93
|
+
o(this,"IncorrectStreamTypeError")}};var ze=require("@ez4/common/library");var W=class extends ze.IncompleteTypeError{static{o(this,"IncompleteHandlerError")}constructor(r,t){
|
|
93
94
|
super("Incomplete stream handler",r,t)}};var Ue=o((e,r,t)=>{if(!be(e))return null;let{description:n,module:a}=e,s={...n&&
|
|
94
95
|
{description:n},...a&&{module:a}},i=new Set(["name","file","change"]);return(s.name=
|
|
95
96
|
e.name)&&i.delete("name"),(s.file=e.file)&&i.delete("file"),e.parameters&&i.delete(
|
|
96
|
-
"change"),i.size===0&&ot(s)?s:(t.push(new
|
|
97
|
-
dler"),ot=o(e=>!!e.name&&!!e.file,"isValidHandler");var Fe=o((e,r,t,n)=>{if(!(0,
|
|
97
|
+
"change"),i.size===0&&ot(s)?s:(t.push(new W([...i],e.file)),null)},"getStreamHan\
|
|
98
|
+
dler"),ot=o(e=>!!e.name&&!!e.file,"isValidHandler");var Fe=o((e,r,t,n)=>{if(!(0,P.isTypeReference)(e))return Ne(e,r,t,n);let a=(0,d.getReferenceType)(
|
|
98
99
|
e,t);return a?Ne(a,r,t,n):null},"getTableStream"),st=o(e=>!!e.handler,"isValidSt\
|
|
99
|
-
ream"),Ne=o((e,r,t,n)=>(0,
|
|
100
|
+
ream"),Ne=o((e,r,t,n)=>(0,P.isTypeObject)(e)?He(e,r,(0,d.getObjectMembers)(e),t,
|
|
100
101
|
n):(0,d.isModelDeclaration)(e)?xe(e)?He(e,r,(0,d.getModelMembers)(e),t,n):(n.push(
|
|
101
|
-
new
|
|
102
|
-
let s={},i=new Set(["handler"]);for(let p of t)if(!(!(0,
|
|
102
|
+
new K(e.name,e.file)),null):(n.push(new J(r.file)),null),"getTypeStream"),He=o((e,r,t,n,a)=>{
|
|
103
|
+
let s={},i=new Set(["handler"]);for(let p of t)if(!(!(0,P.isModelProperty)(p)||p.
|
|
103
104
|
inherited))switch(p.name){default:a.push(new d.InvalidServicePropertyError(r.name,
|
|
104
105
|
p.name,e.file));break;case"handler":s.handler=Ue(p.value,n,a);break;case"listene\
|
|
105
106
|
r":s.listener=(0,d.getServiceListener)(p.value,a);break;case"memory":case"logRet\
|
|
106
107
|
ention":case"timeout":s[p.name]=(0,d.getPropertyNumber)(p);break;case"variables":
|
|
107
|
-
s.variables=(0,d.getLinkedVariableList)(p,a);break}return st(s)?s:(a.push(new
|
|
108
|
-
[...i],e.file)),null)},"getTypeFromMembers");var pe=o((e,r,t,n)=>{if(!(0,
|
|
108
|
+
s.variables=(0,d.getLinkedVariableList)(p,a);break}return st(s)?s:(a.push(new _(
|
|
109
|
+
[...i],e.file)),null)},"getTypeFromMembers");var pe=o((e,r,t,n)=>{if(!(0,O.isTypeReference)(e))return qe(e,r,t,n);let a=(0,x.getReferenceType)(
|
|
109
110
|
e,t);return a?qe(a,r,t,n):null},"getDatabaseTable"),it=o(e=>!!e.name&&!!e.schema&&
|
|
110
111
|
!!e.indexes,"isValidTable"),qe=o((e,r,t,n)=>ue(e)?Ve(e,r,(0,x.getModelMembers)(e),
|
|
111
|
-
t,n):(0,
|
|
112
|
+
t,n):(0,O.isTypeObject)(e)?Ve(e,r,(0,x.getObjectMembers)(e),t,n):null,"getTypeTa\
|
|
112
113
|
ble"),Ve=o((e,r,t,n,a)=>{let s={},i=new Set(["name","schema","indexes"]);for(let l of t)
|
|
113
|
-
if(!(!(0,
|
|
114
|
+
if(!(!(0,O.isModelProperty)(l)||l.inherited))switch(l.name){default:a.push(new x.InvalidServicePropertyError(
|
|
114
115
|
r.name,l.name,e.file));break;case"name":(s.name=(0,x.getPropertyString)(l))&&i.delete(
|
|
115
116
|
l.name);break;case"schema":(s.schema=ie(l.value,e,n,a))&&i.delete(l.name);break;case"\
|
|
116
117
|
indexes":(s.indexes=Ae(l.value,e,n,a))&&i.delete(l.name);break;case"relations":s.
|
|
117
118
|
relations=Oe(l.value,e,n,a);break;case"stream":s.stream=Fe(l.value,r,n,a);break}
|
|
118
|
-
if(!it(s))return a.push(new
|
|
119
|
+
if(!it(s))return a.push(new F([...i],e.file)),null;let p=pt(e,s.indexes,s.schema);
|
|
119
120
|
return p.length?(a.push(...p),null):s},"getTypeFromMembers"),pt=o((e,r,t)=>{let n=t.
|
|
120
|
-
properties,a=[];for(let{name:s,columns:i}of r)i.some(l=>!n[l])&&a.push(new
|
|
121
|
-
file));return a},"validateIndexes");var le=o(e=>{let r={},t=[];for(let n in e){let a=e[n];if(!
|
|
122
|
-
a))continue;let s={type:
|
|
121
|
+
properties,a=[];for(let{name:s,columns:i}of r)i.some(l=>!n[l])&&a.push(new G(s,e.
|
|
122
|
+
file));return a},"validateIndexes");var le=o(e=>{let r={},t=[];for(let n in e){let a=e[n];if(!L(a)||(0,u.isExternalDeclaration)(
|
|
123
|
+
a))continue;let s={type:Y,extras:{}},i=new Set(["engine","tables"]),p=a.file;s.name=
|
|
123
124
|
a.name;for(let m of(0,u.getModelMembers)(a))if(!(!(0,Ge.isModelProperty)(m)||m.inherited))
|
|
124
125
|
switch(m.name){default:t.push(new u.InvalidServicePropertyError(s.name,m.name,p));
|
|
125
126
|
break;case"client":break;case"scalability":(s.scalability=Ie(m.value,a,e,t))&&i.
|
|
126
127
|
delete(m.name);break;case"engine":(s.engine=ve(m.value,a,e,t))&&i.delete(m.name);
|
|
127
128
|
break;case"tables":(s.tables=mt(m,a,e,t))&&i.delete(m.name);break;case"variables":
|
|
128
129
|
s.variables=(0,u.getLinkedVariableList)(m,t);break;case"services":s.services=(0,u.getLinkedServiceList)(
|
|
129
|
-
m,e,t);break}if(!lt(s)){t.push(new
|
|
130
|
+
m,e,t);break}if(!lt(s)){t.push(new R([...i],p));continue}let l=ct(a,s.tables);if(l.
|
|
130
131
|
length){t.push(...l);continue}if(r[a.name]){t.push(new u.DuplicateServiceError(a.
|
|
131
132
|
name,p));continue}r[a.name]=s}return{services:r,errors:t}},"getDatabaseServices"),
|
|
132
133
|
lt=o(e=>!!e.name&&!!e.tables&&!!e.extras,"isValidService"),mt=o((e,r,t,n)=>{let a=(0,u.getPropertyTuple)(
|
|
133
134
|
e)??[],s=[];for(let i of a){let p=pe(i,r,t,n);p&&s.push(p)}return s},"getAllTabl\
|
|
134
135
|
es"),ct=o((e,r)=>{let t=dt(r),n=[];for(let{relations:a,schema:s,indexes:i}of r){
|
|
135
|
-
if(!a)continue;let p=s.properties;for(let l of a){let{sourceTable:m,sourceColumn:
|
|
136
|
+
if(!a)continue;let p=s.properties;for(let l of a){let{sourceTable:m,sourceColumn:k,
|
|
136
137
|
targetColumn:oe,targetAlias:me}=l;p[oe]||n.push(new I(oe,e.file)),p[me]&&n.push(
|
|
137
|
-
new
|
|
138
|
-
!se[
|
|
138
|
+
new U(me,e.file));let se=t[m]?.schema.properties;se||n.push(new z(m,e.file)),se&&
|
|
139
|
+
!se[k]&&n.push(new I(k,e.file));let We=t[m]?.indexes??[];l.sourceIndex=$e(We,k),
|
|
139
140
|
l.targetIndex=$e(i,oe)}}return n},"validateRelations"),$e=o((e,r)=>e.find(({name:t})=>t===
|
|
140
141
|
r)?.type,"getIndexType"),dt=o(e=>e.reduce((r,t)=>({...r,[t.name]:t}),{}),"getTab\
|
|
141
|
-
leMap");var Qe=o(e=>
|
|
142
|
+
leMap");var Qe=o(e=>L(e)?e.name:null,"getLinkedService");var Be=!1,ut=o(()=>{Be||((0,_e.registerTriggers)(),(0,Je.registerTriggers)(),(0,Ke.createTrigger)(
|
|
142
143
|
"@ez4/database",{"metadata:getServices":le,"metadata:getLinkedService":Qe}),Be=!0)},
|
|
143
144
|
"registerTriggers");0&&(module.exports={IncompleteEngineError,IncompleteHandlerError,IncompleteScalabilityError,
|
|
144
145
|
IncompleteServiceError,IncompleteStreamError,IncompleteTableError,IncorrectIndexesTypeError,
|
package/dist/library.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
var De=Object.defineProperty;var n=(e,r)=>De(e,"name",{value:r,configurable:!0});import{registerTriggers as
|
|
2
|
-
import{createTrigger as
|
|
3
|
-
getLinkedServiceList as
|
|
4
|
-
import{isModelProperty as
|
|
1
|
+
var De=Object.defineProperty;var n=(e,r)=>De(e,"name",{value:r,configurable:!0});import{registerTriggers as lr}from"@ez4/common/library";import{registerTriggers as mr}from"@ez4/schema/library";
|
|
2
|
+
import{createTrigger as cr}from"@ez4/project/library";import{DuplicateServiceError as Yt,InvalidServicePropertyError as Zt,isExternalDeclaration as Lt,
|
|
3
|
+
getLinkedServiceList as er,getLinkedVariableList as tr,getPropertyTuple as rr,getModelMembers as nr}from"@ez4/common/library";
|
|
4
|
+
import{isModelProperty as ar}from"@ez4/reflection";var F="@ez4/database",ur=n(e=>e.type===F,"isDatabaseService");import{IncompleteTypeError as he}from"@ez4/common/library";var T=class extends he{static{n(this,"IncompleteServiceError")}constructor(r,t){
|
|
5
5
|
super("Incomplete database service",r,t)}};import{IncorrectTypeError as ve,InvalidTypeError as Ee,TypeError as I}from"@ez4/common/library";var y=class extends Ee{static{n(this,"InvalidRelationsTypeError")}constructor(r){
|
|
6
6
|
super("Invalid table relations type",void 0,"Database.Relations",r)}},f=class extends ve{constructor(t,a){
|
|
7
7
|
super("Incorrect table relations type",t,"Database.Relations",a);this.schemaType=
|
|
@@ -45,9 +45,9 @@ e"]))&&s.delete(i.name);break;case"insensitiveMode":(o.insensitiveMode=b(i,["uns
|
|
|
45
45
|
upported","enabled"]))&&s.delete(i.name);break;case"paginationMode":(o.paginationMode=
|
|
46
46
|
b(i,["cursor","offset"]))&&s.delete(i.name);break;case"orderMode":(o.orderMode=b(
|
|
47
47
|
i,["any","index"]))&&s.delete(i.name);break}return We(o)?o:(a.push(new v([...s],
|
|
48
|
-
e.file)),null)},"getTypeFromMembers");import{InvalidServicePropertyError as
|
|
49
|
-
getPropertyString as
|
|
50
|
-
isModelProperty as
|
|
48
|
+
e.file)),null)},"getTypeFromMembers");import{InvalidServicePropertyError as Vt,getModelMembers as $t,getObjectMembers as Gt,
|
|
49
|
+
getPropertyString as Qt,getReferenceType as Bt}from"@ez4/common/library";import{
|
|
50
|
+
isModelProperty as _t,isTypeObject as Jt,isTypeReference as Kt}from"@ez4/reflection";import{IncompleteTypeError as Xe}from"@ez4/common/library";var E=class extends Xe{static{n(this,"IncompleteTableError")}constructor(r,t){super(
|
|
51
51
|
"Incomplete database table",r,t)}};import{IncorrectTypeError as Ye,InvalidTypeError as Ze,TypeError as te}from"@ez4/common/library";var j=class extends Ze{static{n(this,"InvalidIndexesTypeError")}constructor(r){super(
|
|
52
52
|
"Invalid table indexes type",void 0,"Database.Indexes",r)}},P=class extends Ye{constructor(t,a){
|
|
53
53
|
super("Incorrect table indexes type",t,"Database.Indexes",a);this.schemaType=t}static{
|
|
@@ -71,66 +71,66 @@ t):(t.push(new P(e.name,e.file)),null):(t.push(new j(r.file)),null),"getTypeInde
|
|
|
71
71
|
xes"),se=n((e,r,t)=>{let a=[];for(let o of r){if(!dt(o)||o.inherited)continue;let s=o.
|
|
72
72
|
name,i=mt(o);switch(i){case"primary":case"secondary":case"unique":case"ttl":a.push(
|
|
73
73
|
{name:s,columns:s.split(":"),type:i});break;default:return t.push(new O(s,e.file)),
|
|
74
|
-
null}}return a},"getTypeFromMembers");import{
|
|
75
|
-
import{
|
|
76
|
-
isTypeObject as
|
|
74
|
+
null}}return a},"getTypeFromMembers");import{createSchemaContext as ft,getObjectSchema as xt,isObjectSchema as gt}from"@ez4/schema/library";
|
|
75
|
+
import{getReferenceType as Mt,isModelDeclaration as It}from"@ez4/common/library";
|
|
76
|
+
import{isTypeObject as St,isTypeReference as Dt}from"@ez4/reflection";import{IncorrectTypeError as Tt,InvalidTypeError as yt}from"@ez4/common/library";var R=class extends yt{static{n(this,"InvalidSchemaTypeError")}constructor(r){super(
|
|
77
77
|
"Invalid table schema type",void 0,"Database.Schema",r)}},A=class extends Tt{constructor(t,a){
|
|
78
78
|
super("Incorrect table schema type",t,"Database.Schema",a);this.schemaType=t}static{
|
|
79
|
-
n(this,"IncorrectSchemaTypeError")}};var me=n((e,r,t,a)=>{if(!
|
|
80
|
-
t,a):null},"getTableSchema"),pe=n((e,r,t,a)=>
|
|
79
|
+
n(this,"IncorrectSchemaTypeError")}};var me=n((e,r,t,a)=>{if(!Dt(e))return pe(e,r,t,a);let o=Mt(e,t);return o?pe(o,r,
|
|
80
|
+
t,a):null},"getTableSchema"),pe=n((e,r,t,a)=>St(e)?le(e,t):It(e)?J(e)?le(e,t):(a.
|
|
81
81
|
push(new A(e.name,e.file)),null):(a.push(new R(r.file)),null),"getTypeSchema"),le=n(
|
|
82
|
-
(e,r)=>{let t=
|
|
83
|
-
getModelMembers as
|
|
84
|
-
getReferenceType as
|
|
85
|
-
isTypeReference as
|
|
86
|
-
"Incomplete table stream",r,t)}},C=class extends
|
|
82
|
+
(e,r)=>{let t=xt(e,r,ft({nullish:!0}));return t&>(t)?t:null},"getSchema");import{InvalidServicePropertyError as Ot,isModelDeclaration as kt,getLinkedVariableList as Rt,
|
|
83
|
+
getModelMembers as At,getObjectMembers as wt,getPropertyNumber as Ct,getServiceListener as zt,
|
|
84
|
+
getReferenceType as Ut}from"@ez4/common/library";import{isModelProperty as Nt,isTypeObject as Ht,
|
|
85
|
+
isTypeReference as Ft}from"@ez4/reflection";import{IncompleteTypeError as ht,IncorrectTypeError as vt,InvalidTypeError as Et}from"@ez4/common/library";var w=class extends ht{static{n(this,"IncompleteStreamError")}constructor(r,t){super(
|
|
86
|
+
"Incomplete table stream",r,t)}},C=class extends Et{static{n(this,"InvalidStream\
|
|
87
87
|
TypeError")}constructor(r){super("Invalid table stream type",void 0,"Database.St\
|
|
88
|
-
ream",r)}},z=class extends
|
|
88
|
+
ream",r)}},z=class extends vt{constructor(t,a){super("Incorrect table stream typ\
|
|
89
89
|
e",t,"Database.Stream",a);this.streamType=t}static{n(this,"IncorrectStreamTypeEr\
|
|
90
|
-
ror")}};import{IncompleteTypeError as
|
|
90
|
+
ror")}};import{IncompleteTypeError as jt}from"@ez4/common/library";var U=class extends jt{static{n(this,"IncompleteHandlerError")}constructor(r,t){
|
|
91
91
|
super("Incomplete stream handler",r,t)}};var ce=n((e,r,t)=>{if(!Q(e))return null;let{description:a,module:o}=e,s={...a&&{
|
|
92
92
|
description:a},...o&&{module:o}},i=new Set(["name","file","change"]);return(s.name=
|
|
93
93
|
e.name)&&i.delete("name"),(s.file=e.file)&&i.delete("file"),e.parameters&&i.delete(
|
|
94
|
-
"change"),i.size===0&&
|
|
95
|
-
dler"),
|
|
96
|
-
t,a):null},"getTableStream"),
|
|
97
|
-
e)?ue(e,r,
|
|
94
|
+
"change"),i.size===0&&Pt(s)?s:(t.push(new U([...i],e.file)),null)},"getStreamHan\
|
|
95
|
+
dler"),Pt=n(e=>!!e.name&&!!e.file,"isValidHandler");var be=n((e,r,t,a)=>{if(!Ft(e))return de(e,r,t,a);let o=Ut(e,t);return o?de(o,r,
|
|
96
|
+
t,a):null},"getTableStream"),qt=n(e=>!!e.handler,"isValidStream"),de=n((e,r,t,a)=>Ht(
|
|
97
|
+
e)?ue(e,r,wt(e),t,a):kt(e)?K(e)?ue(e,r,At(e),t,a):(a.push(new z(e.name,e.file)),
|
|
98
98
|
null):(a.push(new C(r.file)),null),"getTypeStream"),ue=n((e,r,t,a,o)=>{let s={},
|
|
99
|
-
i=new Set(["handler"]);for(let p of t)if(!(!
|
|
100
|
-
o.push(new
|
|
101
|
-
o);break;case"listener":s.listener=
|
|
102
|
-
ntion":case"timeout":s[p.name]=
|
|
103
|
-
return
|
|
104
|
-
t,a):null},"getDatabaseTable"),
|
|
105
|
-
dTable"),Te=n((e,r,t,a)=>G(e)?ye(e,r
|
|
99
|
+
i=new Set(["handler"]);for(let p of t)if(!(!Nt(p)||p.inherited))switch(p.name){default:
|
|
100
|
+
o.push(new Ot(r.name,p.name,e.file));break;case"handler":s.handler=ce(p.value,a,
|
|
101
|
+
o);break;case"listener":s.listener=zt(p.value,o);break;case"memory":case"logRete\
|
|
102
|
+
ntion":case"timeout":s[p.name]=Ct(p);break;case"variables":s.variables=Rt(p,o);break}
|
|
103
|
+
return qt(s)?s:(o.push(new w([...i],e.file)),null)},"getTypeFromMembers");var fe=n((e,r,t,a)=>{if(!Kt(e))return Te(e,r,t,a);let o=Bt(e,t);return o?Te(o,r,
|
|
104
|
+
t,a):null},"getDatabaseTable"),Wt=n(e=>!!e.name&&!!e.schema&&!!e.indexes,"isVali\
|
|
105
|
+
dTable"),Te=n((e,r,t,a)=>G(e)?ye(e,r,$t(e),t,a):Jt(e)?ye(e,r,Gt(e),t,a):null,"ge\
|
|
106
106
|
tTypeTable"),ye=n((e,r,t,a,o)=>{let s={},i=new Set(["name","schema","indexes"]);
|
|
107
|
-
for(let l of t)if(!(!
|
|
108
|
-
name,l.name,e.file));break;case"name":(s.name=
|
|
107
|
+
for(let l of t)if(!(!_t(l)||l.inherited))switch(l.name){default:o.push(new Vt(r.
|
|
108
|
+
name,l.name,e.file));break;case"name":(s.name=Qt(l))&&i.delete(l.name);break;case"\
|
|
109
109
|
schema":(s.schema=me(l.value,e,a,o))&&i.delete(l.name);break;case"indexes":(s.indexes=
|
|
110
110
|
ie(l.value,e,a,o))&&i.delete(l.name);break;case"relations":s.relations=ae(l.value,
|
|
111
|
-
e,a,o);break;case"stream":s.stream=be(l.value,r,a,o);break}if(!
|
|
112
|
-
new E([...i],e.file)),null;let p=
|
|
113
|
-
...p),null):s},"getTypeFromMembers"),
|
|
111
|
+
e,a,o);break;case"stream":s.stream=be(l.value,r,a,o);break}if(!Wt(s))return o.push(
|
|
112
|
+
new E([...i],e.file)),null;let p=Xt(e,s.indexes,s.schema);return p.length?(o.push(
|
|
113
|
+
...p),null):s},"getTypeFromMembers"),Xt=n((e,r,t)=>{let a=t.properties,o=[];for(let{
|
|
114
114
|
name:s,columns:i}of r)i.some(l=>!a[l])&&o.push(new k(s,e.file));return o},"valid\
|
|
115
|
-
ateIndexes");var ge=n(e=>{let r={},t=[];for(let a in e){let o=e[a];if(!D(o)||
|
|
116
|
-
type:F,extras:{}},i=new Set(["engine","tables"]),p=o.file;s.name=o.name;for(let m of
|
|
117
|
-
o))if(!(!
|
|
115
|
+
ateIndexes");var ge=n(e=>{let r={},t=[];for(let a in e){let o=e[a];if(!D(o)||Lt(o))continue;let s={
|
|
116
|
+
type:F,extras:{}},i=new Set(["engine","tables"]),p=o.file;s.name=o.name;for(let m of nr(
|
|
117
|
+
o))if(!(!ar(m)||m.inherited))switch(m.name){default:t.push(new Zt(s.name,m.name,
|
|
118
118
|
p));break;case"client":break;case"scalability":(s.scalability=Y(m.value,o,e,t))&&
|
|
119
119
|
i.delete(m.name);break;case"engine":(s.engine=ee(m.value,o,e,t))&&i.delete(m.name);
|
|
120
|
-
break;case"tables":(s.tables=
|
|
121
|
-
s.variables=
|
|
122
|
-
push(new T([...i],p));continue}let l=
|
|
123
|
-
if(r[o.name]){t.push(new
|
|
124
|
-
"getDatabaseServices"),
|
|
125
|
-
|
|
126
|
-
p)}return s},"getAllTables"),
|
|
120
|
+
break;case"tables":(s.tables=sr(m,o,e,t))&&i.delete(m.name);break;case"variables":
|
|
121
|
+
s.variables=tr(m,t);break;case"services":s.services=er(m,e,t);break}if(!or(s)){t.
|
|
122
|
+
push(new T([...i],p));continue}let l=ir(o,s.tables);if(l.length){t.push(...l);continue}
|
|
123
|
+
if(r[o.name]){t.push(new Yt(o.name,p));continue}r[o.name]=s}return{services:r,errors:t}},
|
|
124
|
+
"getDatabaseServices"),or=n(e=>!!e.name&&!!e.tables&&!!e.extras,"isValidService"),
|
|
125
|
+
sr=n((e,r,t,a)=>{let o=rr(e)??[],s=[];for(let i of o){let p=fe(i,r,t,a);p&&s.push(
|
|
126
|
+
p)}return s},"getAllTables"),ir=n((e,r)=>{let t=pr(r),a=[];for(let{relations:o,schema:s,
|
|
127
127
|
indexes:i}of r){if(!o)continue;let p=s.properties;for(let l of o){let{sourceTable:m,
|
|
128
128
|
sourceColumn:d,targetColumn:N,targetAlias:V}=l;p[N]||a.push(new u(N,e.file)),p[V]&&
|
|
129
129
|
a.push(new M(V,e.file));let H=t[m]?.schema.properties;H||a.push(new g(m,e.file)),
|
|
130
130
|
H&&!H[d]&&a.push(new u(d,e.file));let Se=t[m]?.indexes??[];l.sourceIndex=xe(Se,d),
|
|
131
131
|
l.targetIndex=xe(i,N)}}return a},"validateRelations"),xe=n((e,r)=>e.find(({name:t})=>t===
|
|
132
|
-
r)?.type,"getIndexType"),
|
|
133
|
-
leMap");var Me=n(e=>D(e)?e.name:null,"getLinkedService");var Ie=!1,
|
|
132
|
+
r)?.type,"getIndexType"),pr=n(e=>e.reduce((r,t)=>({...r,[t.name]:t}),{}),"getTab\
|
|
133
|
+
leMap");var Me=n(e=>D(e)?e.name:null,"getLinkedService");var Ie=!1,Ra=n(()=>{Ie||(lr(),mr(),cr("@ez4/database",{"metadata:getServices":ge,
|
|
134
134
|
"metadata:getLinkedService":Me}),Ie=!0)},"registerTriggers");export{v as IncompleteEngineError,U as IncompleteHandlerError,S as IncompleteScalabilityError,
|
|
135
135
|
T as IncompleteServiceError,w as IncompleteStreamError,E as IncompleteTableError,
|
|
136
136
|
P as IncorrectIndexesTypeError,f as IncorrectRelationsTypeError,A as IncorrectSchemaTypeError,
|
|
@@ -138,5 +138,5 @@ z as IncorrectStreamTypeError,k as InvalidIndexReferenceError,O as InvalidIndexT
|
|
|
138
138
|
j as InvalidIndexesTypeError,M as InvalidRelationAliasError,u as InvalidRelationColumnError,
|
|
139
139
|
g as InvalidRelationTableError,x as InvalidRelationTargetError,y as InvalidRelationsTypeError,
|
|
140
140
|
R as InvalidSchemaTypeError,C as InvalidStreamTypeError,F as ServiceType,ge as getDatabaseServices,
|
|
141
|
-
fe as getDatabaseTable,me as getTableSchema,
|
|
141
|
+
fe as getDatabaseTable,me as getTableSchema,ur as isDatabaseService,Ra as registerTriggers};
|
|
142
142
|
//# sourceMappingURL=library.mjs.map
|
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.25.0",
|
|
5
5
|
"author": "Silas B.",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"type": "module",
|
|
@@ -40,13 +40,13 @@
|
|
|
40
40
|
"test:types": "npm run build && tsc -p tsconfig.test.json",
|
|
41
41
|
"local:publish": "npm run build && npm run clean:registry && npm publish --registry http://localhost:4873",
|
|
42
42
|
"clean:registry": "rm -rf ../../.registry/@ez4/database",
|
|
43
|
-
"live:publish": "npm
|
|
43
|
+
"live:publish": "npm publish --access public"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@ez4/common": "^0.
|
|
47
|
-
"@ez4/project": "^0.
|
|
48
|
-
"@ez4/reflection": "^0.
|
|
49
|
-
"@ez4/schema": "^0.
|
|
50
|
-
"@ez4/utils": "^0.
|
|
46
|
+
"@ez4/common": "^0.25.0",
|
|
47
|
+
"@ez4/project": "^0.25.0",
|
|
48
|
+
"@ez4/reflection": "^0.25.0",
|
|
49
|
+
"@ez4/schema": "^0.25.0",
|
|
50
|
+
"@ez4/utils": "^0.25.0"
|
|
51
51
|
}
|
|
52
52
|
}
|