@ez4/database 0.20.0 → 0.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,4 @@
1
+ import { IncompleteTypeError } from '@ez4/common/library';
2
+ export declare class IncompleteEngineError extends IncompleteTypeError {
3
+ constructor(properties: string[], fileName?: string);
4
+ }
@@ -0,0 +1,4 @@
1
+ import { IncompleteTypeError } from '@ez4/common/library';
2
+ export declare class IncompleteScalabilityError extends IncompleteTypeError {
3
+ constructor(properties: string[], fileName?: string);
4
+ }
package/dist/library.cjs CHANGED
@@ -1,117 +1,130 @@
1
- "use strict";var L=Object.defineProperty;var Ve=Object.getOwnPropertyDescriptor;var Fe=Object.getOwnPropertyNames;var Qe=Object.prototype.hasOwnProperty;var $e=(e,r)=>{for(var t in r)L(e,t,{get:r[t],enumerable:!0})},Ge=(e,r,t,n)=>{if(r&&
2
- typeof r=="object"||typeof r=="function")for(let a of Fe(r))!Qe.call(e,a)&&a!==t&&
3
- L(e,a,{get:()=>r[a],enumerable:!(n=Ve(r,a))||n.enumerable});return e};var Be=e=>Ge(L({},"__esModule",{value:!0}),e);var lt={};$e(lt,{IncompleteHandlerError:()=>$,IncompleteServiceError:()=>A,IncompleteStreamError:()=>V,
4
- IncompleteTableError:()=>x,IncorrectIndexesTypeError:()=>U,IncorrectRelationsTypeError:()=>O,
5
- IncorrectSchemaTypeError:()=>q,IncorrectStreamTypeError:()=>Q,InvalidIndexReferenceError:()=>N,
6
- InvalidIndexTypeError:()=>z,InvalidIndexesTypeError:()=>w,InvalidRelationAliasError:()=>C,
7
- InvalidRelationColumnError:()=>S,InvalidRelationTableError:()=>k,InvalidRelationTargetError:()=>R,
8
- InvalidRelationsTypeError:()=>j,InvalidSchemaTypeError:()=>H,InvalidStreamTypeError:()=>F,
9
- ServiceType:()=>G,getDatabaseServices:()=>re,getDatabaseTable:()=>te,getTableSchema:()=>ee,
10
- isDatabaseService:()=>_e,registerTriggers:()=>pt});module.exports=Be(lt);var ze=require("@ez4/common/library"),Ne=require("@ez4/schema/library"),He=require("@ez4/project/library");var d=require("@ez4/common/library"),Ae=require("@ez4/reflection");var y=require("@ez4/common/library"),j=class extends y.InvalidTypeError{constructor(r){
11
- super("Invalid table relations type",void 0,"Database.Relations",r)}},O=class extends y.IncorrectTypeError{constructor(t,n){
1
+ "use strict";var oe=Object.defineProperty;var We=Object.getOwnPropertyDescriptor;var Xe=Object.getOwnPropertyNames;var Ye=Object.prototype.hasOwnProperty;var Ze=(e,r)=>{for(var t in r)oe(e,t,{get:r[t],enumerable:!0})},Le=(e,r,t,n)=>{if(r&&
2
+ typeof r=="object"||typeof r=="function")for(let a of Xe(r))!Ye.call(e,a)&&a!==t&&
3
+ oe(e,a,{get:()=>r[a],enumerable:!(n=We(r,a))||n.enumerable});return e};var et=e=>Le(oe({},"__esModule",{value:!0}),e);var ut={};Ze(ut,{IncompleteEngineError:()=>U,IncompleteHandlerError:()=>J,IncompleteScalabilityError:()=>z,
4
+ IncompleteServiceError:()=>O,IncompleteStreamError:()=>Q,IncompleteTableError:()=>N,
5
+ IncorrectIndexesTypeError:()=>F,IncorrectRelationsTypeError:()=>R,IncorrectSchemaTypeError:()=>G,
6
+ IncorrectStreamTypeError:()=>_,InvalidIndexReferenceError:()=>V,InvalidIndexTypeError:()=>q,
7
+ InvalidIndexesTypeError:()=>H,InvalidRelationAliasError:()=>C,InvalidRelationColumnError:()=>M,
8
+ InvalidRelationTableError:()=>w,InvalidRelationTargetError:()=>A,InvalidRelationsTypeError:()=>k,
9
+ InvalidSchemaTypeError:()=>$,InvalidStreamTypeError:()=>B,ServiceType:()=>K,getDatabaseServices:()=>pe,
10
+ getDatabaseTable:()=>ie,getTableSchema:()=>se,isDatabaseService:()=>tt,registerTriggers:()=>dt});
11
+ module.exports=et(ut);var Be=require("@ez4/common/library"),_e=require("@ez4/schema/library"),Je=require("@ez4/project/library");var d=require("@ez4/common/library"),$e=require("@ez4/reflection");var K="@ez4/database",tt=e=>e.type===K;var me=require("@ez4/common/library"),O=class extends me.IncompleteTypeError{constructor(r,t){
12
+ super("Incomplete database service",r,t)}};var x=require("@ez4/common/library"),k=class extends x.InvalidTypeError{constructor(r){
13
+ super("Invalid table relations type",void 0,"Database.Relations",r)}},R=class extends x.IncorrectTypeError{constructor(t,n){
12
14
  super("Incorrect table relations type",t,"Database.Relations",n);this.schemaType=
13
- t}},R=class extends y.TypeError{constructor(t,n){super(`Target ${t} must follow \
14
- the pattern 'column@alias'.`,n);this.relationSource=t}},k=class extends y.TypeError{constructor(t,n){
15
- super(`Relation table ${t} don't exists.`,n);this.relationTable=t}},S=class extends y.TypeError{constructor(t,n){
16
- super(`Relation column ${t} don't exists.`,n);this.relationColumn=t}},C=class extends y.TypeError{constructor(t,n){
15
+ t}},A=class extends x.TypeError{constructor(t,n){super(`Target ${t} must follow \
16
+ the pattern 'column@alias'.`,n);this.relationSource=t}},w=class extends x.TypeError{constructor(t,n){
17
+ super(`Relation table ${t} don't exists.`,n);this.relationTable=t}},M=class extends x.TypeError{constructor(t,n){
18
+ super(`Relation column ${t} don't exists.`,n);this.relationColumn=t}},C=class extends x.TypeError{constructor(t,n){
17
19
  super(`Relation alias ${t} can't override table columns.`,n);this.relationAlias=
18
- t}};var ae=require("@ez4/common/library"),A=class extends ae.IncompleteTypeError{constructor(r,t){
19
- super("Incomplete database service",r,t)}};var G="@ez4/database",_e=e=>e.type===G;var I=require("@ez4/reflection"),m=require("@ez4/common/library");var oe=require("@ez4/common/library"),x=class extends oe.IncompleteTypeError{constructor(r,t){
20
- super("Incomplete database table",r,t)}};var T=require("@ez4/common/library"),B=require("@ez4/reflection"),_=e=>(0,T.isClassDeclaration)(
21
- e)&&(0,T.hasHeritageType)(e,"Database.Service"),se=e=>(0,T.isModelDeclaration)(e)&&
22
- (0,T.hasHeritageType)(e,"Database.Engine"),ie=e=>(0,T.isModelDeclaration)(e)&&(0,T.hasHeritageType)(
23
- e,"Database.Table"),pe=e=>(0,B.isTypeCallback)(e)||(0,B.isTypeFunction)(e),le=e=>(0,T.hasHeritageType)(
24
- e,"Database.Relations"),me=e=>(0,T.hasHeritageType)(e,"Database.Indexes"),ce=e=>(0,T.hasHeritageType)(
25
- e,"Database.Schema"),de=e=>(0,T.hasHeritageType)(e,"Database.Stream");var Te;(e=>{})(Te||={});var fe=(e,r,t,n)=>{if(!(0,I.isTypeReference)(e))return ue(e,r,n);let a=(0,m.getReferenceType)(
26
- e,t);return a?ue(a,r,n):null},Le=e=>!!e.name&&!!e.parametersMode&&!!e.transactionMode&&
27
- !!e.orderMode,ue=(e,r,t)=>se(e)?be(e,r,(0,m.getModelMembers)(e),t):(0,I.isTypeObject)(
28
- e)?be(e,r,(0,m.getObjectMembers)(e),t):null,be=(e,r,t,n)=>{let a={},o=new Set(["\
29
- name","parametersMode","transactionMode","insensitiveMode","paginationMode","ord\
30
- erMode"]);for(let s of t)if(!(!(0,I.isModelProperty)(s)||s.inherited))switch(s.name){default:
31
- n.push(new m.InvalidServicePropertyError(r.name,s.name,e.file));break;case"name":
32
- (a.name=(0,m.getPropertyString)(s))&&o.delete(s.name);break;case"parametersMode":
33
- (a.parametersMode=(0,m.getPropertyStringIn)(s,["index","both"]))&&o.delete(s.name);
34
- break;case"transactionMode":(a.transactionMode=(0,m.getPropertyStringIn)(s,["sta\
35
- tic","interactive"]))&&o.delete(s.name);break;case"insensitiveMode":(a.insensitiveMode=
36
- (0,m.getPropertyStringIn)(s,["unsupported","enabled"]))&&o.delete(s.name);break;case"\
37
- paginationMode":(a.paginationMode=(0,m.getPropertyStringIn)(s,["cursor","offset"]))&&
38
- o.delete(s.name);break;case"orderMode":(a.orderMode=(0,m.getPropertyStringIn)(s,
39
- ["any","index"]))&&o.delete(s.name);break}return Le(a)?a:(n.push(new x([...o],e.
40
- file)),null)};var f=require("@ez4/common/library"),E=require("@ez4/reflection");var g=require("@ez4/common/library"),w=class extends g.InvalidTypeError{constructor(r){
41
- super("Invalid table indexes type",void 0,"Database.Indexes",r)}},U=class extends g.IncorrectTypeError{constructor(t,n){
20
+ t}};var b=require("@ez4/common/library"),I=require("@ez4/reflection"),Z=require("@ez4/utils");var ce=require("@ez4/common/library"),z=class extends ce.IncompleteTypeError{constructor(r,t){
21
+ super("Incomplete database scalability",r,t)}};var u=require("@ez4/common/library"),W=require("@ez4/reflection"),X=e=>(0,u.isClassDeclaration)(
22
+ e)&&(0,u.hasHeritageType)(e,"Database.Service"),Y=e=>(0,u.isModelDeclaration)(e)&&
23
+ (0,u.hasHeritageType)(e,"Database.Engine"),de=e=>(0,u.isModelDeclaration)(e)&&(0,u.hasHeritageType)(
24
+ e,"Database.Table"),ue=e=>(0,W.isTypeCallback)(e)||(0,W.isTypeFunction)(e),be=e=>(0,u.hasHeritageType)(
25
+ e,"Database.Relations"),Te=e=>(0,u.hasHeritageType)(e,"Database.Indexes"),fe=e=>(0,u.hasHeritageType)(
26
+ e,"Database.Schema"),ye=e=>(0,u.hasHeritageType)(e,"Database.Stream");var Me=(e,r,t,n)=>{if(!(0,I.isTypeReference)(e))return xe(e,r,n);let a=(0,b.getReferenceType)(
27
+ e,t);return a?xe(a,r,n):null},rt=e=>(0,Z.isAnyNumber)(e.minCapacity)&&(0,Z.isAnyNumber)(
28
+ e.maxCapacity),xe=(e,r,t)=>Y(e)?ge(e,r,(0,b.getModelMembers)(e),t):(0,I.isTypeObject)(
29
+ e)?ge(e,r,(0,b.getObjectMembers)(e),t):null,ge=(e,r,t,n)=>{let a={},o=new Set(["\
30
+ minCapacity","maxCapacity"]);for(let s of t)if(!(!(0,I.isModelProperty)(s)||s.inherited))
31
+ switch(s.name){default:n.push(new b.InvalidServicePropertyError(r.name,s.name,e.
32
+ file));break;case"minCapacity":case"maxCapacity":let i=(0,b.getPropertyNumber)(s);
33
+ (0,Z.isAnyNumber)(i)&&(a[s.name]=i,o.delete(s.name));break}return rt(a)?a:(n.push(
34
+ new z([...o],e.file)),null)};var S=require("@ez4/reflection"),m=require("@ez4/common/library");var Ie=require("@ez4/common/library"),U=class extends Ie.IncompleteTypeError{constructor(r,t){
35
+ super("Incomplete database engine",r,t)}};var he=(e,r,t,n)=>{if(!(0,S.isTypeReference)(e))return Se(e,r,n);let a=(0,m.getReferenceType)(
36
+ e,t);return a?Se(a,r,n):null},nt=e=>!!e.name&&!!e.parametersMode&&!!e.transactionMode&&
37
+ !!e.insensitiveMode&&!!e.paginationMode&&!!e.orderMode,Se=(e,r,t)=>Y(e)?De(e,r,(0,m.getModelMembers)(
38
+ e),t):(0,S.isTypeObject)(e)?De(e,r,(0,m.getObjectMembers)(e),t):null,De=(e,r,t,n)=>{
39
+ let a={},o=new Set(["name","parametersMode","transactionMode","insensitiveMode",
40
+ "paginationMode","orderMode"]);for(let s of t)if(!(!(0,S.isModelProperty)(s)||s.
41
+ inherited))switch(s.name){default:n.push(new m.InvalidServicePropertyError(r.name,
42
+ s.name,e.file));break;case"name":(a.name=(0,m.getPropertyString)(s))&&o.delete(s.
43
+ name);break;case"parametersMode":(a.parametersMode=(0,m.getPropertyStringIn)(s,[
44
+ "index","both"]))&&o.delete(s.name);break;case"transactionMode":(a.transactionMode=
45
+ (0,m.getPropertyStringIn)(s,["static","interactive"]))&&o.delete(s.name);break;case"\
46
+ insensitiveMode":(a.insensitiveMode=(0,m.getPropertyStringIn)(s,["unsupported","\
47
+ enabled"]))&&o.delete(s.name);break;case"paginationMode":(a.paginationMode=(0,m.getPropertyStringIn)(
48
+ s,["cursor","offset"]))&&o.delete(s.name);break;case"orderMode":(a.orderMode=(0,m.getPropertyStringIn)(
49
+ s,["any","index"]))&&o.delete(s.name);break}return nt(a)?a:(n.push(new U([...o],
50
+ e.file)),null)};var y=require("@ez4/common/library"),j=require("@ez4/reflection");var ve=require("@ez4/common/library"),N=class extends ve.IncompleteTypeError{constructor(r,t){
51
+ super("Incomplete database table",r,t)}};var g=require("@ez4/common/library"),H=class extends g.InvalidTypeError{constructor(r){
52
+ super("Invalid table indexes type",void 0,"Database.Indexes",r)}},F=class extends g.IncorrectTypeError{constructor(t,n){
42
53
  super("Incorrect table indexes type",t,"Database.Indexes",n);this.schemaType=t}},
43
- z=class extends g.TypeError{constructor(t,n){super(`Invalid index type, ${t} mus\
44
- t follow one of the Index options.`,n);this.indexName=t}},N=class extends g.TypeError{constructor(t,n){
45
- super(`Invalid index reference, ${t} must be valid column.`,n);this.indexName=t}};var u=require("@ez4/common/library"),M=require("@ez4/reflection");var ge=(e,r,t,n)=>{if(!(0,M.isTypeReference)(e))return ye(e,r,n);let a=(0,u.getReferenceType)(
46
- e,t);return a?ye(a,r,n):null},ye=(e,r,t)=>(0,M.isTypeObject)(e)?xe(e,(0,u.getObjectMembers)(
47
- e),t):(0,u.isModelDeclaration)(e)?le(e)?xe(e,(0,u.getModelMembers)(e),t):(t.push(
48
- new O(e.name,e.file)),null):(t.push(new j(r.file)),null),xe=(e,r,t)=>{let n=[];for(let a of r){
49
- if(!(0,M.isModelProperty)(a)||a.inherited)continue;let o=(0,u.getPropertyString)(
50
- a),s=a.name;if(!o)return t.push(new R(s,e.file)),null;let[i,p]=s.split("@",2),[l,
54
+ q=class extends g.TypeError{constructor(t,n){super(`Invalid index type, ${t} mus\
55
+ t follow one of the Index options.`,n);this.indexName=t}},V=class extends g.TypeError{constructor(t,n){
56
+ super(`Invalid index reference, ${t} must be valid column.`,n);this.indexName=t}};var T=require("@ez4/common/library"),D=require("@ez4/reflection");var Pe=(e,r,t,n)=>{if(!(0,D.isTypeReference)(e))return Ee(e,r,n);let a=(0,T.getReferenceType)(
57
+ e,t);return a?Ee(a,r,n):null},Ee=(e,r,t)=>(0,D.isTypeObject)(e)?je(e,(0,T.getObjectMembers)(
58
+ e),t):(0,T.isModelDeclaration)(e)?be(e)?je(e,(0,T.getModelMembers)(e),t):(t.push(
59
+ new R(e.name,e.file)),null):(t.push(new k(r.file)),null),je=(e,r,t)=>{let n=[];for(let a of r){
60
+ if(!(0,D.isModelProperty)(a)||a.inherited)continue;let o=(0,T.getPropertyString)(
61
+ a),s=a.name;if(!o)return t.push(new A(s,e.file)),null;let[i,p]=s.split("@",2),[l,
51
62
  P]=o.split(":",2);n.push({sourceTable:l,sourceColumn:P,targetColumn:i,targetAlias:p})}
52
- return n};var b=require("@ez4/common/library"),h=require("@ez4/reflection");var Me=(e,r,t,n)=>{if(!(0,h.isTypeReference)(e))return Se(e,r,n);let a=(0,b.getReferenceType)(
53
- e,t);return a?Se(a,r,n):null},Se=(e,r,t)=>(0,h.isTypeObject)(e)?Ie(e,(0,b.getObjectMembers)(
54
- e),t):(0,b.isModelDeclaration)(e)?me(e)?Ie(e,(0,b.getModelMembers)(e),t):(t.push(
55
- new U(e.name,e.file)),null):(t.push(new w(r.file)),null),Ie=(e,r,t)=>{let n=[];for(let a of r){
56
- if(!(0,h.isModelProperty)(a)||a.inherited)continue;let o=a.name,s=(0,b.getPropertyString)(
63
+ return n};var f=require("@ez4/common/library"),h=require("@ez4/reflection");var Re=(e,r,t,n)=>{if(!(0,h.isTypeReference)(e))return Oe(e,r,n);let a=(0,f.getReferenceType)(
64
+ e,t);return a?Oe(a,r,n):null},Oe=(e,r,t)=>(0,h.isTypeObject)(e)?ke(e,(0,f.getObjectMembers)(
65
+ e),t):(0,f.isModelDeclaration)(e)?Te(e)?ke(e,(0,f.getModelMembers)(e),t):(t.push(
66
+ new F(e.name,e.file)),null):(t.push(new H(r.file)),null),ke=(e,r,t)=>{let n=[];for(let a of r){
67
+ if(!(0,h.isModelProperty)(a)||a.inherited)continue;let o=a.name,s=(0,f.getPropertyString)(
57
68
  a);switch(s){case"primary":case"secondary":case"unique":case"ttl":n.push({name:o,
58
- columns:o.split(":"),type:s});break;default:return t.push(new z(o,e.file)),null}}
59
- return n};var K=require("@ez4/common/library"),W=require("@ez4/schema/library"),X=require("@ez4/reflection");var J=require("@ez4/common/library"),H=class extends J.InvalidTypeError{constructor(r){
60
- super("Invalid table schema type",void 0,"Database.Schema",r)}},q=class extends J.IncorrectTypeError{constructor(t,n){
61
- super("Incorrect table schema type",t,"Database.Schema",n);this.schemaType=t}};var ee=(e,r,t,n)=>{if(!(0,X.isTypeReference)(e))return he(e,r,t,n);let a=(0,K.getReferenceType)(
62
- e,t);return a?he(a,r,t,n):null},he=(e,r,t,n)=>(0,X.isTypeObject)(e)?ve(e,t):(0,K.isModelDeclaration)(
63
- e)?ce(e)?ve(e,t):(n.push(new q(e.name,e.file)),null):(n.push(new H(r.file)),null),
64
- ve=(e,r)=>{let t=(0,W.getObjectSchema)(e,r);return t&&(0,W.isObjectSchema)(t)?t:
65
- null};var c=require("@ez4/common/library"),D=require("@ez4/reflection");var v=require("@ez4/common/library"),V=class extends v.IncompleteTypeError{constructor(r,t){
66
- super("Incomplete table stream",r,t)}},F=class extends v.InvalidTypeError{constructor(r){
67
- super("Invalid table stream type",void 0,"Database.Stream",r)}},Q=class extends v.IncorrectTypeError{constructor(t,n){
68
- super("Incorrect table stream type",t,"Database.Stream",n);this.streamType=t}};var De=require("@ez4/common/library"),$=class extends De.IncompleteTypeError{constructor(r,t){
69
- super("Incomplete stream handler",r,t)}};var Ee=(e,r,t)=>{if(!pe(e))return null;let n={},a=new Set(["name","file","change"]);
69
+ columns:o.split(":"),type:s});break;default:return t.push(new q(o,e.file)),null}}
70
+ return n};var ee=require("@ez4/common/library"),te=require("@ez4/schema/library"),re=require("@ez4/reflection");var L=require("@ez4/common/library"),$=class extends L.InvalidTypeError{constructor(r){
71
+ super("Invalid table schema type",void 0,"Database.Schema",r)}},G=class extends L.IncorrectTypeError{constructor(t,n){
72
+ super("Incorrect table schema type",t,"Database.Schema",n);this.schemaType=t}};var se=(e,r,t,n)=>{if(!(0,re.isTypeReference)(e))return Ae(e,r,t,n);let a=(0,ee.getReferenceType)(
73
+ e,t);return a?Ae(a,r,t,n):null},Ae=(e,r,t,n)=>(0,re.isTypeObject)(e)?we(e,t):(0,ee.isModelDeclaration)(
74
+ e)?fe(e)?we(e,t):(n.push(new G(e.name,e.file)),null):(n.push(new $(r.file)),null),
75
+ we=(e,r)=>{let t=(0,te.getObjectSchema)(e,r);return t&&(0,te.isObjectSchema)(t)?
76
+ t:null};var c=require("@ez4/common/library"),E=require("@ez4/reflection");var v=require("@ez4/common/library"),Q=class extends v.IncompleteTypeError{constructor(r,t){
77
+ super("Incomplete table stream",r,t)}},B=class extends v.InvalidTypeError{constructor(r){
78
+ super("Invalid table stream type",void 0,"Database.Stream",r)}},_=class extends v.IncorrectTypeError{constructor(t,n){
79
+ super("Incorrect table stream type",t,"Database.Stream",n);this.streamType=t}};var Ce=require("@ez4/common/library"),J=class extends Ce.IncompleteTypeError{constructor(r,t){
80
+ super("Incomplete stream handler",r,t)}};var ze=(e,r,t)=>{if(!ue(e))return null;let n={},a=new Set(["name","file","change"]);
70
81
  return e.description&&(n.description=e.description),(n.name=e.name)&&a.delete("n\
71
82
  ame"),(n.file=e.file)&&a.delete("file"),e.parameters&&a.delete("change"),a.size===
72
- 0&&et(n)?n:(t.push(new $([...a],e.file)),null)},et=e=>!!e.name&&!!e.file;var Oe=(e,r,t,n)=>{if(!(0,D.isTypeReference)(e))return Pe(e,r,t,n);let a=(0,c.getReferenceType)(
73
- e,t);return a?Pe(a,r,t,n):null},tt=e=>!!e.handler,Pe=(e,r,t,n)=>(0,D.isTypeObject)(
74
- e)?je(e,r,(0,c.getObjectMembers)(e),t,n):(0,c.isModelDeclaration)(e)?de(e)?je(e,
75
- r,(0,c.getModelMembers)(e),t,n):(n.push(new Q(e.name,e.file)),null):(n.push(new F(
76
- r.file)),null),je=(e,r,t,n,a)=>{let o={},s=new Set(["handler"]);for(let i of t)if(!(!(0,D.isModelProperty)(
83
+ 0&&at(n)?n:(t.push(new J([...a],e.file)),null)},at=e=>!!e.name&&!!e.file;var He=(e,r,t,n)=>{if(!(0,E.isTypeReference)(e))return Ue(e,r,t,n);let a=(0,c.getReferenceType)(
84
+ e,t);return a?Ue(a,r,t,n):null},ot=e=>!!e.handler,Ue=(e,r,t,n)=>(0,E.isTypeObject)(
85
+ e)?Ne(e,r,(0,c.getObjectMembers)(e),t,n):(0,c.isModelDeclaration)(e)?ye(e)?Ne(e,
86
+ r,(0,c.getModelMembers)(e),t,n):(n.push(new _(e.name,e.file)),null):(n.push(new B(
87
+ r.file)),null),Ne=(e,r,t,n,a)=>{let o={},s=new Set(["handler"]);for(let i of t)if(!(!(0,E.isModelProperty)(
77
88
  i)||i.inherited))switch(i.name){default:a.push(new c.InvalidServicePropertyError(
78
- r.name,i.name,e.file));break;case"handler":o.handler=Ee(i.value,n,a);break;case"\
89
+ r.name,i.name,e.file));break;case"handler":o.handler=ze(i.value,n,a);break;case"\
79
90
  listener":o.listener=(0,c.getServiceListener)(i.value,a);break;case"memory":case"\
80
91
  logRetention":case"timeout":o[i.name]=(0,c.getPropertyNumber)(i);break;case"vari\
81
- ables":o.variables=(0,c.getLinkedVariableList)(i,a);break}return tt(o)?o:(a.push(
82
- new V([...s],e.file)),null)};var te=(e,r,t,n)=>{if(!(0,E.isTypeReference)(e))return Re(e,r,t,n);let a=(0,f.getReferenceType)(
83
- e,t);return a?Re(a,r,t,n):null},rt=e=>!!e.name&&!!e.schema&&!!e.indexes,Re=(e,r,t,n)=>ie(
84
- e)?ke(e,r,(0,f.getModelMembers)(e),t,n):(0,E.isTypeObject)(e)?ke(e,r,(0,f.getObjectMembers)(
85
- e),t,n):null,ke=(e,r,t,n,a)=>{let o={},s=new Set(["name","schema","indexes"]);for(let p of t)
86
- if(!(!(0,E.isModelProperty)(p)||p.inherited))switch(p.name){default:a.push(new f.InvalidServicePropertyError(
87
- r.name,p.name,e.file));break;case"name":(o.name=(0,f.getPropertyString)(p))&&s.delete(
88
- p.name);break;case"schema":(o.schema=ee(p.value,e,n,a))&&s.delete(p.name);break;case"\
89
- indexes":(o.indexes=Me(p.value,e,n,a))&&s.delete(p.name);break;case"relations":o.
90
- relations=ge(p.value,e,n,a);break;case"stream":o.stream=Oe(p.value,r,n,a);break}
91
- if(!rt(o))return a.push(new x([...s],e.file)),null;let i=nt(e,o.indexes,o.schema);
92
- return i.length?(a.push(...i),null):o},nt=(e,r,t)=>{let n=t.properties,a=[];for(let{
93
- name:o,columns:s}of r)s.some(p=>!n[p])&&a.push(new N(o,e.file));return a};var re=e=>{let r={},t=[];for(let n in e){let a=e[n];if(!_(a)||(0,d.isExternalDeclaration)(
94
- a))continue;let o={type:G,extras:{}},s=new Set(["engine","tables"]),i=a.file;o.name=
95
- a.name;for(let l of(0,d.getModelMembers)(a))if(!(!(0,Ae.isModelProperty)(l)||l.inherited))
92
+ ables":o.variables=(0,c.getLinkedVariableList)(i,a);break}return ot(o)?o:(a.push(
93
+ new Q([...s],e.file)),null)};var ie=(e,r,t,n)=>{if(!(0,j.isTypeReference)(e))return Fe(e,r,t,n);let a=(0,y.getReferenceType)(
94
+ e,t);return a?Fe(a,r,t,n):null},st=e=>!!e.name&&!!e.schema&&!!e.indexes,Fe=(e,r,t,n)=>de(
95
+ e)?qe(e,r,(0,y.getModelMembers)(e),t,n):(0,j.isTypeObject)(e)?qe(e,r,(0,y.getObjectMembers)(
96
+ e),t,n):null,qe=(e,r,t,n,a)=>{let o={},s=new Set(["name","schema","indexes"]);for(let p of t)
97
+ if(!(!(0,j.isModelProperty)(p)||p.inherited))switch(p.name){default:a.push(new y.InvalidServicePropertyError(
98
+ r.name,p.name,e.file));break;case"name":(o.name=(0,y.getPropertyString)(p))&&s.delete(
99
+ p.name);break;case"schema":(o.schema=se(p.value,e,n,a))&&s.delete(p.name);break;case"\
100
+ indexes":(o.indexes=Re(p.value,e,n,a))&&s.delete(p.name);break;case"relations":o.
101
+ relations=Pe(p.value,e,n,a);break;case"stream":o.stream=He(p.value,r,n,a);break}
102
+ if(!st(o))return a.push(new N([...s],e.file)),null;let i=it(e,o.indexes,o.schema);
103
+ return i.length?(a.push(...i),null):o},it=(e,r,t)=>{let n=t.properties,a=[];for(let{
104
+ name:o,columns:s}of r)s.some(p=>!n[p])&&a.push(new V(o,e.file));return a};var pe=e=>{let r={},t=[];for(let n in e){let a=e[n];if(!X(a)||(0,d.isExternalDeclaration)(
105
+ a))continue;let o={type:K,extras:{}},s=new Set(["engine","tables"]),i=a.file;o.name=
106
+ a.name;for(let l of(0,d.getModelMembers)(a))if(!(!(0,$e.isModelProperty)(l)||l.inherited))
96
107
  switch(l.name){default:t.push(new d.InvalidServicePropertyError(o.name,l.name,i));
97
- break;case"client":break;case"engine":(o.engine=fe(l.value,a,e,t))&&s.delete(l.name);
98
- break;case"tables":(o.tables=ot(l,a,e,t))&&s.delete(l.name);break;case"variables":
108
+ break;case"client":break;case"scalability":(o.scalability=Me(l.value,a,e,t))&&s.
109
+ delete(l.name);break;case"engine":(o.engine=he(l.value,a,e,t))&&s.delete(l.name);
110
+ break;case"tables":(o.tables=lt(l,a,e,t))&&s.delete(l.name);break;case"variables":
99
111
  o.variables=(0,d.getLinkedVariableList)(l,t);break;case"services":o.services=(0,d.getLinkedServiceList)(
100
- l,e,t);break}if(!at(o)){t.push(new A([...s],i));continue}let p=st(a,o.tables);if(p.
112
+ l,e,t);break}if(!pt(o)){t.push(new O([...s],i));continue}let p=mt(a,o.tables);if(p.
101
113
  length){t.push(...p);continue}if(r[a.name]){t.push(new d.DuplicateServiceError(a.
102
- name,i));continue}r[a.name]=o}return{services:r,errors:t}},at=e=>!!e.name&&!!e.tables&&
103
- !!e.extras,ot=(e,r,t,n)=>{let a=(0,d.getPropertyTuple)(e)??[],o=[];for(let s of a){
104
- let i=te(s,r,t,n);i&&o.push(i)}return o},st=(e,r)=>{let t=it(r),n=[];for(let{relations:a,
114
+ name,i));continue}r[a.name]=o}return{services:r,errors:t}},pt=e=>!!e.name&&!!e.tables&&
115
+ !!e.extras,lt=(e,r,t,n)=>{let a=(0,d.getPropertyTuple)(e)??[],o=[];for(let s of a){
116
+ let i=ie(s,r,t,n);i&&o.push(i)}return o},mt=(e,r)=>{let t=ct(r),n=[];for(let{relations:a,
105
117
  schema:o,indexes:s}of r){if(!a)continue;let i=o.properties;for(let p of a){let{sourceTable:l,
106
- sourceColumn:P,targetColumn:Y,targetAlias:ne}=p;i[Y]||n.push(new S(Y,e.file)),i[ne]&&
107
- n.push(new C(ne,e.file));let Z=t[l]?.schema.properties;Z||n.push(new k(l,e.file)),
108
- Z&&!Z[P]&&n.push(new S(P,e.file));let qe=t[l]?.indexes??[];p.sourceIndex=Ce(qe,P),
109
- p.targetIndex=Ce(s,Y)}}return n},Ce=(e,r)=>e.find(({name:t})=>t===r)?.type,it=e=>e.
110
- reduce((r,t)=>({...r,[t.name]:t}),{});var we=e=>_(e)?e.name:null;var Ue=!1,pt=()=>{Ue||((0,ze.registerTriggers)(),(0,Ne.registerTriggers)(),(0,He.createTrigger)(
111
- "@ez4/database",{"metadata:getServices":re,"metadata:getLinkedService":we}),Ue=!0)};0&&(module.exports={IncompleteHandlerError,IncompleteServiceError,IncompleteStreamError,
112
- IncompleteTableError,IncorrectIndexesTypeError,IncorrectRelationsTypeError,IncorrectSchemaTypeError,
113
- IncorrectStreamTypeError,InvalidIndexReferenceError,InvalidIndexTypeError,InvalidIndexesTypeError,
114
- InvalidRelationAliasError,InvalidRelationColumnError,InvalidRelationTableError,InvalidRelationTargetError,
115
- InvalidRelationsTypeError,InvalidSchemaTypeError,InvalidStreamTypeError,ServiceType,
116
- getDatabaseServices,getDatabaseTable,getTableSchema,isDatabaseService,registerTriggers});
118
+ sourceColumn:P,targetColumn:ne,targetAlias:le}=p;i[ne]||n.push(new M(ne,e.file)),
119
+ i[le]&&n.push(new C(le,e.file));let ae=t[l]?.schema.properties;ae||n.push(new w(
120
+ l,e.file)),ae&&!ae[P]&&n.push(new M(P,e.file));let Ke=t[l]?.indexes??[];p.sourceIndex=
121
+ Ve(Ke,P),p.targetIndex=Ve(s,ne)}}return n},Ve=(e,r)=>e.find(({name:t})=>t===r)?.
122
+ type,ct=e=>e.reduce((r,t)=>({...r,[t.name]:t}),{});var Ge=e=>X(e)?e.name:null;var Qe=!1,dt=()=>{Qe||((0,Be.registerTriggers)(),(0,_e.registerTriggers)(),(0,Je.createTrigger)(
123
+ "@ez4/database",{"metadata:getServices":pe,"metadata:getLinkedService":Ge}),Qe=!0)};0&&(module.exports={IncompleteEngineError,IncompleteHandlerError,IncompleteScalabilityError,
124
+ IncompleteServiceError,IncompleteStreamError,IncompleteTableError,IncorrectIndexesTypeError,
125
+ IncorrectRelationsTypeError,IncorrectSchemaTypeError,IncorrectStreamTypeError,InvalidIndexReferenceError,
126
+ InvalidIndexTypeError,InvalidIndexesTypeError,InvalidRelationAliasError,InvalidRelationColumnError,
127
+ InvalidRelationTableError,InvalidRelationTargetError,InvalidRelationsTypeError,InvalidSchemaTypeError,
128
+ InvalidStreamTypeError,ServiceType,getDatabaseServices,getDatabaseTable,getTableSchema,
129
+ isDatabaseService,registerTriggers});
117
130
  //# sourceMappingURL=library.cjs.map
package/dist/library.d.ts CHANGED
@@ -3,6 +3,8 @@ export * from './metadata/service.js';
3
3
  export * from './metadata/table.js';
4
4
  export * from './metadata/schema.js';
5
5
  export * from './errors/service.js';
6
+ export * from './errors/scalability.js';
7
+ export * from './errors/engine.js';
6
8
  export * from './errors/table.js';
7
9
  export * from './errors/schema.js';
8
10
  export * from './errors/relations.js';
package/dist/library.mjs CHANGED
@@ -1,113 +1,124 @@
1
- import{registerTriggers as Xt}from"@ez4/common/library";import{registerTriggers as Yt}from"@ez4/schema/library";
2
- import{createTrigger as Zt}from"@ez4/project/library";import{DuplicateServiceError as Ht,InvalidServicePropertyError as qt,isExternalDeclaration as Vt,
3
- getLinkedServiceList as Ft,getLinkedVariableList as Qt,getPropertyTuple as $t,getModelMembers as Gt}from"@ez4/common/library";
4
- import{isModelProperty as Bt}from"@ez4/reflection";import{IncorrectTypeError as ye,InvalidTypeError as xe,TypeError as S}from"@ez4/common/library";
5
- var b=class extends xe{constructor(r){super("Invalid table relations type",void 0,
6
- "Database.Relations",r)}},f=class extends ye{constructor(t,n){super("Incorrect t\
7
- able relations type",t,"Database.Relations",n);this.schemaType=t}},y=class extends S{constructor(t,n){
1
+ import{registerTriggers as sr}from"@ez4/common/library";import{registerTriggers as ir}from"@ez4/schema/library";
2
+ import{createTrigger as pr}from"@ez4/project/library";import{DuplicateServiceError as Kt,InvalidServicePropertyError as Wt,isExternalDeclaration as Xt,
3
+ getLinkedServiceList as Yt,getLinkedVariableList as Zt,getPropertyTuple as Lt,getModelMembers as er}from"@ez4/common/library";
4
+ import{isModelProperty as tr}from"@ez4/reflection";var H="@ez4/database",lr=e=>e.type===H;import{IncompleteTypeError as Se}from"@ez4/common/library";var b=class extends Se{constructor(r,t){
5
+ super("Incomplete database service",r,t)}};import{IncorrectTypeError as De,InvalidTypeError as he,TypeError as M}from"@ez4/common/library";
6
+ var T=class extends he{constructor(r){super("Invalid table relations type",void 0,
7
+ "Database.Relations",r)}},f=class extends De{constructor(t,n){super("Incorrect t\
8
+ able relations type",t,"Database.Relations",n);this.schemaType=t}},y=class extends M{constructor(t,n){
8
9
  super(`Target ${t} must follow the pattern 'column@alias'.`,n);this.relationSource=
9
- t}},x=class extends S{constructor(t,n){super(`Relation table ${t} don't exists.`,
10
- n);this.relationTable=t}},T=class extends S{constructor(t,n){super(`Relation col\
11
- umn ${t} don't exists.`,n);this.relationColumn=t}},g=class extends S{constructor(t,n){
10
+ t}},x=class extends M{constructor(t,n){super(`Relation table ${t} don't exists.`,
11
+ n);this.relationTable=t}},d=class extends M{constructor(t,n){super(`Relation col\
12
+ umn ${t} don't exists.`,n);this.relationColumn=t}},g=class extends M{constructor(t,n){
12
13
  super(`Relation alias ${t} can't override table columns.`,n);this.relationAlias=
13
- t}};import{IncompleteTypeError as ge}from"@ez4/common/library";var I=class extends ge{constructor(r,t){
14
- super("Incomplete database service",r,t)}};var U="@ez4/database",nr=e=>e.type===U;import{isModelProperty as Re,isTypeObject as ke,isTypeReference as Ce}from"@ez4/reflection";
15
- import{InvalidServicePropertyError as Ae,getModelMembers as we,getObjectMembers as Ue,
16
- getPropertyString as ze,getPropertyStringIn as u,getReferenceType as Ne}from"@ez4/common/library";import{IncompleteTypeError as Se}from"@ez4/common/library";var c=class extends Se{constructor(r,t){
17
- super("Incomplete database table",r,t)}};import{hasHeritageType as m,isClassDeclaration as Ie,isModelDeclaration as N}from"@ez4/common/library";
18
- import{isTypeCallback as Me,isTypeFunction as he}from"@ez4/reflection";var M=e=>Ie(
19
- e)&&m(e,"Database.Service"),H=e=>N(e)&&m(e,"Database.Engine"),q=e=>N(e)&&m(e,"Da\
20
- tabase.Table"),V=e=>Me(e)||he(e),F=e=>m(e,"Database.Relations"),Q=e=>m(e,"Databa\
21
- se.Indexes"),$=e=>m(e,"Database.Schema"),G=e=>m(e,"Database.Stream");var B;(e=>{})(B||={});var K=(e,r,t,n)=>{if(!Ce(e))return _(e,r,n);let a=Ne(e,t);return a?_(a,r,n):null},
22
- He=e=>!!e.name&&!!e.parametersMode&&!!e.transactionMode&&!!e.orderMode,_=(e,r,t)=>H(
23
- e)?J(e,r,we(e),t):ke(e)?J(e,r,Ue(e),t):null,J=(e,r,t,n)=>{let a={},o=new Set(["n\
24
- ame","parametersMode","transactionMode","insensitiveMode","paginationMode","orde\
25
- rMode"]);for(let s of t)if(!(!Re(s)||s.inherited))switch(s.name){default:n.push(
26
- new Ae(r.name,s.name,e.file));break;case"name":(a.name=ze(s))&&o.delete(s.name);
27
- break;case"parametersMode":(a.parametersMode=u(s,["index","both"]))&&o.delete(s.
28
- name);break;case"transactionMode":(a.transactionMode=u(s,["static","interactive"]))&&
29
- o.delete(s.name);break;case"insensitiveMode":(a.insensitiveMode=u(s,["unsupporte\
30
- d","enabled"]))&&o.delete(s.name);break;case"paginationMode":(a.paginationMode=u(
31
- s,["cursor","offset"]))&&o.delete(s.name);break;case"orderMode":(a.orderMode=u(s,
32
- ["any","index"]))&&o.delete(s.name);break}return He(a)?a:(n.push(new c([...o],e.
33
- file)),null)};import{InvalidServicePropertyError as jt,getModelMembers as Ot,getObjectMembers as Rt,
34
- getPropertyString as kt,getReferenceType as Ct}from"@ez4/common/library";import{
35
- isModelProperty as At,isTypeObject as wt,isTypeReference as Ut}from"@ez4/reflection";import{IncorrectTypeError as qe,InvalidTypeError as Ve,TypeError as W}from"@ez4/common/library";
36
- var h=class extends Ve{constructor(r){super("Invalid table indexes type",void 0,
37
- "Database.Indexes",r)}},v=class extends qe{constructor(t,n){super("Incorrect tab\
38
- le indexes type",t,"Database.Indexes",n);this.schemaType=t}},D=class extends W{constructor(t,n){
14
+ t}};import{InvalidServicePropertyError as Oe,getModelMembers as ke,getPropertyNumber as Re,
15
+ getObjectMembers as Ae,getReferenceType as we}from"@ez4/common/library";import{isModelProperty as Ce,
16
+ isTypeObject as ze,isTypeReference as Ue}from"@ez4/reflection";import{isAnyNumber as F}from"@ez4/utils";import{IncompleteTypeError as ve}from"@ez4/common/library";var I=class extends ve{constructor(r,t){
17
+ super("Incomplete database scalability",r,t)}};import{hasHeritageType as m,isClassDeclaration as Ee,isModelDeclaration as V}from"@ez4/common/library";
18
+ import{isTypeCallback as je,isTypeFunction as Pe}from"@ez4/reflection";var S=e=>Ee(
19
+ e)&&m(e,"Database.Service"),D=e=>V(e)&&m(e,"Database.Engine"),$=e=>V(e)&&m(e,"Da\
20
+ tabase.Table"),G=e=>je(e)||Pe(e),Q=e=>m(e,"Database.Relations"),B=e=>m(e,"Databa\
21
+ se.Indexes"),_=e=>m(e,"Database.Schema"),J=e=>m(e,"Database.Stream");var X=(e,r,t,n)=>{if(!Ue(e))return K(e,r,n);let a=we(e,t);return a?K(a,r,n):null},
22
+ Ne=e=>F(e.minCapacity)&&F(e.maxCapacity),K=(e,r,t)=>D(e)?W(e,r,ke(e),t):ze(e)?W(
23
+ e,r,Ae(e),t):null,W=(e,r,t,n)=>{let a={},o=new Set(["minCapacity","maxCapacity"]);
24
+ for(let s of t)if(!(!Ce(s)||s.inherited))switch(s.name){default:n.push(new Oe(r.
25
+ name,s.name,e.file));break;case"minCapacity":case"maxCapacity":let i=Re(s);F(i)&&
26
+ (a[s.name]=i,o.delete(s.name));break}return Ne(a)?a:(n.push(new I([...o],e.file)),
27
+ null)};import{isModelProperty as Fe,isTypeObject as qe,isTypeReference as Ve}from"@ez4/reflection";
28
+ import{InvalidServicePropertyError as $e,getModelMembers as Ge,getObjectMembers as Qe,
29
+ getPropertyString as Be,getPropertyStringIn as u,getReferenceType as _e}from"@ez4/common/library";import{IncompleteTypeError as He}from"@ez4/common/library";var h=class extends He{constructor(r,t){
30
+ super("Incomplete database engine",r,t)}};var L=(e,r,t,n)=>{if(!Ve(e))return Y(e,r,n);let a=_e(e,t);return a?Y(a,r,n):null},
31
+ Je=e=>!!e.name&&!!e.parametersMode&&!!e.transactionMode&&!!e.insensitiveMode&&!!e.
32
+ paginationMode&&!!e.orderMode,Y=(e,r,t)=>D(e)?Z(e,r,Ge(e),t):qe(e)?Z(e,r,Qe(e),t):
33
+ null,Z=(e,r,t,n)=>{let a={},o=new Set(["name","parametersMode","transactionMode",
34
+ "insensitiveMode","paginationMode","orderMode"]);for(let s of t)if(!(!Fe(s)||s.inherited))
35
+ switch(s.name){default:n.push(new $e(r.name,s.name,e.file));break;case"name":(a.
36
+ name=Be(s))&&o.delete(s.name);break;case"parametersMode":(a.parametersMode=u(s,[
37
+ "index","both"]))&&o.delete(s.name);break;case"transactionMode":(a.transactionMode=
38
+ u(s,["static","interactive"]))&&o.delete(s.name);break;case"insensitiveMode":(a.
39
+ insensitiveMode=u(s,["unsupported","enabled"]))&&o.delete(s.name);break;case"pag\
40
+ inationMode":(a.paginationMode=u(s,["cursor","offset"]))&&o.delete(s.name);break;case"\
41
+ orderMode":(a.orderMode=u(s,["any","index"]))&&o.delete(s.name);break}return Je(
42
+ a)?a:(n.push(new h([...o],e.file)),null)};import{InvalidServicePropertyError as Ht,getModelMembers as Ft,getObjectMembers as qt,
43
+ getPropertyString as Vt,getReferenceType as $t}from"@ez4/common/library";import{
44
+ isModelProperty as Gt,isTypeObject as Qt,isTypeReference as Bt}from"@ez4/reflection";import{IncompleteTypeError as Ke}from"@ez4/common/library";var v=class extends Ke{constructor(r,t){
45
+ super("Incomplete database table",r,t)}};import{IncorrectTypeError as We,InvalidTypeError as Xe,TypeError as ee}from"@ez4/common/library";
46
+ var E=class extends Xe{constructor(r){super("Invalid table indexes type",void 0,
47
+ "Database.Indexes",r)}},j=class extends We{constructor(t,n){super("Incorrect tab\
48
+ le indexes type",t,"Database.Indexes",n);this.schemaType=t}},P=class extends ee{constructor(t,n){
39
49
  super(`Invalid index type, ${t} must follow one of the Index options.`,n);this.indexName=
40
- t}},E=class extends W{constructor(t,n){super(`Invalid index reference, ${t} must\
41
- be valid column.`,n);this.indexName=t}};import{isModelDeclaration as Fe,getModelMembers as Qe,getObjectMembers as $e,getPropertyString as Ge,
42
- getReferenceType as Be}from"@ez4/common/library";import{isModelProperty as _e,isTypeObject as Je,
43
- isTypeReference as Ke}from"@ez4/reflection";var Z=(e,r,t,n)=>{if(!Ke(e))return X(e,r,n);let a=Be(e,t);return a?X(a,r,n):null},
44
- X=(e,r,t)=>Je(e)?Y(e,$e(e),t):Fe(e)?F(e)?Y(e,Qe(e),t):(t.push(new f(e.name,e.file)),
45
- null):(t.push(new b(r.file)),null),Y=(e,r,t)=>{let n=[];for(let a of r){if(!_e(a)||
46
- a.inherited)continue;let o=Ge(a),s=a.name;if(!o)return t.push(new y(s,e.file)),null;
47
- let[i,p]=s.split("@",2),[l,d]=o.split(":",2);n.push({sourceTable:l,sourceColumn:d,
48
- targetColumn:i,targetAlias:p})}return n};import{isModelDeclaration as We,getModelMembers as Xe,getObjectMembers as Ye,getPropertyString as Ze,
49
- getReferenceType as Le}from"@ez4/common/library";import{isModelProperty as et,isTypeObject as tt,
50
- isTypeReference as rt}from"@ez4/reflection";var te=(e,r,t,n)=>{if(!rt(e))return L(e,r,n);let a=Le(e,t);return a?L(a,r,n):null},
51
- L=(e,r,t)=>tt(e)?ee(e,Ye(e),t):We(e)?Q(e)?ee(e,Xe(e),t):(t.push(new v(e.name,e.file)),
52
- null):(t.push(new h(r.file)),null),ee=(e,r,t)=>{let n=[];for(let a of r){if(!et(
53
- a)||a.inherited)continue;let o=a.name,s=Ze(a);switch(s){case"primary":case"secon\
54
- dary":case"unique":case"ttl":n.push({name:o,columns:o.split(":"),type:s});break;default:
55
- return t.push(new D(o,e.file)),null}}return n};import{getReferenceType as ot,isModelDeclaration as st}from"@ez4/common/library";
56
- import{getObjectSchema as it,isObjectSchema as pt}from"@ez4/schema/library";import{
57
- isTypeObject as lt,isTypeReference as mt}from"@ez4/reflection";import{IncorrectTypeError as nt,InvalidTypeError as at}from"@ez4/common/library";
58
- var P=class extends at{constructor(r){super("Invalid table schema type",void 0,"\
59
- Database.Schema",r)}},j=class extends nt{constructor(t,n){super("Incorrect table\
60
- schema type",t,"Database.Schema",n);this.schemaType=t}};var ae=(e,r,t,n)=>{if(!mt(e))return re(e,r,t,n);let a=ot(e,t);return a?re(a,r,t,
61
- n):null},re=(e,r,t,n)=>lt(e)?ne(e,t):st(e)?$(e)?ne(e,t):(n.push(new j(e.name,e.file)),
62
- null):(n.push(new P(r.file)),null),ne=(e,r)=>{let t=it(e,r);return t&&pt(t)?t:null};import{InvalidServicePropertyError as ft,isModelDeclaration as yt,getLinkedVariableList as xt,
63
- getModelMembers as gt,getObjectMembers as St,getPropertyNumber as It,getServiceListener as Mt,
64
- getReferenceType as ht}from"@ez4/common/library";import{isModelProperty as vt,isTypeObject as Dt,
65
- isTypeReference as Et}from"@ez4/reflection";import{IncompleteTypeError as ct,IncorrectTypeError as dt,InvalidTypeError as Tt}from"@ez4/common/library";
66
- var O=class extends ct{constructor(r,t){super("Incomplete table stream",r,t)}},R=class extends Tt{constructor(r){
67
- super("Invalid table stream type",void 0,"Database.Stream",r)}},k=class extends dt{constructor(t,n){
68
- super("Incorrect table stream type",t,"Database.Stream",n);this.streamType=t}};import{IncompleteTypeError as ut}from"@ez4/common/library";var C=class extends ut{constructor(r,t){
69
- super("Incomplete stream handler",r,t)}};var oe=(e,r,t)=>{if(!V(e))return null;let n={},a=new Set(["name","file","change"]);
50
+ t}},O=class extends ee{constructor(t,n){super(`Invalid index reference, ${t} mus\
51
+ t be valid column.`,n);this.indexName=t}};import{isModelDeclaration as Ye,getModelMembers as Ze,getObjectMembers as Le,getPropertyString as et,
52
+ getReferenceType as tt}from"@ez4/common/library";import{isModelProperty as rt,isTypeObject as nt,
53
+ isTypeReference as at}from"@ez4/reflection";var ne=(e,r,t,n)=>{if(!at(e))return te(e,r,n);let a=tt(e,t);return a?te(a,r,n):null},
54
+ te=(e,r,t)=>nt(e)?re(e,Le(e),t):Ye(e)?Q(e)?re(e,Ze(e),t):(t.push(new f(e.name,e.
55
+ file)),null):(t.push(new T(r.file)),null),re=(e,r,t)=>{let n=[];for(let a of r){
56
+ if(!rt(a)||a.inherited)continue;let o=et(a),s=a.name;if(!o)return t.push(new y(s,
57
+ e.file)),null;let[i,p]=s.split("@",2),[l,c]=o.split(":",2);n.push({sourceTable:l,
58
+ sourceColumn:c,targetColumn:i,targetAlias:p})}return n};import{isModelDeclaration as ot,getModelMembers as st,getObjectMembers as it,getPropertyString as pt,
59
+ getReferenceType as lt}from"@ez4/common/library";import{isModelProperty as mt,isTypeObject as ct,
60
+ isTypeReference as dt}from"@ez4/reflection";var se=(e,r,t,n)=>{if(!dt(e))return ae(e,r,n);let a=lt(e,t);return a?ae(a,r,n):null},
61
+ ae=(e,r,t)=>ct(e)?oe(e,it(e),t):ot(e)?B(e)?oe(e,st(e),t):(t.push(new j(e.name,e.
62
+ file)),null):(t.push(new E(r.file)),null),oe=(e,r,t)=>{let n=[];for(let a of r){
63
+ if(!mt(a)||a.inherited)continue;let o=a.name,s=pt(a);switch(s){case"primary":case"\
64
+ secondary":case"unique":case"ttl":n.push({name:o,columns:o.split(":"),type:s});break;default:
65
+ return t.push(new P(o,e.file)),null}}return n};import{getReferenceType as Tt,isModelDeclaration as ft}from"@ez4/common/library";
66
+ import{getObjectSchema as yt,isObjectSchema as xt}from"@ez4/schema/library";import{
67
+ isTypeObject as gt,isTypeReference as Mt}from"@ez4/reflection";import{IncorrectTypeError as ut,InvalidTypeError as bt}from"@ez4/common/library";
68
+ var k=class extends bt{constructor(r){super("Invalid table schema type",void 0,"\
69
+ Database.Schema",r)}},R=class extends ut{constructor(t,n){super("Incorrect table\
70
+ schema type",t,"Database.Schema",n);this.schemaType=t}};var le=(e,r,t,n)=>{if(!Mt(e))return ie(e,r,t,n);let a=Tt(e,t);return a?ie(a,r,t,
71
+ n):null},ie=(e,r,t,n)=>gt(e)?pe(e,t):ft(e)?_(e)?pe(e,t):(n.push(new R(e.name,e.file)),
72
+ null):(n.push(new k(r.file)),null),pe=(e,r)=>{let t=yt(e,r);return t&&xt(t)?t:null};import{InvalidServicePropertyError as Et,isModelDeclaration as jt,getLinkedVariableList as Pt,
73
+ getModelMembers as Ot,getObjectMembers as kt,getPropertyNumber as Rt,getServiceListener as At,
74
+ getReferenceType as wt}from"@ez4/common/library";import{isModelProperty as Ct,isTypeObject as zt,
75
+ isTypeReference as Ut}from"@ez4/reflection";import{IncompleteTypeError as It,IncorrectTypeError as St,InvalidTypeError as Dt}from"@ez4/common/library";
76
+ var A=class extends It{constructor(r,t){super("Incomplete table stream",r,t)}},w=class extends Dt{constructor(r){
77
+ super("Invalid table stream type",void 0,"Database.Stream",r)}},C=class extends St{constructor(t,n){
78
+ super("Incorrect table stream type",t,"Database.Stream",n);this.streamType=t}};import{IncompleteTypeError as ht}from"@ez4/common/library";var z=class extends ht{constructor(r,t){
79
+ super("Incomplete stream handler",r,t)}};var me=(e,r,t)=>{if(!G(e))return null;let n={},a=new Set(["name","file","change"]);
70
80
  return e.description&&(n.description=e.description),(n.name=e.name)&&a.delete("n\
71
81
  ame"),(n.file=e.file)&&a.delete("file"),e.parameters&&a.delete("change"),a.size===
72
- 0&&bt(n)?n:(t.push(new C([...a],e.file)),null)},bt=e=>!!e.name&&!!e.file;var pe=(e,r,t,n)=>{if(!Et(e))return se(e,r,t,n);let a=ht(e,t);return a?se(a,r,t,
73
- n):null},Pt=e=>!!e.handler,se=(e,r,t,n)=>Dt(e)?ie(e,r,St(e),t,n):yt(e)?G(e)?ie(e,
74
- r,gt(e),t,n):(n.push(new k(e.name,e.file)),null):(n.push(new R(r.file)),null),ie=(e,r,t,n,a)=>{
75
- let o={},s=new Set(["handler"]);for(let i of t)if(!(!vt(i)||i.inherited))switch(i.
76
- name){default:a.push(new ft(r.name,i.name,e.file));break;case"handler":o.handler=
77
- oe(i.value,n,a);break;case"listener":o.listener=Mt(i.value,a);break;case"memory":case"\
78
- logRetention":case"timeout":o[i.name]=It(i);break;case"variables":o.variables=xt(
79
- i,a);break}return Pt(o)?o:(a.push(new O([...s],e.file)),null)};var ce=(e,r,t,n)=>{if(!Ut(e))return le(e,r,t,n);let a=Ct(e,t);return a?le(a,r,t,
80
- n):null},zt=e=>!!e.name&&!!e.schema&&!!e.indexes,le=(e,r,t,n)=>q(e)?me(e,r,Ot(e),
81
- t,n):wt(e)?me(e,r,Rt(e),t,n):null,me=(e,r,t,n,a)=>{let o={},s=new Set(["name","s\
82
- chema","indexes"]);for(let p of t)if(!(!At(p)||p.inherited))switch(p.name){default:
83
- a.push(new jt(r.name,p.name,e.file));break;case"name":(o.name=kt(p))&&s.delete(p.
84
- name);break;case"schema":(o.schema=ae(p.value,e,n,a))&&s.delete(p.name);break;case"\
85
- indexes":(o.indexes=te(p.value,e,n,a))&&s.delete(p.name);break;case"relations":o.
86
- relations=Z(p.value,e,n,a);break;case"stream":o.stream=pe(p.value,r,n,a);break}if(!zt(
87
- o))return a.push(new c([...s],e.file)),null;let i=Nt(e,o.indexes,o.schema);return i.
88
- length?(a.push(...i),null):o},Nt=(e,r,t)=>{let n=t.properties,a=[];for(let{name:o,
89
- columns:s}of r)s.some(p=>!n[p])&&a.push(new E(o,e.file));return a};var Te=e=>{let r={},t=[];for(let n in e){let a=e[n];if(!M(a)||Vt(a))continue;let o={
90
- type:U,extras:{}},s=new Set(["engine","tables"]),i=a.file;o.name=a.name;for(let l of Gt(
91
- a))if(!(!Bt(l)||l.inherited))switch(l.name){default:t.push(new qt(o.name,l.name,
92
- i));break;case"client":break;case"engine":(o.engine=K(l.value,a,e,t))&&s.delete(
93
- l.name);break;case"tables":(o.tables=Jt(l,a,e,t))&&s.delete(l.name);break;case"v\
94
- ariables":o.variables=Qt(l,t);break;case"services":o.services=Ft(l,e,t);break}if(!_t(
95
- o)){t.push(new I([...s],i));continue}let p=Kt(a,o.tables);if(p.length){t.push(...p);
96
- continue}if(r[a.name]){t.push(new Ht(a.name,i));continue}r[a.name]=o}return{services:r,
97
- errors:t}},_t=e=>!!e.name&&!!e.tables&&!!e.extras,Jt=(e,r,t,n)=>{let a=$t(e)??[],
98
- o=[];for(let s of a){let i=ce(s,r,t,n);i&&o.push(i)}return o},Kt=(e,r)=>{let t=Wt(
99
- r),n=[];for(let{relations:a,schema:o,indexes:s}of r){if(!a)continue;let i=o.properties;
100
- for(let p of a){let{sourceTable:l,sourceColumn:d,targetColumn:A,targetAlias:z}=p;
101
- i[A]||n.push(new T(A,e.file)),i[z]&&n.push(new g(z,e.file));let w=t[l]?.schema.properties;
102
- w||n.push(new x(l,e.file)),w&&!w[d]&&n.push(new T(d,e.file));let fe=t[l]?.indexes??
103
- [];p.sourceIndex=de(fe,d),p.targetIndex=de(s,A)}}return n},de=(e,r)=>e.find(({name:t})=>t===
104
- r)?.type,Wt=e=>e.reduce((r,t)=>({...r,[t.name]:t}),{});var ue=e=>M(e)?e.name:null;var be=!1,Xn=()=>{be||(Xt(),Yt(),Zt("@ez4/database",{"metadata:getServices":Te,"\
105
- metadata:getLinkedService":ue}),be=!0)};export{C as IncompleteHandlerError,I as IncompleteServiceError,O as IncompleteStreamError,
106
- c as IncompleteTableError,v as IncorrectIndexesTypeError,f as IncorrectRelationsTypeError,
107
- j as IncorrectSchemaTypeError,k as IncorrectStreamTypeError,E as InvalidIndexReferenceError,
108
- D as InvalidIndexTypeError,h as InvalidIndexesTypeError,g as InvalidRelationAliasError,
109
- T as InvalidRelationColumnError,x as InvalidRelationTableError,y as InvalidRelationTargetError,
110
- b as InvalidRelationsTypeError,P as InvalidSchemaTypeError,R as InvalidStreamTypeError,
111
- U as ServiceType,Te as getDatabaseServices,ce as getDatabaseTable,ae as getTableSchema,
112
- nr as isDatabaseService,Xn as registerTriggers};
82
+ 0&&vt(n)?n:(t.push(new z([...a],e.file)),null)},vt=e=>!!e.name&&!!e.file;var ue=(e,r,t,n)=>{if(!Ut(e))return ce(e,r,t,n);let a=wt(e,t);return a?ce(a,r,t,
83
+ n):null},Nt=e=>!!e.handler,ce=(e,r,t,n)=>zt(e)?de(e,r,kt(e),t,n):jt(e)?J(e)?de(e,
84
+ r,Ot(e),t,n):(n.push(new C(e.name,e.file)),null):(n.push(new w(r.file)),null),de=(e,r,t,n,a)=>{
85
+ let o={},s=new Set(["handler"]);for(let i of t)if(!(!Ct(i)||i.inherited))switch(i.
86
+ name){default:a.push(new Et(r.name,i.name,e.file));break;case"handler":o.handler=
87
+ me(i.value,n,a);break;case"listener":o.listener=At(i.value,a);break;case"memory":case"\
88
+ logRetention":case"timeout":o[i.name]=Rt(i);break;case"variables":o.variables=Pt(
89
+ i,a);break}return Nt(o)?o:(a.push(new A([...s],e.file)),null)};var fe=(e,r,t,n)=>{if(!Bt(e))return be(e,r,t,n);let a=$t(e,t);return a?be(a,r,t,
90
+ n):null},_t=e=>!!e.name&&!!e.schema&&!!e.indexes,be=(e,r,t,n)=>$(e)?Te(e,r,Ft(e),
91
+ t,n):Qt(e)?Te(e,r,qt(e),t,n):null,Te=(e,r,t,n,a)=>{let o={},s=new Set(["name","s\
92
+ chema","indexes"]);for(let p of t)if(!(!Gt(p)||p.inherited))switch(p.name){default:
93
+ a.push(new Ht(r.name,p.name,e.file));break;case"name":(o.name=Vt(p))&&s.delete(p.
94
+ name);break;case"schema":(o.schema=le(p.value,e,n,a))&&s.delete(p.name);break;case"\
95
+ indexes":(o.indexes=se(p.value,e,n,a))&&s.delete(p.name);break;case"relations":o.
96
+ relations=ne(p.value,e,n,a);break;case"stream":o.stream=ue(p.value,r,n,a);break}
97
+ if(!_t(o))return a.push(new v([...s],e.file)),null;let i=Jt(e,o.indexes,o.schema);
98
+ return i.length?(a.push(...i),null):o},Jt=(e,r,t)=>{let n=t.properties,a=[];for(let{
99
+ name:o,columns:s}of r)s.some(p=>!n[p])&&a.push(new O(o,e.file));return a};var xe=e=>{let r={},t=[];for(let n in e){let a=e[n];if(!S(a)||Xt(a))continue;let o={
100
+ type:H,extras:{}},s=new Set(["engine","tables"]),i=a.file;o.name=a.name;for(let l of er(
101
+ a))if(!(!tr(l)||l.inherited))switch(l.name){default:t.push(new Wt(o.name,l.name,
102
+ i));break;case"client":break;case"scalability":(o.scalability=X(l.value,a,e,t))&&
103
+ s.delete(l.name);break;case"engine":(o.engine=L(l.value,a,e,t))&&s.delete(l.name);
104
+ break;case"tables":(o.tables=nr(l,a,e,t))&&s.delete(l.name);break;case"variables":
105
+ o.variables=Zt(l,t);break;case"services":o.services=Yt(l,e,t);break}if(!rr(o)){t.
106
+ push(new b([...s],i));continue}let p=ar(a,o.tables);if(p.length){t.push(...p);continue}
107
+ if(r[a.name]){t.push(new Kt(a.name,i));continue}r[a.name]=o}return{services:r,errors:t}},
108
+ rr=e=>!!e.name&&!!e.tables&&!!e.extras,nr=(e,r,t,n)=>{let a=Lt(e)??[],o=[];for(let s of a){
109
+ let i=fe(s,r,t,n);i&&o.push(i)}return o},ar=(e,r)=>{let t=or(r),n=[];for(let{relations:a,
110
+ schema:o,indexes:s}of r){if(!a)continue;let i=o.properties;for(let p of a){let{sourceTable:l,
111
+ sourceColumn:c,targetColumn:U,targetAlias:q}=p;i[U]||n.push(new d(U,e.file)),i[q]&&
112
+ n.push(new g(q,e.file));let N=t[l]?.schema.properties;N||n.push(new x(l,e.file)),
113
+ N&&!N[c]&&n.push(new d(c,e.file));let Ie=t[l]?.indexes??[];p.sourceIndex=ye(Ie,c),
114
+ p.targetIndex=ye(s,U)}}return n},ye=(e,r)=>e.find(({name:t})=>t===r)?.type,or=e=>e.
115
+ reduce((r,t)=>({...r,[t.name]:t}),{});var ge=e=>S(e)?e.name:null;var Me=!1,sa=()=>{Me||(sr(),ir(),pr("@ez4/database",{"metadata:getServices":xe,"\
116
+ metadata:getLinkedService":ge}),Me=!0)};export{h as IncompleteEngineError,z as IncompleteHandlerError,I as IncompleteScalabilityError,
117
+ b as IncompleteServiceError,A as IncompleteStreamError,v as IncompleteTableError,
118
+ j as IncorrectIndexesTypeError,f as IncorrectRelationsTypeError,R as IncorrectSchemaTypeError,
119
+ C as IncorrectStreamTypeError,O as InvalidIndexReferenceError,P as InvalidIndexTypeError,
120
+ E as InvalidIndexesTypeError,g as InvalidRelationAliasError,d as InvalidRelationColumnError,
121
+ x as InvalidRelationTableError,y as InvalidRelationTargetError,T as InvalidRelationsTypeError,
122
+ k as InvalidSchemaTypeError,w as InvalidStreamTypeError,H as ServiceType,xe as getDatabaseServices,
123
+ fe as getDatabaseTable,le as getTableSchema,lr as isDatabaseService,sa as registerTriggers};
113
124
  //# sourceMappingURL=library.mjs.map
@@ -0,0 +1,3 @@
1
+ import type { AllType, SourceMap, TypeModel } from '@ez4/reflection';
2
+ import { DatabaseScalability } from '../types/scalability.js';
3
+ export declare const getDatabaseScalability: (type: AllType, parent: TypeModel, reflection: SourceMap, errorList: Error[]) => DatabaseScalability | null;
@@ -52,6 +52,13 @@ export declare namespace Database {
52
52
  * Service engine.
53
53
  */
54
54
  type Engine = DatabaseEngine;
55
+ /**
56
+ * Service scalability configuration.
57
+ */
58
+ interface Scalability {
59
+ minCapacity: number;
60
+ maxCapacity: number;
61
+ }
55
62
  /**
56
63
  * Table stream.
57
64
  */
@@ -119,6 +126,10 @@ export declare namespace Database {
119
126
  * Describe all available tables for the service.
120
127
  */
121
128
  abstract tables: Table<any>[];
129
+ /**
130
+ * Scalability configuration.
131
+ */
132
+ scalability: Scalability;
122
133
  /**
123
134
  * Service client.
124
135
  */
@@ -0,0 +1,4 @@
1
+ export type DatabaseScalability = {
2
+ minCapacity: number;
3
+ maxCapacity: number;
4
+ };
@@ -1,9 +1,11 @@
1
1
  import type { ServiceMetadata } from '@ez4/project/library';
2
+ import type { DatabaseScalability } from './scalability.js';
2
3
  import type { DatabaseEngine } from './engine.js';
3
4
  import type { DatabaseTable } from './table.js';
4
5
  export declare const ServiceType = "@ez4/database";
5
6
  export type DatabaseService = ServiceMetadata & {
6
7
  type: typeof ServiceType;
8
+ scalability?: DatabaseScalability | null;
7
9
  engine: DatabaseEngine;
8
10
  tables: DatabaseTable[];
9
11
  name: string;
package/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.20.0",
4
+ "version": "0.21.0",
5
5
  "author": "Silas B.",
6
6
  "license": "MIT",
7
7
  "type": "module",
@@ -42,10 +42,10 @@
42
42
  "live:publish": "npm run test && npm publish --access public"
43
43
  },
44
44
  "dependencies": {
45
- "@ez4/common": "^0.20.0",
46
- "@ez4/project": "^0.20.0",
47
- "@ez4/reflection": "^0.20.0",
48
- "@ez4/schema": "^0.20.0",
49
- "@ez4/utils": "^0.20.0"
45
+ "@ez4/common": "^0.21.0",
46
+ "@ez4/project": "^0.21.0",
47
+ "@ez4/reflection": "^0.21.0",
48
+ "@ez4/schema": "^0.21.0",
49
+ "@ez4/utils": "^0.21.0"
50
50
  }
51
51
  }