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