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