@ez4/database 0.15.0 → 0.16.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 +94 -94
- package/dist/library.mjs +95 -91
- package/dist/metadata/stream.d.ts +2 -4
- package/dist/metadata/table.d.ts +2 -2
- package/package.json +7 -7
package/dist/library.cjs
CHANGED
|
@@ -1,99 +1,99 @@
|
|
|
1
|
-
"use strict";var
|
|
2
|
-
typeof t=="object"||typeof t=="function")for(let n of
|
|
3
|
-
|
|
4
|
-
IncompleteTableError:()=>k,IncorrectIndexesTypeError:()=>
|
|
1
|
+
"use strict";var Y=Object.defineProperty;var Ae=Object.getOwnPropertyDescriptor;var ze=Object.getOwnPropertyNames;var Ce=Object.prototype.hasOwnProperty;var Ne=(e,t)=>{for(var r in t)Y(e,r,{get:t[r],enumerable:!0})},He=(e,t,r,o)=>{if(t&&
|
|
2
|
+
typeof t=="object"||typeof t=="function")for(let n of ze(t))!Ce.call(e,n)&&n!==r&&
|
|
3
|
+
Y(e,n,{get:()=>t[n],enumerable:!(o=Ae(t,n))||o.enumerable});return e};var $e=e=>He(Y({},"__esModule",{value:!0}),e);var We={};Ne(We,{IncompleteHandlerError:()=>F,IncompleteServiceError:()=>w,IncompleteStreamError:()=>H,
|
|
4
|
+
IncompleteTableError:()=>k,IncorrectIndexesTypeError:()=>O,IncorrectRelationsTypeError:()=>D,
|
|
5
5
|
IncorrectSchemaTypeError:()=>N,IncorrectStreamTypeError:()=>q,InvalidIndexReferenceError:()=>z,
|
|
6
|
-
InvalidIndexTypeError:()=>
|
|
7
|
-
InvalidRelationColumnError:()=>
|
|
6
|
+
InvalidIndexTypeError:()=>A,InvalidIndexesTypeError:()=>R,InvalidRelationAliasError:()=>E,
|
|
7
|
+
InvalidRelationColumnError:()=>x,InvalidRelationTableError:()=>j,InvalidRelationTargetError:()=>P,
|
|
8
8
|
InvalidRelationsTypeError:()=>v,InvalidSchemaTypeError:()=>C,InvalidStreamTypeError:()=>$,
|
|
9
|
-
ServiceType:()=>U,getDatabaseServices:()=>
|
|
10
|
-
isDatabaseService:()=>
|
|
11
|
-
super("Invalid table relations type",void 0,"Database.Relations",t)}},D=class extends
|
|
12
|
-
super("Incorrect table relations type",r,"Database.Relations",
|
|
13
|
-
r}},P=class extends
|
|
14
|
-
the pattern 'column@alias'.`,
|
|
15
|
-
super(`Relation table ${r} don't exists.`,
|
|
16
|
-
super(`Relation column ${r} don't exists.`,
|
|
17
|
-
super(`Relation alias ${r} can't override table columns.`,
|
|
18
|
-
r}};var
|
|
19
|
-
super("Incomplete database service",t,r)}};var
|
|
20
|
-
e)&&(0,
|
|
21
|
-
(0,
|
|
22
|
-
e),
|
|
23
|
-
e,"Database.Indexes"),
|
|
24
|
-
e,"Database.Stream");var
|
|
25
|
-
super("Incomplete database table",t,r)}};var
|
|
26
|
-
super("Invalid table indexes type",void 0,"Database.Indexes",t)}},
|
|
27
|
-
super("Incorrect table indexes type",r,"Database.Indexes",
|
|
28
|
-
|
|
29
|
-
t follow one of the Index options.`,
|
|
30
|
-
super(`Invalid index reference, ${r} must be valid column.`,
|
|
31
|
-
return n?
|
|
32
|
-
e),r):(0,
|
|
33
|
-
new D(e.name,e.file)),null):(r.push(new v(t.file)),null),
|
|
34
|
-
if(!(0,
|
|
35
|
-
n);if(!
|
|
36
|
-
p
|
|
37
|
-
return
|
|
38
|
-
return n?
|
|
39
|
-
e),r):(0,
|
|
40
|
-
new
|
|
41
|
-
if(!(0,
|
|
42
|
-
n);switch(
|
|
43
|
-
columns:
|
|
44
|
-
return
|
|
45
|
-
super("Invalid table schema type",void 0,"Database.Schema",t)}},N=class extends B.IncorrectTypeError{constructor(r,
|
|
46
|
-
super("Incorrect table schema type",r,"Database.Schema",
|
|
47
|
-
return n?fe(n,t,r,
|
|
48
|
-
e)?
|
|
49
|
-
|
|
50
|
-
null};var
|
|
51
|
-
super("Incomplete table stream",t,r)}},$=class extends
|
|
52
|
-
super("Invalid table stream type",void 0,"Database.Stream",t)}},q=class extends
|
|
53
|
-
super("Incorrect table stream type",r,"Database.Stream",
|
|
54
|
-
super("Incomplete stream handler",t,r)}};var ge=(e,t,r)=>{if(!
|
|
55
|
-
return e.description&&(
|
|
56
|
-
ame"),(
|
|
57
|
-
0&&
|
|
58
|
-
return n?Se(n,t,r,
|
|
59
|
-
|
|
60
|
-
e),r,
|
|
61
|
-
let
|
|
62
|
-
inherited))switch(s.name){default:
|
|
63
|
-
name,s.name,e.file));break;case"
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
e),t,
|
|
70
|
-
let
|
|
71
|
-
i)||i.inherited))switch(i.name){default:
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
n
|
|
81
|
-
|
|
82
|
-
engine=(0,
|
|
83
|
-
|
|
84
|
-
p,r);break;case"services":
|
|
85
|
-
|
|
86
|
-
...i);continue}if(t[n.name]){r.push(new
|
|
87
|
-
continue}t[n.name]=
|
|
88
|
-
let
|
|
89
|
-
s)}return
|
|
90
|
-
if(!n)continue;let
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
push(new
|
|
94
|
-
|
|
95
|
-
...t,[r.name]:r}),{});var
|
|
96
|
-
"@ez4/database",{"metadata:getServices":
|
|
9
|
+
ServiceType:()=>U,getDatabaseServices:()=>ee,getDatabaseTable:()=>L,getTableSchema:()=>Z,
|
|
10
|
+
isDatabaseService:()=>qe,registerTriggers:()=>Qe});module.exports=$e(We);var we=require("@ez4/common/library"),ke=require("@ez4/schema/library"),Re=require("@ez4/project/library");var c=require("@ez4/common/library"),Pe=require("@ez4/reflection");var f=require("@ez4/common/library"),v=class extends f.InvalidTypeError{constructor(t){
|
|
11
|
+
super("Invalid table relations type",void 0,"Database.Relations",t)}},D=class extends f.IncorrectTypeError{constructor(r,o){
|
|
12
|
+
super("Incorrect table relations type",r,"Database.Relations",o);this.schemaType=
|
|
13
|
+
r}},P=class extends f.TypeError{constructor(r,o){super(`Target ${r} must follow \
|
|
14
|
+
the pattern 'column@alias'.`,o);this.relationSource=r}},j=class extends f.TypeError{constructor(r,o){
|
|
15
|
+
super(`Relation table ${r} don't exists.`,o);this.relationTable=r}},x=class extends f.TypeError{constructor(r,o){
|
|
16
|
+
super(`Relation column ${r} don't exists.`,o);this.relationColumn=r}},E=class extends f.TypeError{constructor(r,o){
|
|
17
|
+
super(`Relation alias ${r} can't override table columns.`,o);this.relationAlias=
|
|
18
|
+
r}};var te=require("@ez4/common/library"),w=class extends te.IncompleteTypeError{constructor(t,r){
|
|
19
|
+
super("Incomplete database service",t,r)}};var U="@ez4/database",qe=e=>e.type===U;var u=require("@ez4/common/library"),V=require("@ez4/reflection"),_=e=>(0,u.isClassDeclaration)(
|
|
20
|
+
e)&&(0,u.hasHeritageType)(e,"Database.Service"),oe=e=>(0,u.isModelDeclaration)(e)&&
|
|
21
|
+
(0,u.hasHeritageType)(e,"Database.Table"),ne=e=>(0,V.isTypeCallback)(e)||(0,V.isTypeFunction)(
|
|
22
|
+
e),ae=e=>(0,u.hasHeritageType)(e,"Database.Relations"),se=e=>(0,u.hasHeritageType)(
|
|
23
|
+
e,"Database.Indexes"),ie=e=>(0,u.hasHeritageType)(e,"Database.Schema"),le=e=>(0,u.hasHeritageType)(
|
|
24
|
+
e,"Database.Stream");var T=require("@ez4/common/library"),h=require("@ez4/reflection");var pe=require("@ez4/common/library"),k=class extends pe.IncompleteTypeError{constructor(t,r){
|
|
25
|
+
super("Incomplete database table",t,r)}};var y=require("@ez4/common/library"),R=class extends y.InvalidTypeError{constructor(t){
|
|
26
|
+
super("Invalid table indexes type",void 0,"Database.Indexes",t)}},O=class extends y.IncorrectTypeError{constructor(r,o){
|
|
27
|
+
super("Incorrect table indexes type",r,"Database.Indexes",o);this.schemaType=r}},
|
|
28
|
+
A=class extends y.TypeError{constructor(r,o){super(`Invalid index type, ${r} mus\
|
|
29
|
+
t follow one of the Index options.`,o);this.indexName=r}},z=class extends y.TypeError{constructor(r,o){
|
|
30
|
+
super(`Invalid index reference, ${r} must be valid column.`,o);this.indexName=r}};var d=require("@ez4/common/library"),g=require("@ez4/reflection");var ue=(e,t,r,o)=>{if(!(0,g.isTypeReference)(e))return me(e,t,o);let n=(0,d.getReferenceType)(
|
|
31
|
+
e,r);return n?me(n,t,o):null},me=(e,t,r)=>(0,g.isTypeObject)(e)?ce(e,(0,d.getObjectMembers)(
|
|
32
|
+
e),r):(0,d.isModelDeclaration)(e)?ae(e)?ce(e,(0,d.getModelMembers)(e),r):(r.push(
|
|
33
|
+
new D(e.name,e.file)),null):(r.push(new v(t.file)),null),ce=(e,t,r)=>{let o=[];for(let n of t){
|
|
34
|
+
if(!(0,g.isModelProperty)(n)||n.inherited)continue;let a=(0,d.getPropertyString)(
|
|
35
|
+
n);if(!a)return r.push(new P(n.name,e.file)),null;let[l,s]=n.name.split(":",2),[
|
|
36
|
+
i,p]=a.split("@",2);o.push({sourceTable:l,sourceColumn:s,targetColumn:i,targetAlias:p})}
|
|
37
|
+
return o};var b=require("@ez4/common/library"),S=require("@ez4/reflection");var Te=(e,t,r,o)=>{if(!(0,S.isTypeReference)(e))return de(e,t,o);let n=(0,b.getReferenceType)(
|
|
38
|
+
e,r);return n?de(n,t,o):null},de=(e,t,r)=>(0,S.isTypeObject)(e)?be(e,(0,b.getObjectMembers)(
|
|
39
|
+
e),r):(0,b.isModelDeclaration)(e)?se(e)?be(e,(0,b.getModelMembers)(e),r):(r.push(
|
|
40
|
+
new O(e.name,e.file)),null):(r.push(new R(t.file)),null),be=(e,t,r)=>{let o=[];for(let n of t){
|
|
41
|
+
if(!(0,S.isModelProperty)(n)||n.inherited)continue;let a=n.name,l=(0,b.getPropertyString)(
|
|
42
|
+
n);switch(l){case"primary":case"secondary":case"unique":case"ttl":o.push({name:a,
|
|
43
|
+
columns:a.split(":"),type:l});break;default:return r.push(new A(a,e.file)),null}}
|
|
44
|
+
return o};var G=require("@ez4/common/library"),J=require("@ez4/schema/library"),K=require("@ez4/reflection");var B=require("@ez4/common/library"),C=class extends B.InvalidTypeError{constructor(t){
|
|
45
|
+
super("Invalid table schema type",void 0,"Database.Schema",t)}},N=class extends B.IncorrectTypeError{constructor(r,o){
|
|
46
|
+
super("Incorrect table schema type",r,"Database.Schema",o);this.schemaType=r}};var Z=(e,t,r,o)=>{if(!(0,K.isTypeReference)(e))return fe(e,t,r,o);let n=(0,G.getReferenceType)(
|
|
47
|
+
e,r);return n?fe(n,t,r,o):null},fe=(e,t,r,o)=>(0,K.isTypeObject)(e)?ye(e,r):(0,G.isModelDeclaration)(
|
|
48
|
+
e)?ie(e)?ye(e,r):(o.push(new N(e.name,e.file)),null):(o.push(new C(t.file)),null),
|
|
49
|
+
ye=(e,t)=>{let r=(0,J.getObjectSchema)(e,t);return r&&(0,J.isObjectSchema)(r)?r:
|
|
50
|
+
null};var m=require("@ez4/common/library"),I=require("@ez4/reflection");var M=require("@ez4/common/library"),H=class extends M.IncompleteTypeError{constructor(t,r){
|
|
51
|
+
super("Incomplete table stream",t,r)}},$=class extends M.InvalidTypeError{constructor(t){
|
|
52
|
+
super("Invalid table stream type",void 0,"Database.Stream",t)}},q=class extends M.IncorrectTypeError{constructor(r,o){
|
|
53
|
+
super("Incorrect table stream type",r,"Database.Stream",o);this.streamType=r}};var xe=require("@ez4/common/library"),F=class extends xe.IncompleteTypeError{constructor(t,r){
|
|
54
|
+
super("Incomplete stream handler",t,r)}};var ge=(e,t,r)=>{if(!ne(e))return null;let o={},n=new Set(["name","file","change"]);
|
|
55
|
+
return e.description&&(o.description=e.description),(o.name=e.name)&&n.delete("n\
|
|
56
|
+
ame"),(o.file=e.file)&&n.delete("file"),e.parameters&&n.delete("change"),n.size===
|
|
57
|
+
0&&Fe(o)?o:(r.push(new F([...n],e.file)),null)},Fe=e=>!!e.name&&!!e.file;var Ie=(e,t,r,o)=>{if(!(0,I.isTypeReference)(e))return Se(e,t,r,o);let n=(0,m.getReferenceType)(
|
|
58
|
+
e,r);return n?Se(n,t,r,o):null},Ue=e=>!!e.handler,Se=(e,t,r,o)=>(0,I.isTypeObject)(
|
|
59
|
+
e)?Me(e,t,(0,m.getObjectMembers)(e),r,o):(0,m.isModelDeclaration)(e)?le(e)?Me(e,
|
|
60
|
+
t,(0,m.getModelMembers)(e),r,o):(o.push(new q(e.name,e.file)),null):(o.push(new $(
|
|
61
|
+
t.file)),null),Me=(e,t,r,o,n)=>{let a={},l=new Set(["handler"]);for(let s of r)if(!(!(0,I.isModelProperty)(
|
|
62
|
+
s)||s.inherited))switch(s.name){default:n.push(new m.InvalidServicePropertyError(
|
|
63
|
+
t.name,s.name,e.file));break;case"handler":a.handler=ge(s.value,o,n);break;case"\
|
|
64
|
+
listener":a.listener=(0,m.getServiceListener)(s.value,n);break;case"memory":case"\
|
|
65
|
+
timeout":a[s.name]=(0,m.getPropertyNumber)(s);break;case"variables":a.variables=
|
|
66
|
+
(0,m.getLinkedVariableList)(s,n);break}return Ue(a)?a:(n.push(new H([...l],e.file)),
|
|
67
|
+
null)};var L=(e,t,r,o)=>{if(!(0,h.isTypeReference)(e))return he(e,t,r,o);let n=(0,T.getReferenceType)(
|
|
68
|
+
e,r);return n?he(n,t,r,o):null},Ve=e=>!!e.name&&!!e.schema&&!!e.indexes,he=(e,t,r,o)=>oe(
|
|
69
|
+
e)?ve(e,t,(0,T.getModelMembers)(e),r,o):(0,h.isTypeObject)(e)?ve(e,t,(0,T.getObjectMembers)(
|
|
70
|
+
e),r,o):null,ve=(e,t,r,o,n)=>{let a={},l=new Set(["name","schema","indexes"]);for(let i of r)
|
|
71
|
+
if(!(!(0,h.isModelProperty)(i)||i.inherited))switch(i.name){default:n.push(new T.InvalidServicePropertyError(
|
|
72
|
+
t.name,i.name,e.file));break;case"name":(a.name=(0,T.getPropertyString)(i))&&l.delete(
|
|
73
|
+
i.name);break;case"schema":(a.schema=Z(i.value,e,o,n))&&l.delete(i.name);break;case"\
|
|
74
|
+
indexes":(a.indexes=Te(i.value,e,o,n))&&l.delete(i.name);break;case"relations":a.
|
|
75
|
+
relations=ue(i.value,e,o,n);break;case"stream":a.stream=Ie(i.value,t,o,n);break}
|
|
76
|
+
if(!Ve(a))return n.push(new k([...l],e.file)),null;let s=_e(e,a.indexes,a.schema);
|
|
77
|
+
return s.length?(n.push(...s),null):a},_e=(e,t,r)=>{let o=r.properties,n=[];for(let{
|
|
78
|
+
name:a,columns:l}of t)l.some(i=>!o[i])&&n.push(new z(a,e.file));return n};var ee=e=>{let t={},r=[];for(let o in e){let n=e[o];if(!_(n)||(0,c.isExternalStatement)(
|
|
79
|
+
n))continue;let a={type:U,extras:{}},l=new Set(["engine","tables"]),s=n.file;a.name=
|
|
80
|
+
n.name;for(let p of(0,c.getModelMembers)(n))if(!(!(0,Pe.isModelProperty)(p)||p.inherited))
|
|
81
|
+
switch(p.name){default:r.push(new c.InvalidServicePropertyError(a.name,p.name,s));
|
|
82
|
+
break;case"engine":(a.engine=(0,c.getPropertyString)(p))&&l.delete(p.name);break;case"\
|
|
83
|
+
tables":(a.tables=Ge(p,n,e,r))&&l.delete(p.name);break;case"variables":a.variables=
|
|
84
|
+
(0,c.getLinkedVariableList)(p,r);break;case"services":a.services=(0,c.getLinkedServiceList)(
|
|
85
|
+
p,e,r);break}if(!Be(a)){r.push(new w([...l],s));continue}let i=Je(n,a.tables);if(i.
|
|
86
|
+
length){r.push(...i);continue}if(t[n.name]){r.push(new c.DuplicateServiceError(n.
|
|
87
|
+
name,s));continue}t[n.name]=a}return{services:t,errors:r}},Be=e=>!!e.name&&!!e.tables&&
|
|
88
|
+
!!e.extras,Ge=(e,t,r,o)=>{let n=(0,c.getPropertyTuple)(e)??[],a=[];for(let l of n){
|
|
89
|
+
let s=L(l,t,r,o);s&&a.push(s)}return a},Je=(e,t)=>{let r=Ke(t),o=[];for(let{relations:n,
|
|
90
|
+
schema:a,indexes:l}of t){if(!n)continue;let s=a.properties;for(let i of n){let{sourceTable:p,
|
|
91
|
+
sourceColumn:Q,targetColumn:W,targetAlias:re}=i;s[W]||o.push(new x(W,e.file)),s[re]&&
|
|
92
|
+
o.push(new E(re,e.file));let X=r[p]?.schema.properties;X||o.push(new j(p,e.file)),
|
|
93
|
+
X&&!X[Q]&&o.push(new x(Q,e.file));let Oe=r[p]?.indexes??[];i.sourceIndex=De(Oe,Q),
|
|
94
|
+
i.targetIndex=De(l,W)}}return o},De=(e,t)=>e.find(({name:r})=>r===t)?.type,Ke=e=>e.
|
|
95
|
+
reduce((t,r)=>({...t,[r.name]:r}),{});var je=e=>_(e)?e.name:null;var Ee=!1,Qe=()=>{Ee||((0,we.registerTriggers)(),(0,ke.registerTriggers)(),(0,Re.createTrigger)(
|
|
96
|
+
"@ez4/database",{"metadata:getServices":ee,"metadata:getLinkedService":je}),Ee=!0)};0&&(module.exports={IncompleteHandlerError,IncompleteServiceError,IncompleteStreamError,
|
|
97
97
|
IncompleteTableError,IncorrectIndexesTypeError,IncorrectRelationsTypeError,IncorrectSchemaTypeError,
|
|
98
98
|
IncorrectStreamTypeError,InvalidIndexReferenceError,InvalidIndexTypeError,InvalidIndexesTypeError,
|
|
99
99
|
InvalidRelationAliasError,InvalidRelationColumnError,InvalidRelationTableError,InvalidRelationTargetError,
|
package/dist/library.mjs
CHANGED
|
@@ -1,94 +1,98 @@
|
|
|
1
|
-
import{registerTriggers as
|
|
2
|
-
import{createTrigger as
|
|
3
|
-
getLinkedVariableList as
|
|
4
|
-
import{isModelProperty as
|
|
5
|
-
var u=class extends ce{constructor(
|
|
6
|
-
"Database.Relations",
|
|
7
|
-
able relations type",r,"Database.Relations",
|
|
8
|
-
super(`Target ${r} must follow the pattern 'column@alias'.`,
|
|
9
|
-
r}},
|
|
10
|
-
|
|
11
|
-
umn ${r} don't exists.`,
|
|
12
|
-
super(`Relation alias ${r} can't override table columns.`,
|
|
13
|
-
r}};
|
|
14
|
-
super("Incomplete database service",
|
|
15
|
-
import{isTypeCallback as
|
|
16
|
-
e)&&
|
|
17
|
-
$=e=>
|
|
18
|
-
chema"),U=e=>
|
|
19
|
-
getPropertyString as
|
|
20
|
-
isTypeReference as
|
|
21
|
-
super("Incomplete database table",
|
|
22
|
-
var
|
|
23
|
-
"Database.Indexes",
|
|
24
|
-
le indexes type",r,"Database.Indexes",
|
|
25
|
-
super(`Invalid index type, ${r} must follow one of the Index options.`,
|
|
26
|
-
r}},v=class extends V{constructor(r,
|
|
27
|
-
be valid column.`,
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
import{
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
super("Incomplete stream
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
1
|
+
import{registerTriggers as kr}from"@ez4/common/library";import{registerTriggers as Rr}from"@ez4/schema/library";
|
|
2
|
+
import{createTrigger as Or}from"@ez4/project/library";import{DuplicateServiceError as yr,InvalidServicePropertyError as xr,isExternalStatement as gr,
|
|
3
|
+
getLinkedServiceList as Sr,getLinkedVariableList as Mr,getPropertyString as Ir,getPropertyTuple as hr,
|
|
4
|
+
getModelMembers as vr}from"@ez4/common/library";import{isModelProperty as Dr}from"@ez4/reflection";import{IncorrectTypeError as me,InvalidTypeError as ce,TypeError as y}from"@ez4/common/library";
|
|
5
|
+
var u=class extends ce{constructor(t){super("Invalid table relations type",void 0,
|
|
6
|
+
"Database.Relations",t)}},d=class extends me{constructor(r,o){super("Incorrect t\
|
|
7
|
+
able relations type",r,"Database.Relations",o);this.schemaType=r}},b=class extends y{constructor(r,o){
|
|
8
|
+
super(`Target ${r} must follow the pattern 'column@alias'.`,o);this.relationSource=
|
|
9
|
+
r}},T=class extends y{constructor(r,o){super(`Relation table ${r} don't exists.`,
|
|
10
|
+
o);this.relationTable=r}},c=class extends y{constructor(r,o){super(`Relation col\
|
|
11
|
+
umn ${r} don't exists.`,o);this.relationColumn=r}},f=class extends y{constructor(r,o){
|
|
12
|
+
super(`Relation alias ${r} can't override table columns.`,o);this.relationAlias=
|
|
13
|
+
r}};import{IncompleteTypeError as ue}from"@ez4/common/library";var x=class extends ue{constructor(t,r){
|
|
14
|
+
super("Incomplete database service",t,r)}};var z="@ez4/database",Hr=e=>e.type===z;import{hasHeritageType as m,isClassDeclaration as de,isModelDeclaration as be}from"@ez4/common/library";
|
|
15
|
+
import{isTypeCallback as Te,isTypeFunction as fe}from"@ez4/reflection";var g=e=>de(
|
|
16
|
+
e)&&m(e,"Database.Service"),N=e=>be(e)&&m(e,"Database.Table"),H=e=>Te(e)||fe(e),
|
|
17
|
+
$=e=>m(e,"Database.Relations"),q=e=>m(e,"Database.Indexes"),F=e=>m(e,"Database.S\
|
|
18
|
+
chema"),U=e=>m(e,"Database.Stream");import{InvalidServicePropertyError as ir,getModelMembers as lr,getObjectMembers as pr,
|
|
19
|
+
getPropertyString as mr,getReferenceType as cr}from"@ez4/common/library";import{
|
|
20
|
+
isModelProperty as ur,isTypeObject as dr,isTypeReference as br}from"@ez4/reflection";import{IncompleteTypeError as ye}from"@ez4/common/library";var S=class extends ye{constructor(t,r){
|
|
21
|
+
super("Incomplete database table",t,r)}};import{IncorrectTypeError as xe,InvalidTypeError as ge,TypeError as V}from"@ez4/common/library";
|
|
22
|
+
var M=class extends ge{constructor(t){super("Invalid table indexes type",void 0,
|
|
23
|
+
"Database.Indexes",t)}},I=class extends xe{constructor(r,o){super("Incorrect tab\
|
|
24
|
+
le indexes type",r,"Database.Indexes",o);this.schemaType=r}},h=class extends V{constructor(r,o){
|
|
25
|
+
super(`Invalid index type, ${r} must follow one of the Index options.`,o);this.indexName=
|
|
26
|
+
r}},v=class extends V{constructor(r,o){super(`Invalid index reference, ${r} must\
|
|
27
|
+
be valid column.`,o);this.indexName=r}};import{isModelDeclaration as Se,getModelMembers as Me,getObjectMembers as Ie,getPropertyString as he,
|
|
28
|
+
getReferenceType as ve}from"@ez4/common/library";import{isModelProperty as De,isTypeObject as Pe,
|
|
29
|
+
isTypeReference as je}from"@ez4/reflection";var G=(e,t,r,o)=>{if(!je(e))return _(e,t,o);let n=ve(e,r);return n?_(n,t,o):null},
|
|
30
|
+
_=(e,t,r)=>Pe(e)?B(e,Ie(e),r):Se(e)?$(e)?B(e,Me(e),r):(r.push(new d(e.name,e.file)),
|
|
31
|
+
null):(r.push(new u(t.file)),null),B=(e,t,r)=>{let o=[];for(let n of t){if(!De(n)||
|
|
32
|
+
n.inherited)continue;let a=he(n);if(!a)return r.push(new b(n.name,e.file)),null;
|
|
33
|
+
let[l,s]=n.name.split(":",2),[i,p]=a.split("@",2);o.push({sourceTable:l,sourceColumn:s,
|
|
34
|
+
targetColumn:i,targetAlias:p})}return o};import{isModelDeclaration as Ee,getModelMembers as we,getObjectMembers as ke,getPropertyString as Re,
|
|
35
|
+
getReferenceType as Oe}from"@ez4/common/library";import{isModelProperty as Ae,isTypeObject as ze,
|
|
36
|
+
isTypeReference as Ce}from"@ez4/reflection";var Q=(e,t,r,o)=>{if(!Ce(e))return J(e,t,o);let n=Oe(e,r);return n?J(n,t,o):null},
|
|
37
|
+
J=(e,t,r)=>ze(e)?K(e,ke(e),r):Ee(e)?q(e)?K(e,we(e),r):(r.push(new I(e.name,e.file)),
|
|
38
|
+
null):(r.push(new M(t.file)),null),K=(e,t,r)=>{let o=[];for(let n of t){if(!Ae(n)||
|
|
39
|
+
n.inherited)continue;let a=n.name,l=Re(n);switch(l){case"primary":case"secondary":case"\
|
|
40
|
+
unique":case"ttl":o.push({name:a,columns:a.split(":"),type:l});break;default:return r.
|
|
41
|
+
push(new h(a,e.file)),null}}return o};import{getReferenceType as $e,isModelDeclaration as qe}from"@ez4/common/library";
|
|
42
|
+
import{getObjectSchema as Fe,isObjectSchema as Ue}from"@ez4/schema/library";import{
|
|
43
|
+
isTypeObject as Ve,isTypeReference as _e}from"@ez4/reflection";import{IncorrectTypeError as Ne,InvalidTypeError as He}from"@ez4/common/library";
|
|
44
|
+
var D=class extends He{constructor(t){super("Invalid table schema type",void 0,"\
|
|
45
|
+
Database.Schema",t)}},P=class extends Ne{constructor(r,o){super("Incorrect table\
|
|
46
|
+
schema type",r,"Database.Schema",o);this.schemaType=r}};var Y=(e,t,r,o)=>{if(!_e(e))return W(e,t,r,o);let n=$e(e,r);return n?W(n,t,r,o):
|
|
47
|
+
null},W=(e,t,r,o)=>Ve(e)?X(e,r):qe(e)?F(e)?X(e,r):(o.push(new P(e.name,e.file)),
|
|
48
|
+
null):(o.push(new D(t.file)),null),X=(e,t)=>{let r=Fe(e,t);return r&&Ue(r)?r:null};import{InvalidServicePropertyError as We,isModelDeclaration as Xe,getLinkedVariableList as Ye,
|
|
49
|
+
getModelMembers as Ze,getObjectMembers as Le,getPropertyNumber as er,getServiceListener as rr,
|
|
50
|
+
getReferenceType as tr}from"@ez4/common/library";import{isModelProperty as or,isTypeObject as nr,
|
|
51
|
+
isTypeReference as ar}from"@ez4/reflection";import{IncompleteTypeError as Be,IncorrectTypeError as Ge,InvalidTypeError as Je}from"@ez4/common/library";
|
|
52
|
+
var j=class extends Be{constructor(t,r){super("Incomplete table stream",t,r)}},E=class extends Je{constructor(t){
|
|
53
|
+
super("Invalid table stream type",void 0,"Database.Stream",t)}},w=class extends Ge{constructor(r,o){
|
|
54
|
+
super("Incorrect table stream type",r,"Database.Stream",o);this.streamType=r}};import{IncompleteTypeError as Ke}from"@ez4/common/library";var k=class extends Ke{constructor(t,r){
|
|
55
|
+
super("Incomplete stream handler",t,r)}};var Z=(e,t,r)=>{if(!H(e))return null;let o={},n=new Set(["name","file","change"]);
|
|
56
|
+
return e.description&&(o.description=e.description),(o.name=e.name)&&n.delete("n\
|
|
57
|
+
ame"),(o.file=e.file)&&n.delete("file"),e.parameters&&n.delete("change"),n.size===
|
|
58
|
+
0&&Qe(o)?o:(r.push(new k([...n],e.file)),null)},Qe=e=>!!e.name&&!!e.file;var re=(e,t,r,o)=>{if(!ar(e))return L(e,t,r,o);let n=tr(e,r);return n?L(n,t,r,o):
|
|
59
|
+
null},sr=e=>!!e.handler,L=(e,t,r,o)=>nr(e)?ee(e,t,Le(e),r,o):Xe(e)?U(e)?ee(e,t,Ze(
|
|
60
|
+
e),r,o):(o.push(new w(e.name,e.file)),null):(o.push(new E(t.file)),null),ee=(e,t,r,o,n)=>{
|
|
61
|
+
let a={},l=new Set(["handler"]);for(let s of r)if(!(!or(s)||s.inherited))switch(s.
|
|
62
|
+
name){default:n.push(new We(t.name,s.name,e.file));break;case"handler":a.handler=
|
|
63
|
+
Z(s.value,o,n);break;case"listener":a.listener=rr(s.value,n);break;case"memory":case"\
|
|
64
|
+
timeout":a[s.name]=er(s);break;case"variables":a.variables=Ye(s,n);break}return sr(
|
|
65
|
+
a)?a:(n.push(new j([...l],e.file)),null)};var ne=(e,t,r,o)=>{if(!br(e))return te(e,t,r,o);let n=cr(e,r);return n?te(n,t,r,
|
|
66
|
+
o):null},Tr=e=>!!e.name&&!!e.schema&&!!e.indexes,te=(e,t,r,o)=>N(e)?oe(e,t,lr(e),
|
|
67
|
+
r,o):dr(e)?oe(e,t,pr(e),r,o):null,oe=(e,t,r,o,n)=>{let a={},l=new Set(["name","s\
|
|
68
|
+
chema","indexes"]);for(let i of r)if(!(!ur(i)||i.inherited))switch(i.name){default:
|
|
69
|
+
n.push(new ir(t.name,i.name,e.file));break;case"name":(a.name=mr(i))&&l.delete(i.
|
|
70
|
+
name);break;case"schema":(a.schema=Y(i.value,e,o,n))&&l.delete(i.name);break;case"\
|
|
71
|
+
indexes":(a.indexes=Q(i.value,e,o,n))&&l.delete(i.name);break;case"relations":a.
|
|
72
|
+
relations=G(i.value,e,o,n);break;case"stream":a.stream=re(i.value,t,o,n);break}if(!Tr(
|
|
73
|
+
a))return n.push(new S([...l],e.file)),null;let s=fr(e,a.indexes,a.schema);return s.
|
|
74
|
+
length?(n.push(...s),null):a},fr=(e,t,r)=>{let o=r.properties,n=[];for(let{name:a,
|
|
75
|
+
columns:l}of t)l.some(i=>!o[i])&&n.push(new v(a,e.file));return n};var se=e=>{let t={},r=[];for(let o in e){let n=e[o];if(!g(n)||gr(n))continue;let a={
|
|
76
|
+
type:z,extras:{}},l=new Set(["engine","tables"]),s=n.file;a.name=n.name;for(let p of vr(
|
|
77
|
+
n))if(!(!Dr(p)||p.inherited))switch(p.name){default:r.push(new xr(a.name,p.name,
|
|
78
|
+
s));break;case"engine":(a.engine=Ir(p))&&l.delete(p.name);break;case"tables":(a.
|
|
79
|
+
tables=jr(p,n,e,r))&&l.delete(p.name);break;case"variables":a.variables=Mr(p,r);
|
|
80
|
+
break;case"services":a.services=Sr(p,e,r);break}if(!Pr(a)){r.push(new x([...l],s));
|
|
81
|
+
continue}let i=Er(n,a.tables);if(i.length){r.push(...i);continue}if(t[n.name]){r.
|
|
82
|
+
push(new yr(n.name,s));continue}t[n.name]=a}return{services:t,errors:r}},Pr=e=>!!e.
|
|
83
|
+
name&&!!e.tables&&!!e.extras,jr=(e,t,r,o)=>{let n=hr(e)??[],a=[];for(let l of n){
|
|
84
|
+
let s=ne(l,t,r,o);s&&a.push(s)}return a},Er=(e,t)=>{let r=wr(t),o=[];for(let{relations:n,
|
|
85
|
+
schema:a,indexes:l}of t){if(!n)continue;let s=a.properties;for(let i of n){let{sourceTable:p,
|
|
86
|
+
sourceColumn:R,targetColumn:O,targetAlias:C}=i;s[O]||o.push(new c(O,e.file)),s[C]&&
|
|
87
|
+
o.push(new f(C,e.file));let A=r[p]?.schema.properties;A||o.push(new T(p,e.file)),
|
|
88
|
+
A&&!A[R]&&o.push(new c(R,e.file));let pe=r[p]?.indexes??[];i.sourceIndex=ae(pe,R),
|
|
89
|
+
i.targetIndex=ae(l,O)}}return o},ae=(e,t)=>e.find(({name:r})=>r===t)?.type,wr=e=>e.
|
|
90
|
+
reduce((t,r)=>({...t,[r.name]:r}),{});var ie=e=>g(e)?e.name:null;var le=!1,Yt=()=>{le||(kr(),Rr(),Or("@ez4/database",{"metadata:getServices":se,"\
|
|
91
|
+
metadata:getLinkedService":ie}),le=!0)};export{k as IncompleteHandlerError,x as IncompleteServiceError,j as IncompleteStreamError,
|
|
92
|
+
S as IncompleteTableError,I as IncorrectIndexesTypeError,d as IncorrectRelationsTypeError,
|
|
89
93
|
P as IncorrectSchemaTypeError,w as IncorrectStreamTypeError,v as InvalidIndexReferenceError,
|
|
90
|
-
h as InvalidIndexTypeError,
|
|
91
|
-
c as InvalidRelationColumnError,
|
|
94
|
+
h as InvalidIndexTypeError,M as InvalidIndexesTypeError,f as InvalidRelationAliasError,
|
|
95
|
+
c as InvalidRelationColumnError,T as InvalidRelationTableError,b as InvalidRelationTargetError,
|
|
92
96
|
u as InvalidRelationsTypeError,D as InvalidSchemaTypeError,E as InvalidStreamTypeError,
|
|
93
97
|
z as ServiceType,se as getDatabaseServices,ne as getDatabaseTable,Y as getTableSchema,
|
|
94
|
-
|
|
98
|
+
Hr as isDatabaseService,Yt as registerTriggers};
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import type { AllType, SourceMap, TypeModel
|
|
1
|
+
import type { AllType, SourceMap, TypeModel } from '@ez4/reflection';
|
|
2
2
|
import type { TableStream } from '../types/stream.js';
|
|
3
|
-
type
|
|
4
|
-
export declare const getTableStream: (type: AllType, parent: TypeParent, reflection: SourceMap, errorList: Error[]) => TableStream | null;
|
|
5
|
-
export {};
|
|
3
|
+
export declare const getTableStream: (type: AllType, parent: TypeModel, reflection: SourceMap, errorList: Error[]) => TableStream | null;
|
package/dist/metadata/table.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { AllType, SourceMap } from '@ez4/reflection';
|
|
1
|
+
import type { AllType, SourceMap, TypeModel } from '@ez4/reflection';
|
|
2
2
|
import type { DatabaseTable } from '../types/table.js';
|
|
3
|
-
export declare const getDatabaseTable: (type: AllType, reflection: SourceMap, errorList: Error[]) => DatabaseTable | null;
|
|
3
|
+
export declare const getDatabaseTable: (type: AllType, parent: TypeModel, reflection: SourceMap, errorList: Error[]) => DatabaseTable | null;
|
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.16.0",
|
|
5
5
|
"author": "Silas B.",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"type": "module",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"directory": "packages/database"
|
|
15
15
|
},
|
|
16
16
|
"engines": {
|
|
17
|
-
"node": ">=
|
|
17
|
+
"node": ">=22.3.0"
|
|
18
18
|
},
|
|
19
19
|
"exports": {
|
|
20
20
|
".": {
|
|
@@ -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.16.0",
|
|
46
|
+
"@ez4/project": "^0.16.0",
|
|
47
|
+
"@ez4/reflection": "^0.16.0",
|
|
48
|
+
"@ez4/schema": "^0.16.0",
|
|
49
|
+
"@ez4/utils": "^0.16.0"
|
|
50
50
|
}
|
|
51
51
|
}
|