@ez4/database 0.14.0 → 0.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/library.cjs +90 -87
- package/dist/library.mjs +89 -83
- package/dist/metadata/stream.d.ts +2 -4
- package/dist/metadata/table.d.ts +2 -2
- package/dist/services/client.d.ts +1 -1
- package/dist/services/database.d.ts +28 -13
- package/dist/services/indexes.d.ts +1 -1
- package/dist/services/query.d.ts +8 -8
- package/dist/services/relations.d.ts +1 -1
- package/dist/services/schemas.d.ts +1 -1
- package/dist/services/streams.d.ts +29 -8
- package/dist/services/table.d.ts +3 -7
- package/dist/services/transaction.d.ts +4 -4
- package/dist/types/stream.d.ts +2 -0
- package/package.json +7 -7
package/dist/library.cjs
CHANGED
|
@@ -1,96 +1,99 @@
|
|
|
1
|
-
"use strict";var
|
|
2
|
-
typeof t=="object"||typeof t=="function")for(let
|
|
3
|
-
|
|
4
|
-
IncompleteTableError:()=>
|
|
1
|
+
"use strict";var Y=Object.defineProperty;var Ae=Object.getOwnPropertyDescriptor;var ze=Object.getOwnPropertyNames;var Ce=Object.prototype.hasOwnProperty;var Ne=(e,t)=>{for(var r in t)Y(e,r,{get:t[r],enumerable:!0})},He=(e,t,r,o)=>{if(t&&
|
|
2
|
+
typeof t=="object"||typeof t=="function")for(let n of ze(t))!Ce.call(e,n)&&n!==r&&
|
|
3
|
+
Y(e,n,{get:()=>t[n],enumerable:!(o=Ae(t,n))||o.enumerable});return e};var $e=e=>He(Y({},"__esModule",{value:!0}),e);var We={};Ne(We,{IncompleteHandlerError:()=>F,IncompleteServiceError:()=>w,IncompleteStreamError:()=>H,
|
|
4
|
+
IncompleteTableError:()=>k,IncorrectIndexesTypeError:()=>O,IncorrectRelationsTypeError:()=>D,
|
|
5
5
|
IncorrectSchemaTypeError:()=>N,IncorrectStreamTypeError:()=>q,InvalidIndexReferenceError:()=>z,
|
|
6
|
-
InvalidIndexTypeError:()=>
|
|
7
|
-
InvalidRelationColumnError:()=>
|
|
8
|
-
InvalidRelationsTypeError:()=>
|
|
9
|
-
ServiceType:()=>U,getDatabaseServices:()=>
|
|
10
|
-
isDatabaseService:()=>
|
|
11
|
-
super("Invalid table relations type",void 0,"Database.Relations",t)}},
|
|
6
|
+
InvalidIndexTypeError:()=>A,InvalidIndexesTypeError:()=>R,InvalidRelationAliasError:()=>E,
|
|
7
|
+
InvalidRelationColumnError:()=>x,InvalidRelationTableError:()=>j,InvalidRelationTargetError:()=>P,
|
|
8
|
+
InvalidRelationsTypeError:()=>v,InvalidSchemaTypeError:()=>C,InvalidStreamTypeError:()=>$,
|
|
9
|
+
ServiceType:()=>U,getDatabaseServices:()=>ee,getDatabaseTable:()=>L,getTableSchema:()=>Z,
|
|
10
|
+
isDatabaseService:()=>qe,registerTriggers:()=>Qe});module.exports=$e(We);var we=require("@ez4/common/library"),ke=require("@ez4/schema/library"),Re=require("@ez4/project/library");var c=require("@ez4/common/library"),Pe=require("@ez4/reflection");var f=require("@ez4/common/library"),v=class extends f.InvalidTypeError{constructor(t){
|
|
11
|
+
super("Invalid table relations type",void 0,"Database.Relations",t)}},D=class extends f.IncorrectTypeError{constructor(r,o){
|
|
12
12
|
super("Incorrect table relations type",r,"Database.Relations",o);this.schemaType=
|
|
13
|
-
r}},P=class extends
|
|
14
|
-
the pattern 'column@alias'.`,o);this.relationSource=r}},j=class extends
|
|
15
|
-
super(`Relation table ${r} don't exists.`,o);this.relationTable=r}},
|
|
16
|
-
super(`Relation column ${r} don't exists.`,o);this.relationColumn=r}},E=class extends
|
|
13
|
+
r}},P=class extends f.TypeError{constructor(r,o){super(`Target ${r} must follow \
|
|
14
|
+
the pattern 'column@alias'.`,o);this.relationSource=r}},j=class extends f.TypeError{constructor(r,o){
|
|
15
|
+
super(`Relation table ${r} don't exists.`,o);this.relationTable=r}},x=class extends f.TypeError{constructor(r,o){
|
|
16
|
+
super(`Relation column ${r} don't exists.`,o);this.relationColumn=r}},E=class extends f.TypeError{constructor(r,o){
|
|
17
17
|
super(`Relation alias ${r} can't override table columns.`,o);this.relationAlias=
|
|
18
|
-
r}};var
|
|
19
|
-
super("Incomplete database service",t,r)}};var
|
|
20
|
-
e)&&(0,
|
|
21
|
-
(0,
|
|
22
|
-
e),
|
|
23
|
-
e,"Database.Indexes"),
|
|
24
|
-
e,"Database.Stream");var
|
|
25
|
-
super("Incomplete database table",t,r)}};var
|
|
26
|
-
super("Invalid table indexes type",void 0,"Database.Indexes",t)}},
|
|
18
|
+
r}};var te=require("@ez4/common/library"),w=class extends te.IncompleteTypeError{constructor(t,r){
|
|
19
|
+
super("Incomplete database service",t,r)}};var U="@ez4/database",qe=e=>e.type===U;var u=require("@ez4/common/library"),V=require("@ez4/reflection"),_=e=>(0,u.isClassDeclaration)(
|
|
20
|
+
e)&&(0,u.hasHeritageType)(e,"Database.Service"),oe=e=>(0,u.isModelDeclaration)(e)&&
|
|
21
|
+
(0,u.hasHeritageType)(e,"Database.Table"),ne=e=>(0,V.isTypeCallback)(e)||(0,V.isTypeFunction)(
|
|
22
|
+
e),ae=e=>(0,u.hasHeritageType)(e,"Database.Relations"),se=e=>(0,u.hasHeritageType)(
|
|
23
|
+
e,"Database.Indexes"),ie=e=>(0,u.hasHeritageType)(e,"Database.Schema"),le=e=>(0,u.hasHeritageType)(
|
|
24
|
+
e,"Database.Stream");var T=require("@ez4/common/library"),h=require("@ez4/reflection");var pe=require("@ez4/common/library"),k=class extends pe.IncompleteTypeError{constructor(t,r){
|
|
25
|
+
super("Incomplete database table",t,r)}};var y=require("@ez4/common/library"),R=class extends y.InvalidTypeError{constructor(t){
|
|
26
|
+
super("Invalid table indexes type",void 0,"Database.Indexes",t)}},O=class extends y.IncorrectTypeError{constructor(r,o){
|
|
27
27
|
super("Incorrect table indexes type",r,"Database.Indexes",o);this.schemaType=r}},
|
|
28
|
-
|
|
29
|
-
t follow one of the Index options.`,o);this.indexName=r}},z=class extends
|
|
30
|
-
super(`Invalid index reference, ${r} must be valid column.`,o);this.indexName=r}};var
|
|
31
|
-
return
|
|
32
|
-
e),r):(0,
|
|
33
|
-
new
|
|
34
|
-
if(!(0,
|
|
35
|
-
|
|
36
|
-
p
|
|
37
|
-
return o};var
|
|
38
|
-
return
|
|
39
|
-
e),r):(0,
|
|
40
|
-
new
|
|
41
|
-
if(!(0,
|
|
42
|
-
|
|
43
|
-
columns:a.split(":"),type:
|
|
44
|
-
return o};var G=require("@ez4/
|
|
28
|
+
A=class extends y.TypeError{constructor(r,o){super(`Invalid index type, ${r} mus\
|
|
29
|
+
t follow one of the Index options.`,o);this.indexName=r}},z=class extends y.TypeError{constructor(r,o){
|
|
30
|
+
super(`Invalid index reference, ${r} must be valid column.`,o);this.indexName=r}};var d=require("@ez4/common/library"),g=require("@ez4/reflection");var ue=(e,t,r,o)=>{if(!(0,g.isTypeReference)(e))return me(e,t,o);let n=(0,d.getReferenceType)(
|
|
31
|
+
e,r);return n?me(n,t,o):null},me=(e,t,r)=>(0,g.isTypeObject)(e)?ce(e,(0,d.getObjectMembers)(
|
|
32
|
+
e),r):(0,d.isModelDeclaration)(e)?ae(e)?ce(e,(0,d.getModelMembers)(e),r):(r.push(
|
|
33
|
+
new D(e.name,e.file)),null):(r.push(new v(t.file)),null),ce=(e,t,r)=>{let o=[];for(let n of t){
|
|
34
|
+
if(!(0,g.isModelProperty)(n)||n.inherited)continue;let a=(0,d.getPropertyString)(
|
|
35
|
+
n);if(!a)return r.push(new P(n.name,e.file)),null;let[l,s]=n.name.split(":",2),[
|
|
36
|
+
i,p]=a.split("@",2);o.push({sourceTable:l,sourceColumn:s,targetColumn:i,targetAlias:p})}
|
|
37
|
+
return o};var b=require("@ez4/common/library"),S=require("@ez4/reflection");var Te=(e,t,r,o)=>{if(!(0,S.isTypeReference)(e))return de(e,t,o);let n=(0,b.getReferenceType)(
|
|
38
|
+
e,r);return n?de(n,t,o):null},de=(e,t,r)=>(0,S.isTypeObject)(e)?be(e,(0,b.getObjectMembers)(
|
|
39
|
+
e),r):(0,b.isModelDeclaration)(e)?se(e)?be(e,(0,b.getModelMembers)(e),r):(r.push(
|
|
40
|
+
new O(e.name,e.file)),null):(r.push(new R(t.file)),null),be=(e,t,r)=>{let o=[];for(let n of t){
|
|
41
|
+
if(!(0,S.isModelProperty)(n)||n.inherited)continue;let a=n.name,l=(0,b.getPropertyString)(
|
|
42
|
+
n);switch(l){case"primary":case"secondary":case"unique":case"ttl":o.push({name:a,
|
|
43
|
+
columns:a.split(":"),type:l});break;default:return r.push(new A(a,e.file)),null}}
|
|
44
|
+
return o};var G=require("@ez4/common/library"),J=require("@ez4/schema/library"),K=require("@ez4/reflection");var B=require("@ez4/common/library"),C=class extends B.InvalidTypeError{constructor(t){
|
|
45
45
|
super("Invalid table schema type",void 0,"Database.Schema",t)}},N=class extends B.IncorrectTypeError{constructor(r,o){
|
|
46
|
-
super("Incorrect table schema type",r,"Database.Schema",o);this.schemaType=r}};var
|
|
47
|
-
return
|
|
48
|
-
e)?
|
|
49
|
-
|
|
50
|
-
null};var
|
|
51
|
-
super("Incomplete table stream",t,r)}},$=class extends
|
|
52
|
-
super("Invalid table stream type",void 0,"Database.Stream",t)}},q=class extends
|
|
46
|
+
super("Incorrect table schema type",r,"Database.Schema",o);this.schemaType=r}};var Z=(e,t,r,o)=>{if(!(0,K.isTypeReference)(e))return fe(e,t,r,o);let n=(0,G.getReferenceType)(
|
|
47
|
+
e,r);return n?fe(n,t,r,o):null},fe=(e,t,r,o)=>(0,K.isTypeObject)(e)?ye(e,r):(0,G.isModelDeclaration)(
|
|
48
|
+
e)?ie(e)?ye(e,r):(o.push(new N(e.name,e.file)),null):(o.push(new C(t.file)),null),
|
|
49
|
+
ye=(e,t)=>{let r=(0,J.getObjectSchema)(e,t);return r&&(0,J.isObjectSchema)(r)?r:
|
|
50
|
+
null};var m=require("@ez4/common/library"),I=require("@ez4/reflection");var M=require("@ez4/common/library"),H=class extends M.IncompleteTypeError{constructor(t,r){
|
|
51
|
+
super("Incomplete table stream",t,r)}},$=class extends M.InvalidTypeError{constructor(t){
|
|
52
|
+
super("Invalid table stream type",void 0,"Database.Stream",t)}},q=class extends M.IncorrectTypeError{constructor(r,o){
|
|
53
53
|
super("Incorrect table stream type",r,"Database.Stream",o);this.streamType=r}};var xe=require("@ez4/common/library"),F=class extends xe.IncompleteTypeError{constructor(t,r){
|
|
54
|
-
super("Incomplete stream handler",t,r)}};var ge=(e,t,r)=>{if(!
|
|
55
|
-
return e.description&&(o.description=e.description),(o.name=e.name)&&
|
|
56
|
-
ame"),(o.file=e.file)&&
|
|
57
|
-
0&&
|
|
58
|
-
return
|
|
59
|
-
|
|
60
|
-
e),r,o):(o.push(new q(e.name,e.file)),null):(o.push(new $(
|
|
61
|
-
let
|
|
62
|
-
inherited))switch(
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
e
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
s))
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
p
|
|
82
|
-
a
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
54
|
+
super("Incomplete stream handler",t,r)}};var ge=(e,t,r)=>{if(!ne(e))return null;let o={},n=new Set(["name","file","change"]);
|
|
55
|
+
return e.description&&(o.description=e.description),(o.name=e.name)&&n.delete("n\
|
|
56
|
+
ame"),(o.file=e.file)&&n.delete("file"),e.parameters&&n.delete("change"),n.size===
|
|
57
|
+
0&&Fe(o)?o:(r.push(new F([...n],e.file)),null)},Fe=e=>!!e.name&&!!e.file;var Ie=(e,t,r,o)=>{if(!(0,I.isTypeReference)(e))return Se(e,t,r,o);let n=(0,m.getReferenceType)(
|
|
58
|
+
e,r);return n?Se(n,t,r,o):null},Ue=e=>!!e.handler,Se=(e,t,r,o)=>(0,I.isTypeObject)(
|
|
59
|
+
e)?Me(e,t,(0,m.getObjectMembers)(e),r,o):(0,m.isModelDeclaration)(e)?le(e)?Me(e,
|
|
60
|
+
t,(0,m.getModelMembers)(e),r,o):(o.push(new q(e.name,e.file)),null):(o.push(new $(
|
|
61
|
+
t.file)),null),Me=(e,t,r,o,n)=>{let a={},l=new Set(["handler"]);for(let s of r)if(!(!(0,I.isModelProperty)(
|
|
62
|
+
s)||s.inherited))switch(s.name){default:n.push(new m.InvalidServicePropertyError(
|
|
63
|
+
t.name,s.name,e.file));break;case"handler":a.handler=ge(s.value,o,n);break;case"\
|
|
64
|
+
listener":a.listener=(0,m.getServiceListener)(s.value,n);break;case"memory":case"\
|
|
65
|
+
timeout":a[s.name]=(0,m.getPropertyNumber)(s);break;case"variables":a.variables=
|
|
66
|
+
(0,m.getLinkedVariableList)(s,n);break}return Ue(a)?a:(n.push(new H([...l],e.file)),
|
|
67
|
+
null)};var L=(e,t,r,o)=>{if(!(0,h.isTypeReference)(e))return he(e,t,r,o);let n=(0,T.getReferenceType)(
|
|
68
|
+
e,r);return n?he(n,t,r,o):null},Ve=e=>!!e.name&&!!e.schema&&!!e.indexes,he=(e,t,r,o)=>oe(
|
|
69
|
+
e)?ve(e,t,(0,T.getModelMembers)(e),r,o):(0,h.isTypeObject)(e)?ve(e,t,(0,T.getObjectMembers)(
|
|
70
|
+
e),r,o):null,ve=(e,t,r,o,n)=>{let a={},l=new Set(["name","schema","indexes"]);for(let i of r)
|
|
71
|
+
if(!(!(0,h.isModelProperty)(i)||i.inherited))switch(i.name){default:n.push(new T.InvalidServicePropertyError(
|
|
72
|
+
t.name,i.name,e.file));break;case"name":(a.name=(0,T.getPropertyString)(i))&&l.delete(
|
|
73
|
+
i.name);break;case"schema":(a.schema=Z(i.value,e,o,n))&&l.delete(i.name);break;case"\
|
|
74
|
+
indexes":(a.indexes=Te(i.value,e,o,n))&&l.delete(i.name);break;case"relations":a.
|
|
75
|
+
relations=ue(i.value,e,o,n);break;case"stream":a.stream=Ie(i.value,t,o,n);break}
|
|
76
|
+
if(!Ve(a))return n.push(new k([...l],e.file)),null;let s=_e(e,a.indexes,a.schema);
|
|
77
|
+
return s.length?(n.push(...s),null):a},_e=(e,t,r)=>{let o=r.properties,n=[];for(let{
|
|
78
|
+
name:a,columns:l}of t)l.some(i=>!o[i])&&n.push(new z(a,e.file));return n};var ee=e=>{let t={},r=[];for(let o in e){let n=e[o];if(!_(n)||(0,c.isExternalStatement)(
|
|
79
|
+
n))continue;let a={type:U,extras:{}},l=new Set(["engine","tables"]),s=n.file;a.name=
|
|
80
|
+
n.name;for(let p of(0,c.getModelMembers)(n))if(!(!(0,Pe.isModelProperty)(p)||p.inherited))
|
|
81
|
+
switch(p.name){default:r.push(new c.InvalidServicePropertyError(a.name,p.name,s));
|
|
82
|
+
break;case"engine":(a.engine=(0,c.getPropertyString)(p))&&l.delete(p.name);break;case"\
|
|
83
|
+
tables":(a.tables=Ge(p,n,e,r))&&l.delete(p.name);break;case"variables":a.variables=
|
|
84
|
+
(0,c.getLinkedVariableList)(p,r);break;case"services":a.services=(0,c.getLinkedServiceList)(
|
|
85
|
+
p,e,r);break}if(!Be(a)){r.push(new w([...l],s));continue}let i=Je(n,a.tables);if(i.
|
|
86
|
+
length){r.push(...i);continue}if(t[n.name]){r.push(new c.DuplicateServiceError(n.
|
|
87
|
+
name,s));continue}t[n.name]=a}return{services:t,errors:r}},Be=e=>!!e.name&&!!e.tables&&
|
|
88
|
+
!!e.extras,Ge=(e,t,r,o)=>{let n=(0,c.getPropertyTuple)(e)??[],a=[];for(let l of n){
|
|
89
|
+
let s=L(l,t,r,o);s&&a.push(s)}return a},Je=(e,t)=>{let r=Ke(t),o=[];for(let{relations:n,
|
|
90
|
+
schema:a,indexes:l}of t){if(!n)continue;let s=a.properties;for(let i of n){let{sourceTable:p,
|
|
91
|
+
sourceColumn:Q,targetColumn:W,targetAlias:re}=i;s[W]||o.push(new x(W,e.file)),s[re]&&
|
|
92
|
+
o.push(new E(re,e.file));let X=r[p]?.schema.properties;X||o.push(new j(p,e.file)),
|
|
93
|
+
X&&!X[Q]&&o.push(new x(Q,e.file));let Oe=r[p]?.indexes??[];i.sourceIndex=De(Oe,Q),
|
|
94
|
+
i.targetIndex=De(l,W)}}return o},De=(e,t)=>e.find(({name:r})=>r===t)?.type,Ke=e=>e.
|
|
95
|
+
reduce((t,r)=>({...t,[r.name]:r}),{});var je=e=>_(e)?e.name:null;var Ee=!1,Qe=()=>{Ee||((0,we.registerTriggers)(),(0,ke.registerTriggers)(),(0,Re.createTrigger)(
|
|
96
|
+
"@ez4/database",{"metadata:getServices":ee,"metadata:getLinkedService":je}),Ee=!0)};0&&(module.exports={IncompleteHandlerError,IncompleteServiceError,IncompleteStreamError,
|
|
94
97
|
IncompleteTableError,IncorrectIndexesTypeError,IncorrectRelationsTypeError,IncorrectSchemaTypeError,
|
|
95
98
|
IncorrectStreamTypeError,InvalidIndexReferenceError,InvalidIndexTypeError,InvalidIndexesTypeError,
|
|
96
99
|
InvalidRelationAliasError,InvalidRelationColumnError,InvalidRelationTableError,InvalidRelationTargetError,
|
package/dist/library.mjs
CHANGED
|
@@ -1,92 +1,98 @@
|
|
|
1
|
-
import{registerTriggers as
|
|
2
|
-
import{createTrigger as
|
|
3
|
-
getLinkedVariableList as
|
|
4
|
-
import{isModelProperty as
|
|
1
|
+
import{registerTriggers as kr}from"@ez4/common/library";import{registerTriggers as Rr}from"@ez4/schema/library";
|
|
2
|
+
import{createTrigger as Or}from"@ez4/project/library";import{DuplicateServiceError as yr,InvalidServicePropertyError as xr,isExternalStatement as gr,
|
|
3
|
+
getLinkedServiceList as Sr,getLinkedVariableList as Mr,getPropertyString as Ir,getPropertyTuple as hr,
|
|
4
|
+
getModelMembers as vr}from"@ez4/common/library";import{isModelProperty as Dr}from"@ez4/reflection";import{IncorrectTypeError as me,InvalidTypeError as ce,TypeError as y}from"@ez4/common/library";
|
|
5
5
|
var u=class extends ce{constructor(t){super("Invalid table relations type",void 0,
|
|
6
|
-
"Database.Relations",t)}},
|
|
7
|
-
able relations type",r,"Database.Relations",o);this.schemaType=r}},
|
|
6
|
+
"Database.Relations",t)}},d=class extends me{constructor(r,o){super("Incorrect t\
|
|
7
|
+
able relations type",r,"Database.Relations",o);this.schemaType=r}},b=class extends y{constructor(r,o){
|
|
8
8
|
super(`Target ${r} must follow the pattern 'column@alias'.`,o);this.relationSource=
|
|
9
9
|
r}},T=class extends y{constructor(r,o){super(`Relation table ${r} don't exists.`,
|
|
10
10
|
o);this.relationTable=r}},c=class extends y{constructor(r,o){super(`Relation col\
|
|
11
11
|
umn ${r} don't exists.`,o);this.relationColumn=r}},f=class extends y{constructor(r,o){
|
|
12
12
|
super(`Relation alias ${r} can't override table columns.`,o);this.relationAlias=
|
|
13
|
-
r}};
|
|
14
|
-
super("Incomplete database service",t,r)}};import{hasHeritageType as
|
|
15
|
-
import{isTypeCallback as Te,isTypeFunction as fe}from"@ez4/reflection";var g=e=>
|
|
16
|
-
e)&&
|
|
17
|
-
$=e=>
|
|
18
|
-
chema"),U=e=>
|
|
19
|
-
|
|
13
|
+
r}};import{IncompleteTypeError as ue}from"@ez4/common/library";var x=class extends ue{constructor(t,r){
|
|
14
|
+
super("Incomplete database service",t,r)}};var z="@ez4/database",Hr=e=>e.type===z;import{hasHeritageType as m,isClassDeclaration as de,isModelDeclaration as be}from"@ez4/common/library";
|
|
15
|
+
import{isTypeCallback as Te,isTypeFunction as fe}from"@ez4/reflection";var g=e=>de(
|
|
16
|
+
e)&&m(e,"Database.Service"),N=e=>be(e)&&m(e,"Database.Table"),H=e=>Te(e)||fe(e),
|
|
17
|
+
$=e=>m(e,"Database.Relations"),q=e=>m(e,"Database.Indexes"),F=e=>m(e,"Database.S\
|
|
18
|
+
chema"),U=e=>m(e,"Database.Stream");import{InvalidServicePropertyError as ir,getModelMembers as lr,getObjectMembers as pr,
|
|
19
|
+
getPropertyString as mr,getReferenceType as cr}from"@ez4/common/library";import{
|
|
20
|
+
isModelProperty as ur,isTypeObject as dr,isTypeReference as br}from"@ez4/reflection";import{IncompleteTypeError as ye}from"@ez4/common/library";var S=class extends ye{constructor(t,r){
|
|
20
21
|
super("Incomplete database table",t,r)}};import{IncorrectTypeError as xe,InvalidTypeError as ge,TypeError as V}from"@ez4/common/library";
|
|
21
|
-
var
|
|
22
|
-
"Database.Indexes",t)}},
|
|
22
|
+
var M=class extends ge{constructor(t){super("Invalid table indexes type",void 0,
|
|
23
|
+
"Database.Indexes",t)}},I=class extends xe{constructor(r,o){super("Incorrect tab\
|
|
23
24
|
le indexes type",r,"Database.Indexes",o);this.schemaType=r}},h=class extends V{constructor(r,o){
|
|
24
25
|
super(`Invalid index type, ${r} must follow one of the Index options.`,o);this.indexName=
|
|
25
|
-
r}},
|
|
26
|
-
be valid column.`,o);this.indexName=r}};import{isModelDeclaration as Se,getModelMembers as
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
import{
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
super("Incomplete stream
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
a.
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
let
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
26
|
+
r}},v=class extends V{constructor(r,o){super(`Invalid index reference, ${r} must\
|
|
27
|
+
be valid column.`,o);this.indexName=r}};import{isModelDeclaration as Se,getModelMembers as Me,getObjectMembers as Ie,getPropertyString as he,
|
|
28
|
+
getReferenceType as ve}from"@ez4/common/library";import{isModelProperty as De,isTypeObject as Pe,
|
|
29
|
+
isTypeReference as je}from"@ez4/reflection";var G=(e,t,r,o)=>{if(!je(e))return _(e,t,o);let n=ve(e,r);return n?_(n,t,o):null},
|
|
30
|
+
_=(e,t,r)=>Pe(e)?B(e,Ie(e),r):Se(e)?$(e)?B(e,Me(e),r):(r.push(new d(e.name,e.file)),
|
|
31
|
+
null):(r.push(new u(t.file)),null),B=(e,t,r)=>{let o=[];for(let n of t){if(!De(n)||
|
|
32
|
+
n.inherited)continue;let a=he(n);if(!a)return r.push(new b(n.name,e.file)),null;
|
|
33
|
+
let[l,s]=n.name.split(":",2),[i,p]=a.split("@",2);o.push({sourceTable:l,sourceColumn:s,
|
|
34
|
+
targetColumn:i,targetAlias:p})}return o};import{isModelDeclaration as Ee,getModelMembers as we,getObjectMembers as ke,getPropertyString as Re,
|
|
35
|
+
getReferenceType as Oe}from"@ez4/common/library";import{isModelProperty as Ae,isTypeObject as ze,
|
|
36
|
+
isTypeReference as Ce}from"@ez4/reflection";var Q=(e,t,r,o)=>{if(!Ce(e))return J(e,t,o);let n=Oe(e,r);return n?J(n,t,o):null},
|
|
37
|
+
J=(e,t,r)=>ze(e)?K(e,ke(e),r):Ee(e)?q(e)?K(e,we(e),r):(r.push(new I(e.name,e.file)),
|
|
38
|
+
null):(r.push(new M(t.file)),null),K=(e,t,r)=>{let o=[];for(let n of t){if(!Ae(n)||
|
|
39
|
+
n.inherited)continue;let a=n.name,l=Re(n);switch(l){case"primary":case"secondary":case"\
|
|
40
|
+
unique":case"ttl":o.push({name:a,columns:a.split(":"),type:l});break;default:return r.
|
|
41
|
+
push(new h(a,e.file)),null}}return o};import{getReferenceType as $e,isModelDeclaration as qe}from"@ez4/common/library";
|
|
42
|
+
import{getObjectSchema as Fe,isObjectSchema as Ue}from"@ez4/schema/library";import{
|
|
43
|
+
isTypeObject as Ve,isTypeReference as _e}from"@ez4/reflection";import{IncorrectTypeError as Ne,InvalidTypeError as He}from"@ez4/common/library";
|
|
44
|
+
var D=class extends He{constructor(t){super("Invalid table schema type",void 0,"\
|
|
45
|
+
Database.Schema",t)}},P=class extends Ne{constructor(r,o){super("Incorrect table\
|
|
46
|
+
schema type",r,"Database.Schema",o);this.schemaType=r}};var Y=(e,t,r,o)=>{if(!_e(e))return W(e,t,r,o);let n=$e(e,r);return n?W(n,t,r,o):
|
|
47
|
+
null},W=(e,t,r,o)=>Ve(e)?X(e,r):qe(e)?F(e)?X(e,r):(o.push(new P(e.name,e.file)),
|
|
48
|
+
null):(o.push(new D(t.file)),null),X=(e,t)=>{let r=Fe(e,t);return r&&Ue(r)?r:null};import{InvalidServicePropertyError as We,isModelDeclaration as Xe,getLinkedVariableList as Ye,
|
|
49
|
+
getModelMembers as Ze,getObjectMembers as Le,getPropertyNumber as er,getServiceListener as rr,
|
|
50
|
+
getReferenceType as tr}from"@ez4/common/library";import{isModelProperty as or,isTypeObject as nr,
|
|
51
|
+
isTypeReference as ar}from"@ez4/reflection";import{IncompleteTypeError as Be,IncorrectTypeError as Ge,InvalidTypeError as Je}from"@ez4/common/library";
|
|
52
|
+
var j=class extends Be{constructor(t,r){super("Incomplete table stream",t,r)}},E=class extends Je{constructor(t){
|
|
53
|
+
super("Invalid table stream type",void 0,"Database.Stream",t)}},w=class extends Ge{constructor(r,o){
|
|
54
|
+
super("Incorrect table stream type",r,"Database.Stream",o);this.streamType=r}};import{IncompleteTypeError as Ke}from"@ez4/common/library";var k=class extends Ke{constructor(t,r){
|
|
55
|
+
super("Incomplete stream handler",t,r)}};var Z=(e,t,r)=>{if(!H(e))return null;let o={},n=new Set(["name","file","change"]);
|
|
56
|
+
return e.description&&(o.description=e.description),(o.name=e.name)&&n.delete("n\
|
|
57
|
+
ame"),(o.file=e.file)&&n.delete("file"),e.parameters&&n.delete("change"),n.size===
|
|
58
|
+
0&&Qe(o)?o:(r.push(new k([...n],e.file)),null)},Qe=e=>!!e.name&&!!e.file;var re=(e,t,r,o)=>{if(!ar(e))return L(e,t,r,o);let n=tr(e,r);return n?L(n,t,r,o):
|
|
59
|
+
null},sr=e=>!!e.handler,L=(e,t,r,o)=>nr(e)?ee(e,t,Le(e),r,o):Xe(e)?U(e)?ee(e,t,Ze(
|
|
60
|
+
e),r,o):(o.push(new w(e.name,e.file)),null):(o.push(new E(t.file)),null),ee=(e,t,r,o,n)=>{
|
|
61
|
+
let a={},l=new Set(["handler"]);for(let s of r)if(!(!or(s)||s.inherited))switch(s.
|
|
62
|
+
name){default:n.push(new We(t.name,s.name,e.file));break;case"handler":a.handler=
|
|
63
|
+
Z(s.value,o,n);break;case"listener":a.listener=rr(s.value,n);break;case"memory":case"\
|
|
64
|
+
timeout":a[s.name]=er(s);break;case"variables":a.variables=Ye(s,n);break}return sr(
|
|
65
|
+
a)?a:(n.push(new j([...l],e.file)),null)};var ne=(e,t,r,o)=>{if(!br(e))return te(e,t,r,o);let n=cr(e,r);return n?te(n,t,r,
|
|
66
|
+
o):null},Tr=e=>!!e.name&&!!e.schema&&!!e.indexes,te=(e,t,r,o)=>N(e)?oe(e,t,lr(e),
|
|
67
|
+
r,o):dr(e)?oe(e,t,pr(e),r,o):null,oe=(e,t,r,o,n)=>{let a={},l=new Set(["name","s\
|
|
68
|
+
chema","indexes"]);for(let i of r)if(!(!ur(i)||i.inherited))switch(i.name){default:
|
|
69
|
+
n.push(new ir(t.name,i.name,e.file));break;case"name":(a.name=mr(i))&&l.delete(i.
|
|
70
|
+
name);break;case"schema":(a.schema=Y(i.value,e,o,n))&&l.delete(i.name);break;case"\
|
|
71
|
+
indexes":(a.indexes=Q(i.value,e,o,n))&&l.delete(i.name);break;case"relations":a.
|
|
72
|
+
relations=G(i.value,e,o,n);break;case"stream":a.stream=re(i.value,t,o,n);break}if(!Tr(
|
|
73
|
+
a))return n.push(new S([...l],e.file)),null;let s=fr(e,a.indexes,a.schema);return s.
|
|
74
|
+
length?(n.push(...s),null):a},fr=(e,t,r)=>{let o=r.properties,n=[];for(let{name:a,
|
|
75
|
+
columns:l}of t)l.some(i=>!o[i])&&n.push(new v(a,e.file));return n};var se=e=>{let t={},r=[];for(let o in e){let n=e[o];if(!g(n)||gr(n))continue;let a={
|
|
76
|
+
type:z,extras:{}},l=new Set(["engine","tables"]),s=n.file;a.name=n.name;for(let p of vr(
|
|
77
|
+
n))if(!(!Dr(p)||p.inherited))switch(p.name){default:r.push(new xr(a.name,p.name,
|
|
78
|
+
s));break;case"engine":(a.engine=Ir(p))&&l.delete(p.name);break;case"tables":(a.
|
|
79
|
+
tables=jr(p,n,e,r))&&l.delete(p.name);break;case"variables":a.variables=Mr(p,r);
|
|
80
|
+
break;case"services":a.services=Sr(p,e,r);break}if(!Pr(a)){r.push(new x([...l],s));
|
|
81
|
+
continue}let i=Er(n,a.tables);if(i.length){r.push(...i);continue}if(t[n.name]){r.
|
|
82
|
+
push(new yr(n.name,s));continue}t[n.name]=a}return{services:t,errors:r}},Pr=e=>!!e.
|
|
83
|
+
name&&!!e.tables&&!!e.extras,jr=(e,t,r,o)=>{let n=hr(e)??[],a=[];for(let l of n){
|
|
84
|
+
let s=ne(l,t,r,o);s&&a.push(s)}return a},Er=(e,t)=>{let r=wr(t),o=[];for(let{relations:n,
|
|
85
|
+
schema:a,indexes:l}of t){if(!n)continue;let s=a.properties;for(let i of n){let{sourceTable:p,
|
|
86
|
+
sourceColumn:R,targetColumn:O,targetAlias:C}=i;s[O]||o.push(new c(O,e.file)),s[C]&&
|
|
87
|
+
o.push(new f(C,e.file));let A=r[p]?.schema.properties;A||o.push(new T(p,e.file)),
|
|
88
|
+
A&&!A[R]&&o.push(new c(R,e.file));let pe=r[p]?.indexes??[];i.sourceIndex=ae(pe,R),
|
|
89
|
+
i.targetIndex=ae(l,O)}}return o},ae=(e,t)=>e.find(({name:r})=>r===t)?.type,wr=e=>e.
|
|
90
|
+
reduce((t,r)=>({...t,[r.name]:r}),{});var ie=e=>g(e)?e.name:null;var le=!1,Yt=()=>{le||(kr(),Rr(),Or("@ez4/database",{"metadata:getServices":se,"\
|
|
91
|
+
metadata:getLinkedService":ie}),le=!0)};export{k as IncompleteHandlerError,x as IncompleteServiceError,j as IncompleteStreamError,
|
|
92
|
+
S as IncompleteTableError,I as IncorrectIndexesTypeError,d as IncorrectRelationsTypeError,
|
|
93
|
+
P as IncorrectSchemaTypeError,w as IncorrectStreamTypeError,v as InvalidIndexReferenceError,
|
|
94
|
+
h as InvalidIndexTypeError,M as InvalidIndexesTypeError,f as InvalidRelationAliasError,
|
|
95
|
+
c as InvalidRelationColumnError,T as InvalidRelationTableError,b as InvalidRelationTargetError,
|
|
96
|
+
u as InvalidRelationsTypeError,D as InvalidSchemaTypeError,E as InvalidStreamTypeError,
|
|
97
|
+
z as ServiceType,se as getDatabaseServices,ne as getDatabaseTable,Y as getTableSchema,
|
|
98
|
+
Hr as isDatabaseService,Yt as registerTriggers};
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import type { AllType, SourceMap, TypeModel
|
|
1
|
+
import type { AllType, SourceMap, TypeModel } from '@ez4/reflection';
|
|
2
2
|
import type { TableStream } from '../types/stream.js';
|
|
3
|
-
type
|
|
4
|
-
export declare const getTableStream: (type: AllType, parent: TypeParent, reflection: SourceMap, errorList: Error[]) => TableStream | null;
|
|
5
|
-
export {};
|
|
3
|
+
export declare const getTableStream: (type: AllType, parent: TypeModel, reflection: SourceMap, errorList: Error[]) => TableStream | null;
|
package/dist/metadata/table.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { AllType, SourceMap } from '@ez4/reflection';
|
|
1
|
+
import type { AllType, SourceMap, TypeModel } from '@ez4/reflection';
|
|
2
2
|
import type { DatabaseTable } from '../types/table.js';
|
|
3
|
-
export declare const getDatabaseTable: (type: AllType, reflection: SourceMap, errorList: Error[]) => DatabaseTable | null;
|
|
3
|
+
export declare const getDatabaseTable: (type: AllType, parent: TypeModel, reflection: SourceMap, errorList: Error[]) => DatabaseTable | null;
|
|
@@ -4,7 +4,7 @@ import type { Database } from './database.js';
|
|
|
4
4
|
/**
|
|
5
5
|
* Database client.
|
|
6
6
|
*/
|
|
7
|
-
export type Client<T extends Database.Service
|
|
7
|
+
export type Client<T extends Database.Service> = TableClients<T> & {
|
|
8
8
|
/**
|
|
9
9
|
* Prepare and execute the given query.
|
|
10
10
|
*
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import type { Service } from '@ez4/common';
|
|
2
2
|
import type { LinkedVariables } from '@ez4/project/library';
|
|
3
3
|
import type { StreamChange } from './streams.js';
|
|
4
|
-
import type { TableTypes } from './table.js';
|
|
5
4
|
import type { Client } from './client.js';
|
|
6
|
-
import type { Index } from './indexes.js';
|
|
7
5
|
/**
|
|
8
6
|
* Given a database service `T`, it returns all its table.
|
|
9
7
|
*/
|
|
@@ -27,20 +25,37 @@ export declare namespace Database {
|
|
|
27
25
|
/**
|
|
28
26
|
* Table indexes.
|
|
29
27
|
*/
|
|
30
|
-
type Indexes
|
|
31
|
-
|
|
32
|
-
|
|
28
|
+
type Indexes = {};
|
|
29
|
+
/**
|
|
30
|
+
* Incoming stream event.
|
|
31
|
+
*/
|
|
32
|
+
type Incoming<T extends Schema> = StreamChange<T & {
|
|
33
|
+
/**
|
|
34
|
+
* Request tracking Id.
|
|
35
|
+
*/
|
|
36
|
+
requestId: string;
|
|
37
|
+
}>;
|
|
38
|
+
/**
|
|
39
|
+
* Stream listener.
|
|
40
|
+
*/
|
|
41
|
+
type Listener<T extends Schema> = (event: Service.Event<Incoming<T> | StreamChange<T>>, context: Service.Context<Database.Service>) => Promise<void> | void;
|
|
42
|
+
/**
|
|
43
|
+
* Stream handler.
|
|
44
|
+
*/
|
|
45
|
+
type Handler<T extends Schema> = (request: Incoming<T> | StreamChange<T>, context: Service.Context<Database.Service>) => Promise<void> | void;
|
|
46
|
+
type ServiceEvent<T extends Schema = Schema> = Service.Event<Incoming<T>>;
|
|
33
47
|
/**
|
|
34
48
|
* Table stream.
|
|
35
49
|
*/
|
|
36
50
|
interface Stream<T extends Schema = Schema> {
|
|
51
|
+
/**
|
|
52
|
+
* Stream listener.
|
|
53
|
+
*/
|
|
54
|
+
listener?: Listener<T>;
|
|
37
55
|
/**
|
|
38
56
|
* Stream handler.
|
|
39
|
-
*
|
|
40
|
-
* @param change Stream change.
|
|
41
|
-
* @param context Handler context.
|
|
42
57
|
*/
|
|
43
|
-
handler:
|
|
58
|
+
handler: Handler<T>;
|
|
44
59
|
/**
|
|
45
60
|
* Variables associated to the handler.
|
|
46
61
|
*/
|
|
@@ -73,7 +88,7 @@ export declare namespace Database {
|
|
|
73
88
|
/**
|
|
74
89
|
* Table indexes.
|
|
75
90
|
*/
|
|
76
|
-
indexes: Indexes
|
|
91
|
+
indexes: Indexes;
|
|
77
92
|
/**
|
|
78
93
|
* Table stream configuration.
|
|
79
94
|
*/
|
|
@@ -82,7 +97,7 @@ export declare namespace Database {
|
|
|
82
97
|
/**
|
|
83
98
|
* Database service.
|
|
84
99
|
*/
|
|
85
|
-
abstract class Service
|
|
100
|
+
abstract class Service implements Service.Provider {
|
|
86
101
|
/**
|
|
87
102
|
* Determines which database engine to use.
|
|
88
103
|
* Check the provider package to know all the possible values.
|
|
@@ -91,10 +106,10 @@ export declare namespace Database {
|
|
|
91
106
|
/**
|
|
92
107
|
* Describe all available tables for the service.
|
|
93
108
|
*/
|
|
94
|
-
abstract tables:
|
|
109
|
+
abstract tables: Table<any>[];
|
|
95
110
|
/**
|
|
96
111
|
* Service client.
|
|
97
112
|
*/
|
|
98
|
-
client: Client<Service
|
|
113
|
+
client: Client<Service>;
|
|
99
114
|
}
|
|
100
115
|
}
|
|
@@ -46,7 +46,7 @@ export type DecomposeSecondaryIndexNames<T extends Database.Indexes> = Decompose
|
|
|
46
46
|
/**
|
|
47
47
|
* Given a database service `T`, it produces an object with all tables containing indexes.
|
|
48
48
|
*/
|
|
49
|
-
export type IndexedTables<T extends Database.Service
|
|
49
|
+
export type IndexedTables<T extends Database.Service> = MergeIndexes<DatabaseTables<T>>;
|
|
50
50
|
/**
|
|
51
51
|
* Given a list of tables with indexes `T`, it produces another object containing all the
|
|
52
52
|
* table indexes.
|
package/dist/services/query.d.ts
CHANGED
|
@@ -10,25 +10,25 @@ export declare namespace Query {
|
|
|
10
10
|
export type InsertOneInput<T extends Database.Schema, R extends RelationMetadata> = {
|
|
11
11
|
data: InsertDataInput<T, R>;
|
|
12
12
|
};
|
|
13
|
-
export type UpdateOneInput<T extends Database.Schema, S extends AnyObject, I extends Database.Indexes
|
|
13
|
+
export type UpdateOneInput<T extends Database.Schema, S extends AnyObject, I extends Database.Indexes, R extends RelationMetadata> = {
|
|
14
14
|
select?: StrictSelectInput<T, S, R>;
|
|
15
15
|
include?: StrictIncludeInput<S, R>;
|
|
16
16
|
data: OptionalObject<UpdateDataInput<T, R>>;
|
|
17
17
|
where: WhereInput<T, I, R>;
|
|
18
18
|
};
|
|
19
|
-
export type FindOneInput<T extends Database.Schema, S extends AnyObject, I extends Database.Indexes
|
|
19
|
+
export type FindOneInput<T extends Database.Schema, S extends AnyObject, I extends Database.Indexes, R extends RelationMetadata> = {
|
|
20
20
|
select: StrictSelectInput<T, S, R>;
|
|
21
21
|
include?: StrictIncludeInput<S, R>;
|
|
22
22
|
where: WhereInput<T, I, R>;
|
|
23
23
|
};
|
|
24
|
-
export type UpsertOneInput<T extends Database.Schema, S extends AnyObject, I extends Database.Indexes
|
|
24
|
+
export type UpsertOneInput<T extends Database.Schema, S extends AnyObject, I extends Database.Indexes, R extends RelationMetadata> = {
|
|
25
25
|
select?: StrictSelectInput<T, S, R>;
|
|
26
26
|
include?: StrictIncludeInput<S, R>;
|
|
27
27
|
update: OptionalObject<UpdateDataInput<T, R>>;
|
|
28
28
|
insert: InsertDataInput<T, R>;
|
|
29
29
|
where: WhereInput<T, I, R>;
|
|
30
30
|
};
|
|
31
|
-
export type DeleteOneInput<T extends Database.Schema, S extends AnyObject, I extends Database.Indexes
|
|
31
|
+
export type DeleteOneInput<T extends Database.Schema, S extends AnyObject, I extends Database.Indexes, R extends RelationMetadata> = {
|
|
32
32
|
select?: StrictSelectInput<T, S, R>;
|
|
33
33
|
include?: StrictIncludeInput<S, R>;
|
|
34
34
|
where: WhereInput<T, I, R>;
|
|
@@ -43,7 +43,7 @@ export declare namespace Query {
|
|
|
43
43
|
where?: WhereInput<T, {}, R>;
|
|
44
44
|
limit?: number;
|
|
45
45
|
};
|
|
46
|
-
export type FindManyInput<T extends Database.Schema, S extends AnyObject, I extends Database.Indexes
|
|
46
|
+
export type FindManyInput<T extends Database.Schema, S extends AnyObject, I extends Database.Indexes, R extends RelationMetadata> = {
|
|
47
47
|
select: StrictSelectInput<T, S, R>;
|
|
48
48
|
include?: StrictIncludeInput<S, R>;
|
|
49
49
|
where?: WhereInput<T, {}, R>;
|
|
@@ -81,7 +81,7 @@ export declare namespace Query {
|
|
|
81
81
|
export type OrderInput<I extends Database.Indexes> = {
|
|
82
82
|
[P in DecomposeIndexName<keyof I>]?: Order;
|
|
83
83
|
};
|
|
84
|
-
export type WhereInput<T extends Database.Schema, I extends Database.Indexes
|
|
84
|
+
export type WhereInput<T extends Database.Schema, I extends Database.Indexes, R extends RelationMetadata> = WhereInputFilters<T, I, R> & WhereNot<WhereInputFilters<T, I, R>> & WhereAnd<WhereInputFilters<T, I, R>> & WhereOr<WhereInputFilters<T, I, R>>;
|
|
85
85
|
export type WhereOperators = keyof (WhereNegate<any> & WhereEqual<any> & WhereGreaterThan<any> & WhereGreaterThanOrEqual<any> & WhereLessThan<any> & WhereLessThanOrEqual<any> & WhereIn<any> & WhereBetween<any> & WhereIsMissing & WhereIsNull & WhereStartsWith & WhereContains<any>);
|
|
86
86
|
type IndexFields<R extends RelationMetadata> = string extends R['indexes'] ? never : R['indexes'];
|
|
87
87
|
type SelectFields<T extends Database.Schema, R extends RelationMetadata> = IsObjectEmpty<R['selects']> extends true ? T : T & R['selects'];
|
|
@@ -103,8 +103,8 @@ export declare namespace Query {
|
|
|
103
103
|
type WhereOptionalFilters<T extends AnyObject, N extends string> = {
|
|
104
104
|
[P in Exclude<keyof T, N>]?: WhereField<T[P]>;
|
|
105
105
|
};
|
|
106
|
-
type WhereCommonFilters<T extends AnyObject, I extends Database.Indexes
|
|
107
|
-
type WhereInputFilters<T extends Database.Schema, I extends Database.Indexes
|
|
106
|
+
type WhereCommonFilters<T extends AnyObject, I extends Database.Indexes> = (WhereRequiredFilters<T, DecomposePrimaryIndexNames<I>> & WhereOptionalFilters<T, DecomposePrimaryIndexNames<I>>) | (WhereRequiredFilters<T, DecomposeUniqueIndexNames<I>> & WhereOptionalFilters<T, DecomposeUniqueIndexNames<I>>);
|
|
107
|
+
type WhereInputFilters<T extends Database.Schema, I extends Database.Indexes, R extends RelationMetadata> = WhereCommonFilters<T, I> & WhereRelationFilters<R['filters']>;
|
|
108
108
|
type WhereNot<T extends AnyObject> = {
|
|
109
109
|
NOT?: T | WhereAnd<T> | WhereOr<T>;
|
|
110
110
|
};
|
|
@@ -30,7 +30,7 @@ export type RelationTargetAlias<T> = T extends `${string}@${infer U}` ? U : neve
|
|
|
30
30
|
/**
|
|
31
31
|
* Given a database service `T`, it produces an object with all relation tables.
|
|
32
32
|
*/
|
|
33
|
-
export type RelationTables<T extends Database.Service
|
|
33
|
+
export type RelationTables<T extends Database.Service> = MergeRelations<DatabaseTables<T>, TableSchemas<T>, IndexedTables<T>>;
|
|
34
34
|
/**
|
|
35
35
|
* Given a list of tables with relations `T`, it produces an object containing all the
|
|
36
36
|
* relation tables.
|
|
@@ -3,7 +3,7 @@ import type { Database, DatabaseTables } from './database.js';
|
|
|
3
3
|
/**
|
|
4
4
|
* Given a database service `T`, it produces an object containing all tables with schemas.
|
|
5
5
|
*/
|
|
6
|
-
export type TableSchemas<T extends Database.Service
|
|
6
|
+
export type TableSchemas<T extends Database.Service> = MergeTables<DatabaseTables<T>>;
|
|
7
7
|
/**
|
|
8
8
|
* Given a list of tables with schema `T`, it produces an object containing all schemas.
|
|
9
9
|
*/
|
|
@@ -2,33 +2,54 @@
|
|
|
2
2
|
* Stream change for `insert`, `update` or `delete` operations.
|
|
3
3
|
*/
|
|
4
4
|
export type StreamChange<T> = StreamInsertChange<T> | StreamUpdateChange<T> | StreamDeleteChange<T>;
|
|
5
|
+
/**
|
|
6
|
+
* Stream change types.
|
|
7
|
+
*/
|
|
8
|
+
export declare const enum StreamType {
|
|
9
|
+
Insert = "insert",
|
|
10
|
+
Update = "update",
|
|
11
|
+
Delete = "delete"
|
|
12
|
+
}
|
|
5
13
|
/**
|
|
6
14
|
* Stream change for an `insert` operation.
|
|
7
15
|
*/
|
|
8
16
|
export type StreamInsertChange<T> = {
|
|
17
|
+
/**
|
|
18
|
+
* Change type.
|
|
19
|
+
*/
|
|
9
20
|
type: StreamType.Insert;
|
|
21
|
+
/**
|
|
22
|
+
* Inserted record.
|
|
23
|
+
*/
|
|
10
24
|
record: T;
|
|
11
25
|
};
|
|
12
26
|
/**
|
|
13
27
|
* Stream change for an `update` operation.
|
|
14
28
|
*/
|
|
15
29
|
export type StreamUpdateChange<T> = {
|
|
30
|
+
/**
|
|
31
|
+
* Change type.
|
|
32
|
+
*/
|
|
16
33
|
type: StreamType.Update;
|
|
34
|
+
/**
|
|
35
|
+
* Previous record.
|
|
36
|
+
*/
|
|
17
37
|
oldRecord: T;
|
|
38
|
+
/**
|
|
39
|
+
* Current record.
|
|
40
|
+
*/
|
|
18
41
|
newRecord: T;
|
|
19
42
|
};
|
|
20
43
|
/**
|
|
21
44
|
* Stream change for an `delete` operation.
|
|
22
45
|
*/
|
|
23
46
|
export type StreamDeleteChange<T> = {
|
|
47
|
+
/**
|
|
48
|
+
* Change type.
|
|
49
|
+
*/
|
|
24
50
|
type: StreamType.Delete;
|
|
51
|
+
/**
|
|
52
|
+
* Deleted record.
|
|
53
|
+
*/
|
|
25
54
|
record: T;
|
|
26
55
|
};
|
|
27
|
-
/**
|
|
28
|
-
* Stream change types.
|
|
29
|
-
*/
|
|
30
|
-
export declare const enum StreamType {
|
|
31
|
-
Insert = "insert",
|
|
32
|
-
Update = "update",
|
|
33
|
-
Delete = "delete"
|
|
34
|
-
}
|
package/dist/services/table.d.ts
CHANGED
|
@@ -1,13 +1,9 @@
|
|
|
1
|
-
import type { AnyObject,
|
|
1
|
+
import type { AnyObject, PropertyExists } from '@ez4/utils';
|
|
2
2
|
import type { RelationMetadata, RelationTables } from './relations.js';
|
|
3
3
|
import type { IndexedTables } from './indexes.js';
|
|
4
4
|
import type { TableSchemas } from './schemas.js';
|
|
5
5
|
import type { Database } from './database.js';
|
|
6
6
|
import type { Query } from './query.js';
|
|
7
|
-
/**
|
|
8
|
-
* Given an array of schemas `T`, it returns an union of `Database.Table` for each schema.
|
|
9
|
-
*/
|
|
10
|
-
export type TableTypes<T extends Database.Schema[]> = IsAny<T> extends true ? any : IsArrayEmpty<T> extends true ? Database.Table<Database.Schema> : Database.Table<T[0]> | TableTypes<ArrayRest<T>>;
|
|
11
7
|
/**
|
|
12
8
|
* Given an indexed table `T` and a property `P`, it returns all the indexes corresponding
|
|
13
9
|
* to the given property.
|
|
@@ -21,13 +17,13 @@ export type TableRelation<P, T extends AnyObject> = PropertyExists<P, T> extends
|
|
|
21
17
|
/**
|
|
22
18
|
* Given a database service `T`, it returns all table clients.
|
|
23
19
|
*/
|
|
24
|
-
export type TableClients<T extends Database.Service
|
|
20
|
+
export type TableClients<T extends Database.Service> = {
|
|
25
21
|
[P in keyof TableSchemas<T>]: TableSchemas<T>[P] extends Database.Schema ? Table<TableSchemas<T>[P], TableIndex<P, IndexedTables<T>>, TableRelation<P, RelationTables<T>>> : never;
|
|
26
22
|
};
|
|
27
23
|
/**
|
|
28
24
|
* Table client.
|
|
29
25
|
*/
|
|
30
|
-
export interface Table<T extends Database.Schema, I extends Database.Indexes
|
|
26
|
+
export interface Table<T extends Database.Schema, I extends Database.Indexes, R extends RelationMetadata> {
|
|
31
27
|
/**
|
|
32
28
|
* Insert one record into the database.
|
|
33
29
|
*
|
|
@@ -12,17 +12,17 @@ export declare namespace Transaction {
|
|
|
12
12
|
/**
|
|
13
13
|
* Write operations.
|
|
14
14
|
*/
|
|
15
|
-
export type WriteOperations<T extends Database.Service
|
|
15
|
+
export type WriteOperations<T extends Database.Service> = {
|
|
16
16
|
[P in keyof TableSchemas<T>]?: (TableSchemas<T>[P] extends Database.Schema ? AnyOperation<TableSchemas<T>[P], TableIndex<P, IndexedTables<T>>, TableRelation<P, RelationTables<T>>> : AnyObject)[];
|
|
17
17
|
};
|
|
18
|
-
type AnyOperation<T extends Database.Schema, I extends Database.Indexes
|
|
18
|
+
type AnyOperation<T extends Database.Schema, I extends Database.Indexes, R extends RelationMetadata> = InsertOperation<T, R> | UpdateOperation<T, I, R> | DeleteOperation<T, I, R>;
|
|
19
19
|
type InsertOperation<T extends Database.Schema, R extends RelationMetadata> = {
|
|
20
20
|
insert: Query.InsertOneInput<T, R>;
|
|
21
21
|
};
|
|
22
|
-
type UpdateOperation<T extends Database.Schema, I extends Database.Indexes
|
|
22
|
+
type UpdateOperation<T extends Database.Schema, I extends Database.Indexes, R extends RelationMetadata> = {
|
|
23
23
|
update: Omit<Query.UpdateOneInput<T, Query.SelectInput<T, R>, I, R>, 'select' | 'include'>;
|
|
24
24
|
};
|
|
25
|
-
type DeleteOperation<T extends Database.Schema, I extends Database.Indexes
|
|
25
|
+
type DeleteOperation<T extends Database.Schema, I extends Database.Indexes, R extends RelationMetadata> = {
|
|
26
26
|
delete: Omit<Query.DeleteOneInput<T, Query.SelectInput<T, R>, I, R>, 'select' | 'include'>;
|
|
27
27
|
};
|
|
28
28
|
export {};
|
package/dist/types/stream.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { LinkedVariables } from '@ez4/project/library';
|
|
2
|
+
import type { ServiceListener } from '@ez4/common/library';
|
|
2
3
|
import type { StreamHandler } from './handler.js';
|
|
3
4
|
export type TableStream = {
|
|
5
|
+
listener?: ServiceListener;
|
|
4
6
|
handler: StreamHandler;
|
|
5
7
|
variables?: LinkedVariables | null;
|
|
6
8
|
timeout?: number;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ez4/database",
|
|
3
3
|
"description": "EZ4: Components to build database services",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.16.0",
|
|
5
5
|
"author": "Silas B.",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"type": "module",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"directory": "packages/database"
|
|
15
15
|
},
|
|
16
16
|
"engines": {
|
|
17
|
-
"node": ">=
|
|
17
|
+
"node": ">=22.3.0"
|
|
18
18
|
},
|
|
19
19
|
"exports": {
|
|
20
20
|
".": {
|
|
@@ -42,10 +42,10 @@
|
|
|
42
42
|
"live:publish": "npm run test && npm publish --access public"
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@ez4/common": "^0.
|
|
46
|
-
"@ez4/project": "^0.
|
|
47
|
-
"@ez4/reflection": "^0.
|
|
48
|
-
"@ez4/schema": "^0.
|
|
49
|
-
"@ez4/utils": "^0.
|
|
45
|
+
"@ez4/common": "^0.16.0",
|
|
46
|
+
"@ez4/project": "^0.16.0",
|
|
47
|
+
"@ez4/reflection": "^0.16.0",
|
|
48
|
+
"@ez4/schema": "^0.16.0",
|
|
49
|
+
"@ez4/utils": "^0.16.0"
|
|
50
50
|
}
|
|
51
51
|
}
|