@ez4/database 0.17.1 → 0.18.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 +78 -75
- package/dist/library.mjs +85 -83
- package/dist/main.cjs +6 -5
- package/dist/main.d.ts +2 -1
- package/dist/main.mjs +3 -2
- package/dist/services/client.d.ts +4 -3
- package/dist/services/database.d.ts +6 -2
- package/dist/services/engine.d.ts +8 -0
- package/dist/services/parameters.d.ts +18 -0
- package/dist/services/query.d.ts +2 -2
- package/dist/services/transaction.d.ts +16 -12
- package/dist/types/engine.d.ts +2 -1
- package/dist/types/stream.d.ts +1 -0
- package/package.json +6 -6
package/dist/library.cjs
CHANGED
|
@@ -1,107 +1,110 @@
|
|
|
1
1
|
"use strict";var L=Object.defineProperty;var $e=Object.getOwnPropertyDescriptor;var qe=Object.getOwnPropertyNames;var Ve=Object.prototype.hasOwnProperty;var Ue=(e,t)=>{for(var r in t)L(e,r,{get:t[r],enumerable:!0})},_e=(e,t,r,n)=>{if(t&&
|
|
2
|
-
typeof t=="object"||typeof t=="function")for(let
|
|
3
|
-
L(e,
|
|
2
|
+
typeof t=="object"||typeof t=="function")for(let a of qe(t))!Ve.call(e,a)&&a!==r&&
|
|
3
|
+
L(e,a,{get:()=>t[a],enumerable:!(n=$e(t,a))||n.enumerable});return e};var Be=e=>_e(L({},"__esModule",{value:!0}),e);var ar={};Ue(ar,{IncompleteHandlerError:()=>_,IncompleteServiceError:()=>R,IncompleteStreamError:()=>q,
|
|
4
4
|
IncompleteTableError:()=>x,IncorrectIndexesTypeError:()=>C,IncorrectRelationsTypeError:()=>w,
|
|
5
5
|
IncorrectSchemaTypeError:()=>$,IncorrectStreamTypeError:()=>U,InvalidIndexReferenceError:()=>H,
|
|
6
|
-
InvalidIndexTypeError:()=>N,InvalidIndexesTypeError:()=>z,InvalidRelationAliasError:()=>
|
|
6
|
+
InvalidIndexTypeError:()=>N,InvalidIndexesTypeError:()=>z,InvalidRelationAliasError:()=>A,
|
|
7
7
|
InvalidRelationColumnError:()=>M,InvalidRelationTableError:()=>O,InvalidRelationTargetError:()=>k,
|
|
8
|
-
InvalidRelationsTypeError:()=>
|
|
8
|
+
InvalidRelationsTypeError:()=>j,InvalidSchemaTypeError:()=>F,InvalidStreamTypeError:()=>V,
|
|
9
9
|
ServiceType:()=>B,getDatabaseServices:()=>te,getDatabaseTable:()=>re,getTableSchema:()=>ee,
|
|
10
|
-
isDatabaseService:()=>Ge,registerTriggers:()=>
|
|
10
|
+
isDatabaseService:()=>Ge,registerTriggers:()=>nr});module.exports=Be(ar);var Ce=require("@ez4/common/library"),Ne=require("@ez4/schema/library"),He=require("@ez4/project/library");var c=require("@ez4/common/library"),Ae=require("@ez4/reflection");var y=require("@ez4/common/library"),j=class extends y.InvalidTypeError{constructor(t){
|
|
11
11
|
super("Invalid table relations type",void 0,"Database.Relations",t)}},w=class extends y.IncorrectTypeError{constructor(r,n){
|
|
12
12
|
super("Incorrect table relations type",r,"Database.Relations",n);this.schemaType=
|
|
13
13
|
r}},k=class extends y.TypeError{constructor(r,n){super(`Target ${r} must follow \
|
|
14
14
|
the pattern 'column@alias'.`,n);this.relationSource=r}},O=class extends y.TypeError{constructor(r,n){
|
|
15
15
|
super(`Relation table ${r} don't exists.`,n);this.relationTable=r}},M=class extends y.TypeError{constructor(r,n){
|
|
16
|
-
super(`Relation column ${r} don't exists.`,n);this.relationColumn=r}},
|
|
16
|
+
super(`Relation column ${r} don't exists.`,n);this.relationColumn=r}},A=class extends y.TypeError{constructor(r,n){
|
|
17
17
|
super(`Relation alias ${r} can't override table columns.`,n);this.relationAlias=
|
|
18
|
-
r}};var
|
|
18
|
+
r}};var ae=require("@ez4/common/library"),R=class extends ae.IncompleteTypeError{constructor(t,r){
|
|
19
19
|
super("Incomplete database service",t,r)}};var B="@ez4/database",Ge=e=>e.type===B;var u=require("@ez4/common/library"),G=require("@ez4/reflection"),J=e=>(0,u.isClassDeclaration)(
|
|
20
|
-
e)&&(0,u.hasHeritageType)(e,"Database.Service"),
|
|
20
|
+
e)&&(0,u.hasHeritageType)(e,"Database.Service"),oe=e=>(0,u.isModelDeclaration)(e)&&
|
|
21
21
|
(0,u.hasHeritageType)(e,"Database.Engine"),se=e=>(0,u.isModelDeclaration)(e)&&(0,u.hasHeritageType)(
|
|
22
|
-
e,"Database.Table"),ie=e=>(0,G.isTypeCallback)(e)||(0,G.isTypeFunction)(e),
|
|
23
|
-
e,"Database.Relations"),
|
|
22
|
+
e,"Database.Table"),ie=e=>(0,G.isTypeCallback)(e)||(0,G.isTypeFunction)(e),pe=e=>(0,u.hasHeritageType)(
|
|
23
|
+
e,"Database.Relations"),le=e=>(0,u.hasHeritageType)(e,"Database.Indexes"),me=e=>(0,u.hasHeritageType)(
|
|
24
24
|
e,"Database.Schema"),ce=e=>(0,u.hasHeritageType)(e,"Database.Stream");var T=require("@ez4/common/library"),v=require("@ez4/reflection");var ue=require("@ez4/common/library"),x=class extends ue.IncompleteTypeError{constructor(t,r){
|
|
25
25
|
super("Incomplete database table",t,r)}};var g=require("@ez4/common/library"),z=class extends g.InvalidTypeError{constructor(t){
|
|
26
26
|
super("Invalid table indexes type",void 0,"Database.Indexes",t)}},C=class extends g.IncorrectTypeError{constructor(r,n){
|
|
27
27
|
super("Incorrect table indexes type",r,"Database.Indexes",n);this.schemaType=r}},
|
|
28
28
|
N=class extends g.TypeError{constructor(r,n){super(`Invalid index type, ${r} mus\
|
|
29
29
|
t follow one of the Index options.`,n);this.indexName=r}},H=class extends g.TypeError{constructor(r,n){
|
|
30
|
-
super(`Invalid index reference, ${r} must be valid column.`,n);this.indexName=r}};var
|
|
31
|
-
e,r);return
|
|
32
|
-
e),r):(0,
|
|
33
|
-
new w(e.name,e.file)),null):(r.push(new
|
|
34
|
-
if(!(0,S.isModelProperty)(
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
return n};var f=require("@ez4/common/library"),I=require("@ez4/reflection");var xe=(e,t,r,n)=>{if(!(0,I.isTypeReference)(e))return Te(e,t,n);let
|
|
38
|
-
e,r);return
|
|
39
|
-
e),r):(0,f.isModelDeclaration)(e)?
|
|
40
|
-
new C(e.name,e.file)),null):(r.push(new z(t.file)),null),ye=(e,t,r)=>{let n=[];for(let
|
|
41
|
-
if(!(0,I.isModelProperty)(
|
|
42
|
-
|
|
43
|
-
columns:
|
|
30
|
+
super(`Invalid index reference, ${r} must be valid column.`,n);this.indexName=r}};var b=require("@ez4/common/library"),S=require("@ez4/reflection");var fe=(e,t,r,n)=>{if(!(0,S.isTypeReference)(e))return de(e,t,n);let a=(0,b.getReferenceType)(
|
|
31
|
+
e,r);return a?de(a,t,n):null},de=(e,t,r)=>(0,S.isTypeObject)(e)?be(e,(0,b.getObjectMembers)(
|
|
32
|
+
e),r):(0,b.isModelDeclaration)(e)?pe(e)?be(e,(0,b.getModelMembers)(e),r):(r.push(
|
|
33
|
+
new w(e.name,e.file)),null):(r.push(new j(t.file)),null),be=(e,t,r)=>{let n=[];for(let a of t){
|
|
34
|
+
if(!(0,S.isModelProperty)(a)||a.inherited)continue;let o=(0,b.getPropertyString)(
|
|
35
|
+
a),s=a.name;if(!o)return r.push(new k(s,e.file)),null;let[i,p]=s.split("@",2),[l,
|
|
36
|
+
P]=o.split(":",2);n.push({sourceTable:l,sourceColumn:P,targetColumn:i,targetAlias:p})}
|
|
37
|
+
return n};var f=require("@ez4/common/library"),I=require("@ez4/reflection");var xe=(e,t,r,n)=>{if(!(0,I.isTypeReference)(e))return Te(e,t,n);let a=(0,f.getReferenceType)(
|
|
38
|
+
e,r);return a?Te(a,t,n):null},Te=(e,t,r)=>(0,I.isTypeObject)(e)?ye(e,(0,f.getObjectMembers)(
|
|
39
|
+
e),r):(0,f.isModelDeclaration)(e)?le(e)?ye(e,(0,f.getModelMembers)(e),r):(r.push(
|
|
40
|
+
new C(e.name,e.file)),null):(r.push(new z(t.file)),null),ye=(e,t,r)=>{let n=[];for(let a of t){
|
|
41
|
+
if(!(0,I.isModelProperty)(a)||a.inherited)continue;let o=a.name,s=(0,f.getPropertyString)(
|
|
42
|
+
a);switch(s){case"primary":case"secondary":case"unique":case"ttl":n.push({name:o,
|
|
43
|
+
columns:o.split(":"),type:s});break;default:return r.push(new N(o,e.file)),null}}
|
|
44
44
|
return n};var Q=require("@ez4/common/library"),W=require("@ez4/schema/library"),X=require("@ez4/reflection");var K=require("@ez4/common/library"),F=class extends K.InvalidTypeError{constructor(t){
|
|
45
45
|
super("Invalid table schema type",void 0,"Database.Schema",t)}},$=class extends K.IncorrectTypeError{constructor(r,n){
|
|
46
|
-
super("Incorrect table schema type",r,"Database.Schema",n);this.schemaType=r}};var ee=(e,t,r,n)=>{if(!(0,X.isTypeReference)(e))return ge(e,t,r,n);let
|
|
47
|
-
e,r);return
|
|
46
|
+
super("Incorrect table schema type",r,"Database.Schema",n);this.schemaType=r}};var ee=(e,t,r,n)=>{if(!(0,X.isTypeReference)(e))return ge(e,t,r,n);let a=(0,Q.getReferenceType)(
|
|
47
|
+
e,r);return a?ge(a,t,r,n):null},ge=(e,t,r,n)=>(0,X.isTypeObject)(e)?Me(e,r):(0,Q.isModelDeclaration)(
|
|
48
48
|
e)?me(e)?Me(e,r):(n.push(new $(e.name,e.file)),null):(n.push(new F(t.file)),null),
|
|
49
49
|
Me=(e,t)=>{let r=(0,W.getObjectSchema)(e,t);return r&&(0,W.isObjectSchema)(r)?r:
|
|
50
50
|
null};var m=require("@ez4/common/library"),D=require("@ez4/reflection");var h=require("@ez4/common/library"),q=class extends h.IncompleteTypeError{constructor(t,r){
|
|
51
51
|
super("Incomplete table stream",t,r)}},V=class extends h.InvalidTypeError{constructor(t){
|
|
52
52
|
super("Invalid table stream type",void 0,"Database.Stream",t)}},U=class extends h.IncorrectTypeError{constructor(r,n){
|
|
53
53
|
super("Incorrect table stream type",r,"Database.Stream",n);this.streamType=r}};var Se=require("@ez4/common/library"),_=class extends Se.IncompleteTypeError{constructor(t,r){
|
|
54
|
-
super("Incomplete stream handler",t,r)}};var Ie=(e,t,r)=>{if(!ie(e))return null;let n={},
|
|
55
|
-
return e.description&&(n.description=e.description),(n.name=e.name)&&
|
|
56
|
-
ame"),(n.file=e.file)&&
|
|
57
|
-
0&&Je(n)?n:(r.push(new _([...
|
|
58
|
-
e,r);return
|
|
54
|
+
super("Incomplete stream handler",t,r)}};var Ie=(e,t,r)=>{if(!ie(e))return null;let n={},a=new Set(["name","file","change"]);
|
|
55
|
+
return e.description&&(n.description=e.description),(n.name=e.name)&&a.delete("n\
|
|
56
|
+
ame"),(n.file=e.file)&&a.delete("file"),e.parameters&&a.delete("change"),a.size===
|
|
57
|
+
0&&Je(n)?n:(r.push(new _([...a],e.file)),null)},Je=e=>!!e.name&&!!e.file;var ve=(e,t,r,n)=>{if(!(0,D.isTypeReference)(e))return he(e,t,r,n);let a=(0,m.getReferenceType)(
|
|
58
|
+
e,r);return a?he(a,t,r,n):null},Ke=e=>!!e.handler,he=(e,t,r,n)=>(0,D.isTypeObject)(
|
|
59
59
|
e)?De(e,t,(0,m.getObjectMembers)(e),r,n):(0,m.isModelDeclaration)(e)?ce(e)?De(e,
|
|
60
60
|
t,(0,m.getModelMembers)(e),r,n):(n.push(new U(e.name,e.file)),null):(n.push(new V(
|
|
61
|
-
t.file)),null),De=(e,t,r,n,
|
|
62
|
-
i)||i.inherited))switch(i.name){default:
|
|
63
|
-
t.name,i.name,e.file));break;case"handler":
|
|
64
|
-
listener":
|
|
65
|
-
timeout":
|
|
66
|
-
(0,m.getLinkedVariableList)(i,
|
|
67
|
-
null)};var re=(e,t,r,n)=>{if(!(0,v.isTypeReference)(e))return Ee(e,t,r,n);let
|
|
68
|
-
e,r);return
|
|
69
|
-
e)?
|
|
70
|
-
e),r,n):null,
|
|
71
|
-
if(!(!(0,v.isModelProperty)(
|
|
72
|
-
t.name,
|
|
73
|
-
|
|
74
|
-
indexes":(
|
|
75
|
-
relations=fe(
|
|
76
|
-
if(!Qe(
|
|
77
|
-
return i.length?(
|
|
78
|
-
name:
|
|
79
|
-
e,r);return
|
|
80
|
-
we(e,t,(0,
|
|
81
|
-
e),r):null,we=(e,t,r,n)=>{let
|
|
82
|
-
if(!(!(0,E.isModelProperty)(s)||s.inherited))switch(s.name){default:
|
|
83
|
-
t.name,s.name,e.file));break;case"name":
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
(
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
n.push(
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
61
|
+
t.file)),null),De=(e,t,r,n,a)=>{let o={},s=new Set(["handler"]);for(let i of r)if(!(!(0,D.isModelProperty)(
|
|
62
|
+
i)||i.inherited))switch(i.name){default:a.push(new m.InvalidServicePropertyError(
|
|
63
|
+
t.name,i.name,e.file));break;case"handler":o.handler=Ie(i.value,n,a);break;case"\
|
|
64
|
+
listener":o.listener=(0,m.getServiceListener)(i.value,a);break;case"memory":case"\
|
|
65
|
+
timeout":case"retention":o[i.name]=(0,m.getPropertyNumber)(i);break;case"variabl\
|
|
66
|
+
es":o.variables=(0,m.getLinkedVariableList)(i,a);break}return Ke(o)?o:(a.push(new q(
|
|
67
|
+
[...s],e.file)),null)};var re=(e,t,r,n)=>{if(!(0,v.isTypeReference)(e))return Ee(e,t,r,n);let a=(0,T.getReferenceType)(
|
|
68
|
+
e,r);return a?Ee(a,t,r,n):null},Qe=e=>!!e.name&&!!e.schema&&!!e.indexes,Ee=(e,t,r,n)=>se(
|
|
69
|
+
e)?Pe(e,t,(0,T.getModelMembers)(e),r,n):(0,v.isTypeObject)(e)?Pe(e,t,(0,T.getObjectMembers)(
|
|
70
|
+
e),r,n):null,Pe=(e,t,r,n,a)=>{let o={},s=new Set(["name","schema","indexes"]);for(let p of r)
|
|
71
|
+
if(!(!(0,v.isModelProperty)(p)||p.inherited))switch(p.name){default:a.push(new T.InvalidServicePropertyError(
|
|
72
|
+
t.name,p.name,e.file));break;case"name":(o.name=(0,T.getPropertyString)(p))&&s.delete(
|
|
73
|
+
p.name);break;case"schema":(o.schema=ee(p.value,e,n,a))&&s.delete(p.name);break;case"\
|
|
74
|
+
indexes":(o.indexes=xe(p.value,e,n,a))&&s.delete(p.name);break;case"relations":o.
|
|
75
|
+
relations=fe(p.value,e,n,a);break;case"stream":o.stream=ve(p.value,t,n,a);break}
|
|
76
|
+
if(!Qe(o))return a.push(new x([...s],e.file)),null;let i=We(e,o.indexes,o.schema);
|
|
77
|
+
return i.length?(a.push(...i),null):o},We=(e,t,r)=>{let n=r.properties,a=[];for(let{
|
|
78
|
+
name:o,columns:s}of t)s.some(p=>!n[p])&&a.push(new H(o,e.file));return a};var d=require("@ez4/common/library"),E=require("@ez4/reflection");var ke=(e,t,r,n)=>{if(!(0,E.isTypeReference)(e))return je(e,t,n);let a=(0,d.getReferenceType)(
|
|
79
|
+
e,r);return a?je(a,t,n):null},Xe=e=>!!e.name&&!!e.transaction,je=(e,t,r)=>oe(e)?
|
|
80
|
+
we(e,t,(0,d.getModelMembers)(e),r):(0,E.isTypeObject)(e)?we(e,t,(0,d.getObjectMembers)(
|
|
81
|
+
e),r):null,we=(e,t,r,n)=>{let a={},o=new Set(["name","transaction","parameters"]);
|
|
82
|
+
for(let s of r)if(!(!(0,E.isModelProperty)(s)||s.inherited))switch(s.name){default:
|
|
83
|
+
n.push(new d.InvalidServicePropertyError(t.name,s.name,e.file));break;case"name":
|
|
84
|
+
(a.name=(0,d.getPropertyString)(s))&&o.delete(s.name);break;case"transaction":(a.
|
|
85
|
+
transaction=Ye(s))&&o.delete(s.name);break;case"parameters":(a.parameters=Ze(s))&&
|
|
86
|
+
o.delete(s.name);break}return Xe(a)?a:(n.push(new x([...o],e.file)),null)},Ye=e=>{
|
|
87
|
+
let t=(0,d.getPropertyString)(e);switch(t){case"interactive":case"static":return t}
|
|
88
|
+
return null},Ze=e=>{let t=(0,d.getPropertyString)(e);switch(t){case"both":case"i\
|
|
89
|
+
ndex":return t}return null};var te=e=>{let t={},r=[];for(let n in e){let a=e[n];if(!J(a)||(0,c.isExternalStatement)(
|
|
90
|
+
a))continue;let o={type:B,extras:{}},s=new Set(["engine","tables"]),i=a.file;o.name=
|
|
91
|
+
a.name;for(let l of(0,c.getModelMembers)(a))if(!(!(0,Ae.isModelProperty)(l)||l.inherited))
|
|
92
|
+
switch(l.name){default:r.push(new c.InvalidServicePropertyError(o.name,l.name,i));
|
|
93
|
+
break;case"engine":(o.engine=ke(l.value,a,e,r))&&s.delete(l.name);break;case"tab\
|
|
94
|
+
les":(o.tables=er(l,a,e,r))&&s.delete(l.name);break;case"variables":o.variables=
|
|
95
|
+
(0,c.getLinkedVariableList)(l,r);break;case"services":o.services=(0,c.getLinkedServiceList)(
|
|
96
|
+
l,e,r);break}if(!Le(o)){r.push(new R([...s],i));continue}let p=rr(a,o.tables);if(p.
|
|
97
|
+
length){r.push(...p);continue}if(t[a.name]){r.push(new c.DuplicateServiceError(a.
|
|
98
|
+
name,i));continue}t[a.name]=o}return{services:t,errors:r}},Le=e=>!!e.name&&!!e.tables&&
|
|
99
|
+
!!e.extras,er=(e,t,r,n)=>{let a=(0,c.getPropertyTuple)(e)??[],o=[];for(let s of a){
|
|
100
|
+
let i=re(s,t,r,n);i&&o.push(i)}return o},rr=(e,t)=>{let r=tr(t),n=[];for(let{relations:a,
|
|
101
|
+
schema:o,indexes:s}of t){if(!a)continue;let i=o.properties;for(let p of a){let{sourceTable:l,
|
|
102
|
+
sourceColumn:P,targetColumn:Y,targetAlias:ne}=p;i[Y]||n.push(new M(Y,e.file)),i[ne]&&
|
|
103
|
+
n.push(new A(ne,e.file));let Z=r[l]?.schema.properties;Z||n.push(new O(l,e.file)),
|
|
104
|
+
Z&&!Z[P]&&n.push(new M(P,e.file));let Fe=r[l]?.indexes??[];p.sourceIndex=Oe(Fe,P),
|
|
105
|
+
p.targetIndex=Oe(s,Y)}}return n},Oe=(e,t)=>e.find(({name:r})=>r===t)?.type,tr=e=>e.
|
|
106
|
+
reduce((t,r)=>({...t,[r.name]:r}),{});var Re=e=>J(e)?e.name:null;var ze=!1,nr=()=>{ze||((0,Ce.registerTriggers)(),(0,Ne.registerTriggers)(),(0,He.createTrigger)(
|
|
107
|
+
"@ez4/database",{"metadata:getServices":te,"metadata:getLinkedService":Re}),ze=!0)};0&&(module.exports={IncompleteHandlerError,IncompleteServiceError,IncompleteStreamError,
|
|
105
108
|
IncompleteTableError,IncorrectIndexesTypeError,IncorrectRelationsTypeError,IncorrectSchemaTypeError,
|
|
106
109
|
IncorrectStreamTypeError,InvalidIndexReferenceError,InvalidIndexTypeError,InvalidIndexesTypeError,
|
|
107
110
|
InvalidRelationAliasError,InvalidRelationColumnError,InvalidRelationTableError,InvalidRelationTargetError,
|
package/dist/library.mjs
CHANGED
|
@@ -1,107 +1,109 @@
|
|
|
1
|
-
import{registerTriggers as
|
|
2
|
-
import{createTrigger as
|
|
3
|
-
getLinkedServiceList as
|
|
4
|
-
import{isModelProperty as
|
|
5
|
-
var
|
|
1
|
+
import{registerTriggers as Br}from"@ez4/common/library";import{registerTriggers as Gr}from"@ez4/schema/library";
|
|
2
|
+
import{createTrigger as Jr}from"@ez4/project/library";import{DuplicateServiceError as Ar,InvalidServicePropertyError as Rr,isExternalStatement as zr,
|
|
3
|
+
getLinkedServiceList as Cr,getLinkedVariableList as Nr,getPropertyTuple as Hr,getModelMembers as Fr}from"@ez4/common/library";
|
|
4
|
+
import{isModelProperty as $r}from"@ez4/reflection";import{IncorrectTypeError as Te,InvalidTypeError as ye,TypeError as g}from"@ez4/common/library";
|
|
5
|
+
var b=class extends ye{constructor(t){super("Invalid table relations type",void 0,
|
|
6
6
|
"Database.Relations",t)}},f=class extends Te{constructor(r,n){super("Incorrect t\
|
|
7
7
|
able relations type",r,"Database.Relations",n);this.schemaType=r}},T=class extends g{constructor(r,n){
|
|
8
8
|
super(`Target ${r} must follow the pattern 'column@alias'.`,n);this.relationSource=
|
|
9
9
|
r}},y=class extends g{constructor(r,n){super(`Relation table ${r} don't exists.`,
|
|
10
|
-
n);this.relationTable=r}},
|
|
10
|
+
n);this.relationTable=r}},d=class extends g{constructor(r,n){super(`Relation col\
|
|
11
11
|
umn ${r} don't exists.`,n);this.relationColumn=r}},x=class extends g{constructor(r,n){
|
|
12
12
|
super(`Relation alias ${r} can't override table columns.`,n);this.relationAlias=
|
|
13
13
|
r}};import{IncompleteTypeError as xe}from"@ez4/common/library";var M=class extends xe{constructor(t,r){
|
|
14
|
-
super("Incomplete database service",t,r)}};var z="@ez4/database",
|
|
14
|
+
super("Incomplete database service",t,r)}};var z="@ez4/database",Yr=e=>e.type===z;import{hasHeritageType as m,isClassDeclaration as ge,isModelDeclaration as H}from"@ez4/common/library";
|
|
15
15
|
import{isTypeCallback as Me,isTypeFunction as Se}from"@ez4/reflection";var S=e=>ge(
|
|
16
|
-
e)&&m(e,"Database.Service"),
|
|
17
|
-
tabase.Table")
|
|
18
|
-
se.Indexes"),
|
|
16
|
+
e)&&m(e,"Database.Service"),F=e=>H(e)&&m(e,"Database.Engine"),$=e=>H(e)&&m(e,"Da\
|
|
17
|
+
tabase.Table"),q=e=>Me(e)||Se(e),V=e=>m(e,"Database.Relations"),U=e=>m(e,"Databa\
|
|
18
|
+
se.Indexes"),_=e=>m(e,"Database.Schema"),B=e=>m(e,"Database.Stream");import{InvalidServicePropertyError as ur,getModelMembers as dr,getObjectMembers as br,
|
|
19
19
|
getPropertyString as fr,getReferenceType as Tr}from"@ez4/common/library";import{
|
|
20
20
|
isModelProperty as yr,isTypeObject as xr,isTypeReference as gr}from"@ez4/reflection";import{IncompleteTypeError as Ie}from"@ez4/common/library";var c=class extends Ie{constructor(t,r){
|
|
21
|
-
super("Incomplete database table",t,r)}};import{IncorrectTypeError as he,InvalidTypeError as De,TypeError as
|
|
21
|
+
super("Incomplete database table",t,r)}};import{IncorrectTypeError as he,InvalidTypeError as De,TypeError as G}from"@ez4/common/library";
|
|
22
22
|
var I=class extends De{constructor(t){super("Invalid table indexes type",void 0,
|
|
23
23
|
"Database.Indexes",t)}},h=class extends he{constructor(r,n){super("Incorrect tab\
|
|
24
|
-
le indexes type",r,"Database.Indexes",n);this.schemaType=r}},D=class extends
|
|
24
|
+
le indexes type",r,"Database.Indexes",n);this.schemaType=r}},D=class extends G{constructor(r,n){
|
|
25
25
|
super(`Invalid index type, ${r} must follow one of the Index options.`,n);this.indexName=
|
|
26
|
-
r}},v=class extends
|
|
27
|
-
be valid column.`,n);this.indexName=r}};import{isModelDeclaration as ve,getModelMembers as Ee,getObjectMembers as
|
|
26
|
+
r}},v=class extends G{constructor(r,n){super(`Invalid index reference, ${r} must\
|
|
27
|
+
be valid column.`,n);this.indexName=r}};import{isModelDeclaration as ve,getModelMembers as Ee,getObjectMembers as Pe,getPropertyString as je,
|
|
28
28
|
getReferenceType as we}from"@ez4/common/library";import{isModelProperty as ke,isTypeObject as Oe,
|
|
29
|
-
isTypeReference as
|
|
30
|
-
|
|
31
|
-
null):(r.push(new
|
|
32
|
-
|
|
33
|
-
let[i,
|
|
34
|
-
targetColumn:i,targetAlias:
|
|
29
|
+
isTypeReference as Ae}from"@ez4/reflection";var Q=(e,t,r,n)=>{if(!Ae(e))return J(e,t,n);let a=we(e,r);return a?J(a,t,n):null},
|
|
30
|
+
J=(e,t,r)=>Oe(e)?K(e,Pe(e),r):ve(e)?V(e)?K(e,Ee(e),r):(r.push(new f(e.name,e.file)),
|
|
31
|
+
null):(r.push(new b(t.file)),null),K=(e,t,r)=>{let n=[];for(let a of t){if(!ke(a)||
|
|
32
|
+
a.inherited)continue;let o=je(a),s=a.name;if(!o)return r.push(new T(s,e.file)),null;
|
|
33
|
+
let[i,p]=s.split("@",2),[l,u]=o.split(":",2);n.push({sourceTable:l,sourceColumn:u,
|
|
34
|
+
targetColumn:i,targetAlias:p})}return n};import{isModelDeclaration as Re,getModelMembers as ze,getObjectMembers as Ce,getPropertyString as Ne,
|
|
35
35
|
getReferenceType as He}from"@ez4/common/library";import{isModelProperty as Fe,isTypeObject as $e,
|
|
36
|
-
isTypeReference as qe}from"@ez4/reflection";var
|
|
37
|
-
|
|
38
|
-
null):(r.push(new I(t.file)),null),
|
|
39
|
-
|
|
40
|
-
unique":case"ttl":n.push({name:
|
|
41
|
-
push(new D(
|
|
36
|
+
isTypeReference as qe}from"@ez4/reflection";var Y=(e,t,r,n)=>{if(!qe(e))return W(e,t,n);let a=He(e,r);return a?W(a,t,n):null},
|
|
37
|
+
W=(e,t,r)=>$e(e)?X(e,Ce(e),r):Re(e)?U(e)?X(e,ze(e),r):(r.push(new h(e.name,e.file)),
|
|
38
|
+
null):(r.push(new I(t.file)),null),X=(e,t,r)=>{let n=[];for(let a of t){if(!Fe(a)||
|
|
39
|
+
a.inherited)continue;let o=a.name,s=Ne(a);switch(s){case"primary":case"secondary":case"\
|
|
40
|
+
unique":case"ttl":n.push({name:o,columns:o.split(":"),type:s});break;default:return r.
|
|
41
|
+
push(new D(o,e.file)),null}}return n};import{getReferenceType as _e,isModelDeclaration as Be}from"@ez4/common/library";
|
|
42
42
|
import{getObjectSchema as Ge,isObjectSchema as Je}from"@ez4/schema/library";import{
|
|
43
43
|
isTypeObject as Ke,isTypeReference as Qe}from"@ez4/reflection";import{IncorrectTypeError as Ve,InvalidTypeError as Ue}from"@ez4/common/library";
|
|
44
44
|
var E=class extends Ue{constructor(t){super("Invalid table schema type",void 0,"\
|
|
45
|
-
Database.Schema",t)}},
|
|
46
|
-
schema type",r,"Database.Schema",n);this.schemaType=r}};var
|
|
47
|
-
null},
|
|
48
|
-
null):(n.push(new E(t.file)),null),
|
|
49
|
-
getModelMembers as nr,getObjectMembers as
|
|
50
|
-
getReferenceType as ir}from"@ez4/common/library";import{isModelProperty as
|
|
45
|
+
Database.Schema",t)}},P=class extends Ve{constructor(r,n){super("Incorrect table\
|
|
46
|
+
schema type",r,"Database.Schema",n);this.schemaType=r}};var ee=(e,t,r,n)=>{if(!Qe(e))return Z(e,t,r,n);let a=_e(e,r);return a?Z(a,t,r,n):
|
|
47
|
+
null},Z=(e,t,r,n)=>Ke(e)?L(e,r):Be(e)?_(e)?L(e,r):(n.push(new P(e.name,e.file)),
|
|
48
|
+
null):(n.push(new E(t.file)),null),L=(e,t)=>{let r=Ge(e,t);return r&&Je(r)?r:null};import{InvalidServicePropertyError as er,isModelDeclaration as rr,getLinkedVariableList as tr,
|
|
49
|
+
getModelMembers as nr,getObjectMembers as ar,getPropertyNumber as or,getServiceListener as sr,
|
|
50
|
+
getReferenceType as ir}from"@ez4/common/library";import{isModelProperty as pr,isTypeObject as lr,
|
|
51
51
|
isTypeReference as mr}from"@ez4/reflection";import{IncompleteTypeError as We,IncorrectTypeError as Xe,InvalidTypeError as Ye}from"@ez4/common/library";
|
|
52
|
-
var
|
|
52
|
+
var j=class extends We{constructor(t,r){super("Incomplete table stream",t,r)}},w=class extends Ye{constructor(t){
|
|
53
53
|
super("Invalid table stream type",void 0,"Database.Stream",t)}},k=class extends Xe{constructor(r,n){
|
|
54
54
|
super("Incorrect table stream type",r,"Database.Stream",n);this.streamType=r}};import{IncompleteTypeError as Ze}from"@ez4/common/library";var O=class extends Ze{constructor(t,r){
|
|
55
|
-
super("Incomplete stream handler",t,r)}};var
|
|
56
|
-
return e.description&&(n.description=e.description),(n.name=e.name)&&
|
|
57
|
-
ame"),(n.file=e.file)&&
|
|
58
|
-
0&&Le(n)?n:(r.push(new O([...
|
|
59
|
-
n):null},cr=e=>!!e.handler,
|
|
60
|
-
t,nr(e),r,n):(n.push(new k(e.name,e.file)),null):(n.push(new w(t.file)),null),
|
|
61
|
-
let
|
|
62
|
-
name){default:
|
|
63
|
-
|
|
64
|
-
timeout":
|
|
65
|
-
a)?
|
|
66
|
-
n):null},Mr=e=>!!e.name&&!!e.schema&&!!e.indexes,oe=(e,t,r,n)
|
|
67
|
-
r,n):xr(e)?
|
|
68
|
-
chema","indexes"]);for(let
|
|
69
|
-
|
|
70
|
-
name);break;case"schema":(
|
|
71
|
-
indexes":(
|
|
72
|
-
relations=
|
|
73
|
-
|
|
74
|
-
length?(
|
|
75
|
-
columns:s}of t)s.some(
|
|
76
|
-
getPropertyString as
|
|
77
|
-
|
|
78
|
-
wr=e=>!!e.name&&!!e.transaction,
|
|
79
|
-
e),r):null,le=(e,t,r,n)=>{let
|
|
80
|
-
if(!(!Er(s)||s.inherited))switch(s.name){default:n.push(new Ir(t.
|
|
81
|
-
break;case"name":(
|
|
82
|
-
kr(s))&&
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
A
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
55
|
+
super("Incomplete stream handler",t,r)}};var re=(e,t,r)=>{if(!q(e))return null;let n={},a=new Set(["name","file","change"]);
|
|
56
|
+
return e.description&&(n.description=e.description),(n.name=e.name)&&a.delete("n\
|
|
57
|
+
ame"),(n.file=e.file)&&a.delete("file"),e.parameters&&a.delete("change"),a.size===
|
|
58
|
+
0&&Le(n)?n:(r.push(new O([...a],e.file)),null)},Le=e=>!!e.name&&!!e.file;var ae=(e,t,r,n)=>{if(!mr(e))return te(e,t,r,n);let a=ir(e,r);return a?te(a,t,r,
|
|
59
|
+
n):null},cr=e=>!!e.handler,te=(e,t,r,n)=>lr(e)?ne(e,t,ar(e),r,n):rr(e)?B(e)?ne(e,
|
|
60
|
+
t,nr(e),r,n):(n.push(new k(e.name,e.file)),null):(n.push(new w(t.file)),null),ne=(e,t,r,n,a)=>{
|
|
61
|
+
let o={},s=new Set(["handler"]);for(let i of r)if(!(!pr(i)||i.inherited))switch(i.
|
|
62
|
+
name){default:a.push(new er(t.name,i.name,e.file));break;case"handler":o.handler=
|
|
63
|
+
re(i.value,n,a);break;case"listener":o.listener=sr(i.value,a);break;case"memory":case"\
|
|
64
|
+
timeout":case"retention":o[i.name]=or(i);break;case"variables":o.variables=tr(i,
|
|
65
|
+
a);break}return cr(o)?o:(a.push(new j([...s],e.file)),null)};var ie=(e,t,r,n)=>{if(!gr(e))return oe(e,t,r,n);let a=Tr(e,r);return a?oe(a,t,r,
|
|
66
|
+
n):null},Mr=e=>!!e.name&&!!e.schema&&!!e.indexes,oe=(e,t,r,n)=>$(e)?se(e,t,dr(e),
|
|
67
|
+
r,n):xr(e)?se(e,t,br(e),r,n):null,se=(e,t,r,n,a)=>{let o={},s=new Set(["name","s\
|
|
68
|
+
chema","indexes"]);for(let p of r)if(!(!yr(p)||p.inherited))switch(p.name){default:
|
|
69
|
+
a.push(new ur(t.name,p.name,e.file));break;case"name":(o.name=fr(p))&&s.delete(p.
|
|
70
|
+
name);break;case"schema":(o.schema=ee(p.value,e,n,a))&&s.delete(p.name);break;case"\
|
|
71
|
+
indexes":(o.indexes=Y(p.value,e,n,a))&&s.delete(p.name);break;case"relations":o.
|
|
72
|
+
relations=Q(p.value,e,n,a);break;case"stream":o.stream=ae(p.value,t,n,a);break}if(!Mr(
|
|
73
|
+
o))return a.push(new c([...s],e.file)),null;let i=Sr(e,o.indexes,o.schema);return i.
|
|
74
|
+
length?(a.push(...i),null):o},Sr=(e,t,r)=>{let n=r.properties,a=[];for(let{name:o,
|
|
75
|
+
columns:s}of t)s.some(p=>!n[p])&&a.push(new v(o,e.file));return a};import{InvalidServicePropertyError as Ir,getModelMembers as hr,getObjectMembers as Dr,
|
|
76
|
+
getPropertyString as C,getReferenceType as vr}from"@ez4/common/library";import{isModelProperty as Er,
|
|
77
|
+
isTypeObject as Pr,isTypeReference as jr}from"@ez4/reflection";var me=(e,t,r,n)=>{if(!jr(e))return pe(e,t,n);let a=vr(e,r);return a?pe(a,t,n):null},
|
|
78
|
+
wr=e=>!!e.name&&!!e.transaction,pe=(e,t,r)=>F(e)?le(e,t,hr(e),r):Pr(e)?le(e,t,Dr(
|
|
79
|
+
e),r):null,le=(e,t,r,n)=>{let a={},o=new Set(["name","transaction","parameters"]);
|
|
80
|
+
for(let s of r)if(!(!Er(s)||s.inherited))switch(s.name){default:n.push(new Ir(t.
|
|
81
|
+
name,s.name,e.file));break;case"name":(a.name=C(s))&&o.delete(s.name);break;case"\
|
|
82
|
+
transaction":(a.transaction=kr(s))&&o.delete(s.name);break;case"parameters":(a.parameters=
|
|
83
|
+
Or(s))&&o.delete(s.name);break}return wr(a)?a:(n.push(new c([...o],e.file)),null)},
|
|
84
|
+
kr=e=>{let t=C(e);switch(t){case"interactive":case"static":return t}return null},
|
|
85
|
+
Or=e=>{let t=C(e);switch(t){case"both":case"index":return t}return null};var ue=e=>{let t={},r=[];for(let n in e){let a=e[n];if(!S(a)||zr(a))continue;let o={
|
|
86
|
+
type:z,extras:{}},s=new Set(["engine","tables"]),i=a.file;o.name=a.name;for(let l of Fr(
|
|
87
|
+
a))if(!(!$r(l)||l.inherited))switch(l.name){default:r.push(new Rr(o.name,l.name,
|
|
88
|
+
i));break;case"engine":(o.engine=me(l.value,a,e,r))&&s.delete(l.name);break;case"\
|
|
89
|
+
tables":(o.tables=Vr(l,a,e,r))&&s.delete(l.name);break;case"variables":o.variables=
|
|
90
|
+
Nr(l,r);break;case"services":o.services=Cr(l,e,r);break}if(!qr(o)){r.push(new M(
|
|
91
|
+
[...s],i));continue}let p=Ur(a,o.tables);if(p.length){r.push(...p);continue}if(t[a.
|
|
92
|
+
name]){r.push(new Ar(a.name,i));continue}t[a.name]=o}return{services:t,errors:r}},
|
|
93
|
+
qr=e=>!!e.name&&!!e.tables&&!!e.extras,Vr=(e,t,r,n)=>{let a=Hr(e)??[],o=[];for(let s of a){
|
|
94
|
+
let i=ie(s,t,r,n);i&&o.push(i)}return o},Ur=(e,t)=>{let r=_r(t),n=[];for(let{relations:a,
|
|
95
|
+
schema:o,indexes:s}of t){if(!a)continue;let i=o.properties;for(let p of a){let{sourceTable:l,
|
|
96
|
+
sourceColumn:u,targetColumn:A,targetAlias:N}=p;i[A]||n.push(new d(A,e.file)),i[N]&&
|
|
97
|
+
n.push(new x(N,e.file));let R=r[l]?.schema.properties;R||n.push(new y(l,e.file)),
|
|
98
|
+
R&&!R[u]&&n.push(new d(u,e.file));let fe=r[l]?.indexes??[];p.sourceIndex=ce(fe,u),
|
|
99
|
+
p.targetIndex=ce(s,A)}}return n},ce=(e,t)=>e.find(({name:r})=>r===t)?.type,_r=e=>e.
|
|
100
|
+
reduce((t,r)=>({...t,[r.name]:r}),{});var de=e=>S(e)?e.name:null;var be=!1,In=()=>{be||(Br(),Gr(),Jr("@ez4/database",{"metadata:getServices":ue,"\
|
|
101
|
+
metadata:getLinkedService":de}),be=!0)};export{O as IncompleteHandlerError,M as IncompleteServiceError,j as IncompleteStreamError,
|
|
100
102
|
c as IncompleteTableError,h as IncorrectIndexesTypeError,f as IncorrectRelationsTypeError,
|
|
101
|
-
|
|
103
|
+
P as IncorrectSchemaTypeError,k as IncorrectStreamTypeError,v as InvalidIndexReferenceError,
|
|
102
104
|
D as InvalidIndexTypeError,I as InvalidIndexesTypeError,x as InvalidRelationAliasError,
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
z as ServiceType,ue as getDatabaseServices,
|
|
106
|
-
|
|
105
|
+
d as InvalidRelationColumnError,y as InvalidRelationTableError,T as InvalidRelationTargetError,
|
|
106
|
+
b as InvalidRelationsTypeError,E as InvalidSchemaTypeError,w as InvalidStreamTypeError,
|
|
107
|
+
z as ServiceType,ue as getDatabaseServices,ie as getDatabaseTable,ee as getTableSchema,
|
|
108
|
+
Yr as isDatabaseService,In as registerTriggers};
|
|
107
109
|
//# sourceMappingURL=library.mjs.map
|
package/dist/main.cjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
"use strict";var s=Object.defineProperty;var
|
|
2
|
-
typeof a=="object"||typeof a=="function")for(let t of
|
|
3
|
-
s(r,t,{get:()=>a[t],enumerable:!(n=
|
|
4
|
-
module.exports=
|
|
5
|
-
|
|
1
|
+
"use strict";var s=Object.defineProperty;var c=Object.getOwnPropertyDescriptor;var T=Object.getOwnPropertyNames;var y=Object.prototype.hasOwnProperty;var I=(r,a)=>{for(var e in a)s(r,e,{get:a[e],enumerable:!0})},b=(r,a,e,n)=>{if(a&&
|
|
2
|
+
typeof a=="object"||typeof a=="function")for(let t of T(a))!y.call(r,t)&&t!==e&&
|
|
3
|
+
s(r,t,{get:()=>a[t],enumerable:!(n=c(a,t))||n.enumerable});return r};var l=r=>b(s({},"__esModule",{value:!0}),r);var S={};I(S,{Database:()=>m,Index:()=>p,Order:()=>i,ParametersType:()=>x,StreamType:()=>d,
|
|
4
|
+
TransactionType:()=>o});module.exports=l(S);var d=(n=>(n.Insert="insert",n.Update="update",n.Delete="delete",n))(d||{});var o=(e=>(e.Interactive="interactive",e.Static="static",e))(o||{}),x=(e=>(e.NameAndIndex=
|
|
5
|
+
"both",e.OnlyIndex="index",e))(x||{});var m;(r=>{})(m||={});var p=(t=>(t.Primary="primary",t.Secondary="secondary",t.Unique="unique",t.TTL="\
|
|
6
|
+
ttl",t))(p||{});var i=(e=>(e.Asc="asc",e.Desc="desc",e))(i||{});0&&(module.exports={Database,Index,Order,ParametersType,StreamType,TransactionType});
|
|
6
7
|
//# sourceMappingURL=main.cjs.map
|
package/dist/main.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
export * from './services/streams.js';
|
|
2
2
|
export { Client } from './services/client.js';
|
|
3
3
|
export { RelationMetadata } from './services/relations.js';
|
|
4
|
-
export { TransactionType } from './services/engine.js';
|
|
4
|
+
export { TransactionType, ParametersType } from './services/engine.js';
|
|
5
5
|
export { Transaction } from './services/transaction.js';
|
|
6
|
+
export { Parameters } from './services/parameters.js';
|
|
6
7
|
export { Database } from './services/database.js';
|
|
7
8
|
export { Index } from './services/indexes.js';
|
|
8
9
|
export { Table } from './services/table.js';
|
package/dist/main.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
var
|
|
2
|
-
|
|
1
|
+
var m=(a=>(a.Insert="insert",a.Update="update",a.Delete="delete",a))(m||{});var r=(e=>(e.Interactive="interactive",e.Static="static",e))(r||{}),n=(e=>(e.NameAndIndex=
|
|
2
|
+
"both",e.OnlyIndex="index",e))(n||{});var s;(p=>{})(s||={});var o=(t=>(t.Primary="primary",t.Secondary="secondary",t.Unique="unique",t.TTL="\
|
|
3
|
+
ttl",t))(o||{});var x=(e=>(e.Asc="asc",e.Desc="desc",e))(x||{});export{s as Database,o as Index,x as Order,n as ParametersType,m as StreamType,r as TransactionType};
|
|
3
4
|
//# sourceMappingURL=main.mjs.map
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Transaction } from './transaction.js';
|
|
2
|
+
import type { Parameters } from './parameters.js';
|
|
2
3
|
import type { TableClients } from './table.js';
|
|
3
4
|
import type { Database } from './database.js';
|
|
4
5
|
/**
|
|
@@ -9,15 +10,15 @@ export type Client<T extends Database.Service> = TableClients<T> & {
|
|
|
9
10
|
* Prepare and execute the given query.
|
|
10
11
|
*
|
|
11
12
|
* @param query Query statement.
|
|
12
|
-
* @param
|
|
13
|
+
* @param parameters Parameters in use by the given query.
|
|
13
14
|
* @returns Returns the results for the given query.
|
|
14
15
|
*/
|
|
15
|
-
rawQuery(query: string,
|
|
16
|
+
rawQuery(query: string, parameters?: Parameters.Type<T>): Promise<Record<string, unknown>[]>;
|
|
16
17
|
/**
|
|
17
18
|
* Prepare and execute the given transaction.
|
|
18
19
|
*
|
|
19
20
|
* @param operation Transaction operation.
|
|
20
21
|
* @returns Returns the transaction result if the given transaction is interactive.
|
|
21
22
|
*/
|
|
22
|
-
transaction<O extends Transaction.
|
|
23
|
+
transaction<O extends Transaction.Type<T, R>, R>(operation: O): Promise<Transaction.Result<O>>;
|
|
23
24
|
};
|
|
@@ -39,11 +39,11 @@ export declare namespace Database {
|
|
|
39
39
|
/**
|
|
40
40
|
* Stream listener.
|
|
41
41
|
*/
|
|
42
|
-
type Listener<T extends Schema> = (event: Service.Event<Incoming<T
|
|
42
|
+
type Listener<T extends Schema> = (event: Service.Event<Incoming<T>>, context: Service.Context<Database.Service>) => Promise<void> | void;
|
|
43
43
|
/**
|
|
44
44
|
* Stream handler.
|
|
45
45
|
*/
|
|
46
|
-
type Handler<T extends Schema> = (request: Incoming<T
|
|
46
|
+
type Handler<T extends Schema> = (request: Incoming<T>, context: Service.Context<Database.Service>) => Promise<void> | void;
|
|
47
47
|
/**
|
|
48
48
|
* Service event.
|
|
49
49
|
*/
|
|
@@ -68,6 +68,10 @@ export declare namespace Database {
|
|
|
68
68
|
* Variables associated to the handler.
|
|
69
69
|
*/
|
|
70
70
|
variables?: LinkedVariables;
|
|
71
|
+
/**
|
|
72
|
+
* Log retention (in days) for the handler.
|
|
73
|
+
*/
|
|
74
|
+
retention?: number;
|
|
71
75
|
/**
|
|
72
76
|
* Max execution time (in seconds) for the handler.
|
|
73
77
|
*/
|
|
@@ -5,10 +5,18 @@ export declare const enum TransactionType {
|
|
|
5
5
|
Interactive = "interactive",
|
|
6
6
|
Static = "static"
|
|
7
7
|
}
|
|
8
|
+
/**
|
|
9
|
+
* Parameters type.
|
|
10
|
+
*/
|
|
11
|
+
export declare const enum ParametersType {
|
|
12
|
+
NameAndIndex = "both",
|
|
13
|
+
OnlyIndex = "index"
|
|
14
|
+
}
|
|
8
15
|
/**
|
|
9
16
|
* Database engine.
|
|
10
17
|
*/
|
|
11
18
|
export type DatabaseEngine = {
|
|
12
19
|
transaction: TransactionType;
|
|
20
|
+
parameters: ParametersType;
|
|
13
21
|
name: string;
|
|
14
22
|
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ParametersType } from './engine.js';
|
|
2
|
+
import type { Database } from './database.js';
|
|
3
|
+
/**
|
|
4
|
+
* Parameters builder types.
|
|
5
|
+
*/
|
|
6
|
+
export declare namespace Parameters {
|
|
7
|
+
/**
|
|
8
|
+
* Determines the parameters type based on the given database service.
|
|
9
|
+
*/
|
|
10
|
+
export type Type<T extends Database.Service> = EngineParametersType<T> extends ParametersType.NameAndIndex ? unknown[] | Record<string, unknown> : unknown[];
|
|
11
|
+
/**
|
|
12
|
+
* Extract the parameters from the given database service.
|
|
13
|
+
*/
|
|
14
|
+
type EngineParametersType<T extends Database.Service> = T['engine'] extends {
|
|
15
|
+
parameters: infer R;
|
|
16
|
+
} ? R : never;
|
|
17
|
+
export {};
|
|
18
|
+
}
|
package/dist/services/query.d.ts
CHANGED
|
@@ -104,8 +104,8 @@ export declare namespace Query {
|
|
|
104
104
|
};
|
|
105
105
|
type WhereRelationField<T extends AnyObject> = WhereObjectField<T> & {
|
|
106
106
|
NOT?: WhereRelationField<T>;
|
|
107
|
-
AND?: WhereRelationField<T
|
|
108
|
-
OR?: WhereRelationField<T
|
|
107
|
+
AND?: WhereRelationField<T>[];
|
|
108
|
+
OR?: WhereRelationField<T>[];
|
|
109
109
|
};
|
|
110
110
|
type WhereRelationFilters<T extends AnyObject> = {
|
|
111
111
|
[P in keyof T]?: IsObject<T[P]> extends true ? IsObjectEmpty<T[P]> extends false ? null | WhereRelationField<T[P]> : null | {} : never;
|
|
@@ -18,27 +18,31 @@ export declare namespace Transaction {
|
|
|
18
18
|
/**
|
|
19
19
|
* Determines the transaction operation based on the given database service.
|
|
20
20
|
*/
|
|
21
|
-
export type
|
|
22
|
-
transaction: infer O;
|
|
23
|
-
} ? O extends TransactionType.Interactive ? WriteOperation<T> | InteractiveOperation<T, R> : WriteOperation<T> : never;
|
|
21
|
+
export type Type<T extends Database.Service, R> = EngineTransactionType<T> extends TransactionType.Interactive ? StaticOperationType<T> | InteractiveOperationType<T, R> : StaticOperationType<T>;
|
|
24
22
|
/**
|
|
25
|
-
* Interactive
|
|
23
|
+
* Interactive operation type.
|
|
26
24
|
*/
|
|
27
|
-
export type
|
|
25
|
+
export type InteractiveOperationType<T extends Database.Service, R = void> = (client: Client<T>) => Promise<R> | R;
|
|
28
26
|
/**
|
|
29
|
-
*
|
|
27
|
+
* Static operation type.
|
|
30
28
|
*/
|
|
31
|
-
export type
|
|
32
|
-
[P in keyof TableSchemas<T>]?: (TableSchemas<T>[P] extends Database.Schema ?
|
|
29
|
+
export type StaticOperationType<T extends Database.Service> = {
|
|
30
|
+
[P in keyof TableSchemas<T>]?: (TableSchemas<T>[P] extends Database.Schema ? AnyOperationType<TableSchemas<T>[P], TableIndex<P, IndexedTables<T>>, TableRelation<P, RelationTables<T>>> : AnyObject)[];
|
|
33
31
|
};
|
|
34
|
-
|
|
35
|
-
|
|
32
|
+
/**
|
|
33
|
+
* Extract the transaction type from the given database service.
|
|
34
|
+
*/
|
|
35
|
+
type EngineTransactionType<T extends Database.Service> = T['engine'] extends {
|
|
36
|
+
transaction: infer O;
|
|
37
|
+
} ? O : never;
|
|
38
|
+
type AnyOperationType<T extends Database.Schema, I extends Database.Indexes, R extends RelationMetadata> = InsertOperationType<T, R> | UpdateOperationType<T, I, R> | DeleteOperationType<T, I, R>;
|
|
39
|
+
type InsertOperationType<T extends Database.Schema, R extends RelationMetadata> = {
|
|
36
40
|
insert: Omit<Query.InsertOneInput<T, Query.SelectInput<T, R>, R>, 'select'>;
|
|
37
41
|
};
|
|
38
|
-
type
|
|
42
|
+
type UpdateOperationType<T extends Database.Schema, I extends Database.Indexes, R extends RelationMetadata> = {
|
|
39
43
|
update: Omit<Query.UpdateOneInput<T, Query.SelectInput<T, R>, I, R>, 'select' | 'include'>;
|
|
40
44
|
};
|
|
41
|
-
type
|
|
45
|
+
type DeleteOperationType<T extends Database.Schema, I extends Database.Indexes, R extends RelationMetadata> = {
|
|
42
46
|
delete: Omit<Query.DeleteOneInput<T, Query.SelectInput<T, R>, I, R>, 'select' | 'include'>;
|
|
43
47
|
};
|
|
44
48
|
export {};
|
package/dist/types/engine.d.ts
CHANGED
package/dist/types/stream.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ez4/database",
|
|
3
3
|
"description": "EZ4: Components to build database services",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.18.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.
|
|
46
|
-
"@ez4/project": "^0.
|
|
47
|
-
"@ez4/reflection": "^0.
|
|
48
|
-
"@ez4/schema": "^0.
|
|
49
|
-
"@ez4/utils": "^0.
|
|
45
|
+
"@ez4/common": "^0.18.0",
|
|
46
|
+
"@ez4/project": "^0.18.0",
|
|
47
|
+
"@ez4/reflection": "^0.18.0",
|
|
48
|
+
"@ez4/schema": "^0.18.0",
|
|
49
|
+
"@ez4/utils": "^0.18.0"
|
|
50
50
|
}
|
|
51
51
|
}
|