@ez4/database 0.3.0 → 0.4.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.
@@ -1,4 +1,11 @@
1
- import { IncompleteTypeError } from '@ez4/common/library';
1
+ import { IncompleteTypeError, IncorrectTypeError, InvalidTypeError } from '@ez4/common/library';
2
2
  export declare class IncompleteStreamError extends IncompleteTypeError {
3
3
  constructor(properties: string[], fileName?: string);
4
4
  }
5
+ export declare class InvalidStreamTypeError extends InvalidTypeError {
6
+ constructor(fileName?: string);
7
+ }
8
+ export declare class IncorrectStreamTypeError extends IncorrectTypeError {
9
+ streamType: string;
10
+ constructor(streamType: string, fileName?: string);
11
+ }
package/dist/library.cjs CHANGED
@@ -1,65 +1,68 @@
1
- "use strict";var w=Object.defineProperty;var me=Object.getOwnPropertyDescriptor;var le=Object.getOwnPropertyNames;var ce=Object.prototype.hasOwnProperty;var ue=(e,t)=>{for(var r in t)w(e,r,{get:t[r],enumerable:!0})},be=(e,t,r,a)=>{if(t&&
2
- typeof t=="object"||typeof t=="function")for(let o of le(t))!ce.call(e,o)&&o!==r&&
3
- w(e,o,{get:()=>t[o],enumerable:!(a=me(t,o))||a.enumerable});return e};var fe=e=>be(w({},"__esModule",{value:!0}),e);var ve={};ue(ve,{IncompleteHandlerError:()=>j,IncompleteServiceError:()=>y,IncompleteStreamError:()=>D,
4
- IncompleteTableError:()=>x,IncorrectIndexesTypeError:()=>S,IncorrectSchemaTypeError:()=>I,
5
- InvalidIndexReferenceError:()=>h,InvalidIndexTypeError:()=>M,InvalidIndexesTypeError:()=>g,
6
- InvalidSchemaTypeError:()=>v,ServiceType:()=>E,getDatabaseServices:()=>H,getDatabaseTable:()=>C,
7
- getTableSchema:()=>R,isDatabaseService:()=>Te,registerTriggers:()=>he});module.exports=
8
- fe(ve);var ne=require("@ez4/common/library"),ie=require("@ez4/schema/library"),pe=require("@ez4/project/library");var c=require("@ez4/common/library"),oe=require("@ez4/reflection");var E="@ez4/database",Te=e=>e.type===E;var q=require("@ez4/common/library"),y=class extends q.IncompleteTypeError{constructor(t,r){
9
- super("Incomplete database service",t,r)}};var T=require("@ez4/common/library"),d=require("@ez4/reflection");var F=require("@ez4/common/library"),x=class extends F.IncompleteTypeError{constructor(t,r){
10
- super("Incomplete database table",t,r)}};var u=require("@ez4/common/library"),g=class extends u.InvalidTypeError{constructor(t){
11
- super("Invalid table indexes type",void 0,"Database.Indexes",t)}},S=class extends u.IncorrectTypeError{constructor(r,a){
1
+ "use strict";var C=Object.defineProperty;var ce=Object.getOwnPropertyDescriptor;var ue=Object.getOwnPropertyNames;var be=Object.prototype.hasOwnProperty;var fe=(e,t)=>{for(var r in t)C(e,r,{get:t[r],enumerable:!0})},Te=(e,t,r,a)=>{if(t&&
2
+ typeof t=="object"||typeof t=="function")for(let o of ue(t))!be.call(e,o)&&o!==r&&
3
+ C(e,o,{get:()=>t[o],enumerable:!(a=ce(t,o))||a.enumerable});return e};var de=e=>Te(C({},"__esModule",{value:!0}),e);var De={};fe(De,{IncompleteHandlerError:()=>A,IncompleteServiceError:()=>x,IncompleteStreamError:()=>j,
4
+ IncompleteTableError:()=>g,IncorrectIndexesTypeError:()=>M,IncorrectSchemaTypeError:()=>D,
5
+ IncorrectStreamTypeError:()=>P,InvalidIndexReferenceError:()=>I,InvalidIndexTypeError:()=>h,
6
+ InvalidIndexesTypeError:()=>S,InvalidSchemaTypeError:()=>v,InvalidStreamTypeError:()=>E,
7
+ ServiceType:()=>k,getDatabaseServices:()=>F,getDatabaseTable:()=>q,getTableSchema:()=>N,
8
+ isDatabaseService:()=>ye,registerTriggers:()=>ve});module.exports=de(De);var pe=require("@ez4/common/library"),me=require("@ez4/schema/library"),le=require("@ez4/project/library");var c=require("@ez4/common/library"),ne=require("@ez4/reflection");var k="@ez4/database",ye=e=>e.type===k;var U=require("@ez4/common/library"),x=class extends U.IncompleteTypeError{constructor(t,r){
9
+ super("Incomplete database service",t,r)}};var p=require("@ez4/common/library"),w=require("@ez4/reflection"),z=e=>(0,p.isClassDeclaration)(
10
+ e)&&(0,p.hasHeritageType)(e,"Database.Service"),$=e=>(0,p.isModelDeclaration)(e)&&
11
+ (0,p.hasHeritageType)(e,"Database.Table"),_=e=>(0,w.isTypeCallback)(e)||(0,w.isTypeFunction)(
12
+ e),B=e=>(0,p.hasHeritageType)(e,"Database.Indexes"),G=e=>(0,p.hasHeritageType)(e,
13
+ "Database.Schema"),J=e=>(0,p.hasHeritageType)(e,"Database.Stream");var d=require("@ez4/common/library"),y=require("@ez4/reflection");var K=require("@ez4/common/library"),g=class extends K.IncompleteTypeError{constructor(t,r){
14
+ super("Incomplete database table",t,r)}};var u=require("@ez4/common/library"),S=class extends u.InvalidTypeError{constructor(t){
15
+ super("Invalid table indexes type",void 0,"Database.Indexes",t)}},M=class extends u.IncorrectTypeError{constructor(r,a){
12
16
  super("Incorrect table indexes type",r,"Database.Indexes",a);this.schemaType=r}},
13
- M=class extends u.TypeError{constructor(r,a){super(`Invalid index type, ${r} mus\
14
- t follow one of the Index options.`,a);this.indexName=r}},h=class extends u.TypeError{constructor(r,a){
15
- super(`Invalid index reference, ${r} must be valid column.`,a);this.indexName=r}};var p=require("@ez4/common/library"),A=require("@ez4/reflection"),P=e=>(0,p.isClassDeclaration)(
16
- e)&&(0,p.hasHeritageType)(e,"Database.Service"),V=e=>(0,p.isModelDeclaration)(e)&&
17
- (0,p.hasHeritageType)(e,"Database.Table"),U=e=>(0,p.hasHeritageType)(e,"Database\
18
- .Schema"),$=e=>(0,p.hasHeritageType)(e,"Database.Indexes"),_=e=>(0,p.isModelDeclaration)(
19
- e)&&(0,p.hasHeritageType)(e,"Database.Stream"),B=e=>(0,A.isTypeCallback)(e)||(0,A.isTypeFunction)(
20
- e);var O=require("@ez4/reflection"),J=require("@ez4/common/library"),z=require("@ez4/schema/library");var k=require("@ez4/common/library"),v=class extends k.InvalidTypeError{constructor(t){
21
- super("Invalid table schema type",void 0,"Database.Schema",t)}},I=class extends k.IncorrectTypeError{constructor(r,a){
22
- super("Incorrect table schema type",r,"Database.Schema",a);this.schemaType=r}};var R=(e,t,r,a)=>{if(!(0,O.isTypeReference)(e))return G(e,t,r,a);let o=r[e.path];
23
- return o?G(o,t,r,a):null},G=(e,t,r,a)=>(0,O.isTypeObject)(e)?(0,z.getObjectSchema)(
24
- e,r):(0,J.isModelDeclaration)(e)?U(e)?(0,z.getObjectSchema)(e,r):(a.push(new I(e.
25
- name,e.file)),null):(a.push(new v(t.file)),null);var m=require("@ez4/common/library"),b=require("@ez4/reflection");var W=(e,t,r,a)=>{if(!(0,b.isTypeReference)(e))return K(e,t,a);let o=r[e.path];return o?
26
- K(o,t,a):null},K=(e,t,r)=>(0,b.isTypeObject)(e)?Q(e,(0,m.getObjectMembers)(e),r):
27
- (0,m.isModelDeclaration)(e)?$(e)?Q(e,(0,m.getModelMembers)(e),r):(r.push(new S(e.
28
- name,e.file)),null):(r.push(new g(t.file)),null),Q=(e,t,r)=>{let a={};for(let o of t){
29
- if(!(0,b.isModelProperty)(o))continue;let s=o.name,i=(0,m.getPropertyString)(o);
30
- switch(i){case"primary":case"regular":case"unique":case"ttl":a[s]=i;break;default:
31
- return r.push(new M(s,e.file)),null}}return a};var l=require("@ez4/common/library"),f=require("@ez4/reflection");var X=require("@ez4/common/library"),D=class extends X.IncompleteTypeError{constructor(t,r){
32
- super("Incomplete table stream",t,r)}};var Y=require("@ez4/common/library"),j=class extends Y.IncompleteTypeError{constructor(t,r){
33
- super("Incomplete stream handler",t,r)}};var Z=(e,t,r)=>{if(!B(e))return null;let a={},o=new Set(["name","file","change"]);
17
+ h=class extends u.TypeError{constructor(r,a){super(`Invalid index type, ${r} mus\
18
+ t follow one of the Index options.`,a);this.indexName=r}},I=class extends u.TypeError{constructor(r,a){
19
+ super(`Invalid index reference, ${r} must be valid column.`,a);this.indexName=r}};var R=require("@ez4/reflection"),W=require("@ez4/common/library"),H=require("@ez4/schema/library");var O=require("@ez4/common/library"),v=class extends O.InvalidTypeError{constructor(t){
20
+ super("Invalid table schema type",void 0,"Database.Schema",t)}},D=class extends O.IncorrectTypeError{constructor(r,a){
21
+ super("Incorrect table schema type",r,"Database.Schema",a);this.schemaType=r}};var N=(e,t,r,a)=>{if(!(0,R.isTypeReference)(e))return Q(e,t,r,a);let o=r[e.path];
22
+ return o?Q(o,t,r,a):null},Q=(e,t,r,a)=>(0,R.isTypeObject)(e)?(0,H.getObjectSchema)(
23
+ e,r):(0,W.isModelDeclaration)(e)?G(e)?(0,H.getObjectSchema)(e,r):(a.push(new D(e.
24
+ name,e.file)),null):(a.push(new v(t.file)),null);var l=require("@ez4/common/library"),b=require("@ez4/reflection");var Z=(e,t,r,a)=>{if(!(0,b.isTypeReference)(e))return X(e,t,a);let o=r[e.path];return o?
25
+ X(o,t,a):null},X=(e,t,r)=>(0,b.isTypeObject)(e)?Y(e,(0,l.getObjectMembers)(e),r):
26
+ (0,l.isModelDeclaration)(e)?B(e)?Y(e,(0,l.getModelMembers)(e),r):(r.push(new M(e.
27
+ name,e.file)),null):(r.push(new S(t.file)),null),Y=(e,t,r)=>{let a={};for(let o of t){
28
+ if(!(0,b.isModelProperty)(o)||o.inherited)continue;let n=o.name,i=(0,l.getPropertyString)(
29
+ o);switch(i){case"primary":case"regular":case"unique":case"ttl":a[n]=i;break;default:
30
+ return r.push(new h(n,e.file)),null}}return a};var m=require("@ez4/common/library"),T=require("@ez4/reflection");var f=require("@ez4/common/library"),j=class extends f.IncompleteTypeError{constructor(t,r){
31
+ super("Incomplete table stream",t,r)}},E=class extends f.InvalidTypeError{constructor(t){
32
+ super("Invalid table stream type",void 0,"Database.Stream",t)}},P=class extends f.IncorrectTypeError{constructor(r,a){
33
+ super("Incorrect table stream type",r,"Database.Stream",a);this.streamType=r}};var L=require("@ez4/common/library"),A=class extends L.IncompleteTypeError{constructor(t,r){
34
+ super("Incomplete stream handler",t,r)}};var ee=(e,t,r)=>{if(!_(e))return null;let a={},o=new Set(["name","file","change"]);
34
35
  return e.description&&(a.description=e.description),(a.name=e.name)&&o.delete("n\
35
36
  ame"),(a.file=e.file)&&o.delete("file"),e.parameters&&o.delete("change"),o.size===
36
- 0&&de(a)?a:(r.push(new j([...o],e.file)),null)},de=e=>!!e.name&&!!e.file;var re=(e,t,r)=>{if(!(0,f.isTypeReference)(e))return L(e,t,r);let a=t[e.path];return a?
37
- L(a,t,r):null},ye=e=>!!e.handler,L=(e,t,r)=>_(e)?ee(e,(0,l.getModelMembers)(e),t,
38
- r):(0,f.isTypeObject)(e)?ee(e,(0,l.getObjectMembers)(e),t,r):null,ee=(e,t,r,a)=>{
39
- let o={},s=new Set(["handler"]);for(let i of t)if((0,f.isModelProperty)(i))switch(i.
40
- name){case"timeout":case"memory":{let n=(0,l.getPropertyNumber)(i);n!=null&&(o[i.
41
- name]=n);break}case"handler":o.handler=Z(i.value,r,a);break;case"variables":o.variables=
42
- (0,l.getLinkedVariables)(i,a);break}return ye(o)?o:(a.push(new D([...s],e.file)),
43
- null)};var C=(e,t,r)=>{if(!(0,d.isTypeReference)(e))return te(e,t,r);let a=t[e.path];return a?
44
- te(a,t,r):null},xe=e=>!!e.name&&!!e.schema&&!!e.indexes,te=(e,t,r)=>V(e)?ae(e,(0,T.getModelMembers)(
45
- e),t,r):(0,d.isTypeObject)(e)?ae(e,(0,T.getObjectMembers)(e),t,r):null,ae=(e,t,r,a)=>{
46
- let o={},s=new Set(["name","schema","indexes"]);for(let n of t)if((0,d.isModelProperty)(
47
- n))switch(n.name){case"name":(o.name=(0,T.getPropertyString)(n))&&s.delete(n.name);
48
- break;case"schema":{(o.schema=R(n.value,e,r,a))&&s.delete(n.name);break}case"ind\
49
- exes":{(o.indexes=W(n.value,e,r,a))&&s.delete(n.name);break}case"stream":{o.stream=
50
- re(n.value,r,a);break}}if(!xe(o))return a.push(new x([...s],e.file)),null;let i=ge(
51
- e,o.indexes,o.schema);return i.length?(a.push(...i),null):o},ge=(e,t,r)=>{let a=r.
52
- properties,o=[];for(let s in t)for(let i of s.split(":"))a[i]||o.push(new h(s,e.
53
- file));return o};var H=e=>{let t={},r=[];for(let a in e){let o=e[a];if(!P(o))continue;let s={type:E},
54
- i=new Set(["tables"]);s.name=o.name;for(let n of(0,c.getModelMembers)(o))if((0,oe.isModelProperty)(
55
- n))switch(n.name){case"tables":(s.tables=Me(n,e,r))&&i.delete(n.name);break;case"\
56
- variables":s.variables=(0,c.getLinkedVariables)(n,r);break;case"services":s.services=
57
- (0,c.getLinkedServices)(n,e,r);break}if(!Se(s)){r.push(new y([...i],o.file));continue}
58
- t[o.name]=s}return{services:t,errors:r}},Se=e=>!!e.name&&!!e.tables,Me=(e,t,r)=>{
59
- let a=(0,c.getPropertyTuple)(e)??[],o=[];for(let s of a){let i=C(s,t,r);i&&o.push(
60
- i)}return o};var se=e=>P(e)?e.name:null;var N=!1,he=()=>(N||((0,ne.registerTriggers)(),(0,ie.registerTriggers)(),(0,pe.createTrigger)(
61
- "@ez4/database",{"metadata:getServices":H,"metadata:getLinkedService":se}),N=!0),
62
- N);0&&(module.exports={IncompleteHandlerError,IncompleteServiceError,IncompleteStreamError,
63
- IncompleteTableError,IncorrectIndexesTypeError,IncorrectSchemaTypeError,InvalidIndexReferenceError,
64
- InvalidIndexTypeError,InvalidIndexesTypeError,InvalidSchemaTypeError,ServiceType,
65
- getDatabaseServices,getDatabaseTable,getTableSchema,isDatabaseService,registerTriggers});
37
+ 0&&xe(a)?a:(r.push(new A([...o],e.file)),null)},xe=e=>!!e.name&&!!e.file;var ae=(e,t,r,a)=>{if(!(0,T.isTypeReference)(e))return re(e,t,r,a);let o=r[e.path];
38
+ return o?re(o,t,r,a):null},ge=e=>!!e.handler,re=(e,t,r,a)=>(0,T.isTypeObject)(e)?
39
+ te(e,(0,m.getObjectMembers)(e),r,a):(0,m.isModelDeclaration)(e)?J(e)?te(e,(0,m.getModelMembers)(
40
+ e),r,a):(a.push(new P(e.name,e.file)),null):(a.push(new E(t.file)),null),te=(e,t,r,a)=>{
41
+ let o={},n=new Set(["handler"]);for(let i of t)if(!(!(0,T.isModelProperty)(i)||i.
42
+ inherited))switch(i.name){case"handler":o.handler=ee(i.value,r,a);break;case"tim\
43
+ eout":case"memory":{let s=(0,m.getPropertyNumber)(i);s!=null&&(o[i.name]=s);break}case"\
44
+ variables":o.variables=(0,m.getLinkedVariables)(i,a);break}return ge(o)?o:(a.push(
45
+ new j([...n],e.file)),null)};var q=(e,t,r)=>{if(!(0,y.isTypeReference)(e))return oe(e,t,r);let a=t[e.path];return a?
46
+ oe(a,t,r):null},Se=e=>!!e.name&&!!e.schema&&!!e.indexes,oe=(e,t,r)=>$(e)?se(e,(0,d.getModelMembers)(
47
+ e),t,r):(0,y.isTypeObject)(e)?se(e,(0,d.getObjectMembers)(e),t,r):null,se=(e,t,r,a)=>{
48
+ let o={},n=new Set(["name","schema","indexes"]);for(let s of t)if(!(!(0,y.isModelProperty)(
49
+ s)||s.inherited))switch(s.name){case"name":(o.name=(0,d.getPropertyString)(s))&&
50
+ n.delete(s.name);break;case"indexes":{(o.indexes=Z(s.value,e,r,a))&&n.delete(s.name);
51
+ break}case"schema":{(o.schema=N(s.value,e,r,a))&&n.delete(s.name);break}case"str\
52
+ eam":{o.stream=ae(s.value,e,r,a);break}}if(!Se(o))return a.push(new g([...n],e.file)),
53
+ null;let i=Me(e,o.indexes,o.schema);return i.length?(a.push(...i),null):o},Me=(e,t,r)=>{
54
+ let a=r.properties,o=[];for(let n in t)for(let i of n.split(":"))a[i]||o.push(new I(
55
+ n,e.file));return o};var F=e=>{let t={},r=[];for(let a in e){let o=e[a];if(!z(o))continue;let n={type:k},
56
+ i=new Set(["tables"]);n.name=o.name;for(let s of(0,c.getModelMembers)(o))if(!(!(0,ne.isModelProperty)(
57
+ s)||s.inherited))switch(s.name){case"tables":(n.tables=Ie(s,e,r))&&i.delete(s.name);
58
+ break;case"variables":n.variables=(0,c.getLinkedVariables)(s,r);break;case"servi\
59
+ ces":n.services=(0,c.getLinkedServices)(s,e,r);break}if(!he(n)){r.push(new x([...i],
60
+ o.file));continue}t[o.name]=n}return{services:t,errors:r}},he=e=>!!e.name&&!!e.tables,
61
+ Ie=(e,t,r)=>{let a=(0,c.getPropertyTuple)(e)??[],o=[];for(let n of a){let i=q(n,
62
+ t,r);i&&o.push(i)}return o};var ie=e=>z(e)?e.name:null;var V=!1,ve=()=>(V||((0,pe.registerTriggers)(),(0,me.registerTriggers)(),(0,le.createTrigger)(
63
+ "@ez4/database",{"metadata:getServices":F,"metadata:getLinkedService":ie}),V=!0),
64
+ V);0&&(module.exports={IncompleteHandlerError,IncompleteServiceError,IncompleteStreamError,
65
+ IncompleteTableError,IncorrectIndexesTypeError,IncorrectSchemaTypeError,IncorrectStreamTypeError,
66
+ InvalidIndexReferenceError,InvalidIndexTypeError,InvalidIndexesTypeError,InvalidSchemaTypeError,
67
+ InvalidStreamTypeError,ServiceType,getDatabaseServices,getDatabaseTable,getTableSchema,
68
+ isDatabaseService,registerTriggers});
package/dist/library.mjs CHANGED
@@ -1,56 +1,62 @@
1
- import{registerTriggers as Ce}from"@ez4/common/library";import{registerTriggers as He}from"@ez4/schema/library";
2
- import{createTrigger as Ne}from"@ez4/project/library";import{getLinkedServices as Ae,getLinkedVariables as Pe,getModelMembers as ke,getPropertyTuple as Oe}from"@ez4/common/library";
3
- import{isModelProperty as we}from"@ez4/reflection";var S="@ez4/database",qe=e=>e.type===S;import{IncompleteTypeError as B}from"@ez4/common/library";var m=class extends B{constructor(t,r){
4
- super("Incomplete database service",t,r)}};import{getModelMembers as Se,getObjectMembers as Me,getPropertyString as he}from"@ez4/common/library";
5
- import{isModelProperty as ve,isTypeObject as Ie,isTypeReference as De}from"@ez4/reflection";import{IncompleteTypeError as G}from"@ez4/common/library";var l=class extends G{constructor(t,r){
6
- super("Incomplete database table",t,r)}};import{IncorrectTypeError as J,InvalidTypeError as K,TypeError as h}from"@ez4/common/library";
7
- var c=class extends K{constructor(t){super("Invalid table indexes type",void 0,"\
8
- Database.Indexes",t)}},u=class extends J{constructor(r,a){super("Incorrect table\
9
- indexes type",r,"Database.Indexes",a);this.schemaType=r}},b=class extends h{constructor(r,a){
1
+ import{registerTriggers as Ve}from"@ez4/common/library";import{registerTriggers as Ue}from"@ez4/schema/library";
2
+ import{createTrigger as $e}from"@ez4/project/library";import{getLinkedServices as Oe,getLinkedVariables as Re,getModelMembers as Ce,getPropertyTuple as He}from"@ez4/common/library";
3
+ import{isModelProperty as Ne}from"@ez4/reflection";var h="@ez4/database",_e=e=>e.type===h;import{IncompleteTypeError as G}from"@ez4/common/library";var m=class extends G{constructor(t,r){
4
+ super("Incomplete database service",t,r)}};import{hasHeritageType as p,isClassDeclaration as J,isModelDeclaration as K}from"@ez4/common/library";
5
+ import{isTypeCallback as Q,isTypeFunction as W}from"@ez4/reflection";var l=e=>J(
6
+ e)&&p(e,"Database.Service"),v=e=>K(e)&&p(e,"Database.Table"),D=e=>Q(e)||W(e),j=e=>p(
7
+ e,"Database.Indexes"),E=e=>p(e,"Database.Schema"),P=e=>p(e,"Database.Stream");import{getModelMembers as De,getObjectMembers as je,getPropertyString as Ee}from"@ez4/common/library";
8
+ import{isModelProperty as Pe,isTypeObject as Ae,isTypeReference as ke}from"@ez4/reflection";import{IncompleteTypeError as X}from"@ez4/common/library";var c=class extends X{constructor(t,r){
9
+ super("Incomplete database table",t,r)}};import{IncorrectTypeError as Y,InvalidTypeError as Z,TypeError as A}from"@ez4/common/library";
10
+ var u=class extends Z{constructor(t){super("Invalid table indexes type",void 0,"\
11
+ Database.Indexes",t)}},b=class extends Y{constructor(r,a){super("Incorrect table\
12
+ indexes type",r,"Database.Indexes",a);this.schemaType=r}},f=class extends A{constructor(r,a){
10
13
  super(`Invalid index type, ${r} must follow one of the Index options.`,a);this.indexName=
11
- r}},f=class extends h{constructor(r,a){super(`Invalid index reference, ${r} must\
12
- be valid column.`,a);this.indexName=r}};import{hasHeritageType as p,isClassDeclaration as Q,isModelDeclaration as v}from"@ez4/common/library";
13
- import{isTypeCallback as W,isTypeFunction as X}from"@ez4/reflection";var T=e=>Q(
14
- e)&&p(e,"Database.Service"),I=e=>v(e)&&p(e,"Database.Table"),D=e=>p(e,"Database.\
15
- Schema"),j=e=>p(e,"Database.Indexes"),E=e=>v(e)&&p(e,"Database.Stream"),A=e=>W(e)||
16
- X(e);import{isTypeObject as L,isTypeReference as ee}from"@ez4/reflection";import{isModelDeclaration as re}from"@ez4/common/library";
17
- import{getObjectSchema as P}from"@ez4/schema/library";import{IncorrectTypeError as Y,InvalidTypeError as Z}from"@ez4/common/library";var d=class extends Z{constructor(t){
18
- super("Invalid table schema type",void 0,"Database.Schema",t)}},y=class extends Y{constructor(r,a){
19
- super("Incorrect table schema type",r,"Database.Schema",a);this.schemaType=r}};var O=(e,t,r,a)=>{if(!ee(e))return k(e,t,r,a);let o=r[e.path];return o?k(o,t,r,a):
20
- null},k=(e,t,r,a)=>L(e)?P(e,r):re(e)?D(e)?P(e,r):(a.push(new y(e.name,e.file)),null):
21
- (a.push(new d(t.file)),null);import{isModelDeclaration as te,getModelMembers as ae,getObjectMembers as oe,getPropertyString as se}from"@ez4/common/library";
22
- import{isModelProperty as ne,isTypeObject as ie,isTypeReference as pe}from"@ez4/reflection";var R=(e,t,r,a)=>{if(!pe(e))return w(e,t,a);let o=r[e.path];return o?w(o,t,a):null},
23
- w=(e,t,r)=>ie(e)?z(e,oe(e),r):te(e)?j(e)?z(e,ae(e),r):(r.push(new u(e.name,e.file)),
24
- null):(r.push(new c(t.file)),null),z=(e,t,r)=>{let a={};for(let o of t){if(!ne(o))
25
- continue;let s=o.name,i=se(o);switch(i){case"primary":case"regular":case"unique":case"\
26
- ttl":a[s]=i;break;default:return r.push(new b(s,e.file)),null}}return a};import{getLinkedVariables as ue,getModelMembers as be,getObjectMembers as fe,getPropertyNumber as Te}from"@ez4/common/library";
27
- import{isModelProperty as de,isTypeObject as ye,isTypeReference as xe}from"@ez4/reflection";import{IncompleteTypeError as me}from"@ez4/common/library";var x=class extends me{constructor(t,r){
28
- super("Incomplete table stream",t,r)}};import{IncompleteTypeError as le}from"@ez4/common/library";var g=class extends le{constructor(t,r){
29
- super("Incomplete stream handler",t,r)}};var C=(e,t,r)=>{if(!A(e))return null;let a={},o=new Set(["name","file","change"]);
14
+ r}},T=class extends A{constructor(r,a){super(`Invalid index reference, ${r} must\
15
+ be valid column.`,a);this.indexName=r}};import{isTypeObject as re,isTypeReference as te}from"@ez4/reflection";import{isModelDeclaration as ae}from"@ez4/common/library";
16
+ import{getObjectSchema as k}from"@ez4/schema/library";import{IncorrectTypeError as L,InvalidTypeError as ee}from"@ez4/common/library";
17
+ var d=class extends ee{constructor(t){super("Invalid table schema type",void 0,"\
18
+ Database.Schema",t)}},y=class extends L{constructor(r,a){super("Incorrect table \
19
+ schema type",r,"Database.Schema",a);this.schemaType=r}};var z=(e,t,r,a)=>{if(!te(e))return w(e,t,r,a);let o=r[e.path];return o?w(o,t,r,a):
20
+ null},w=(e,t,r,a)=>re(e)?k(e,r):ae(e)?E(e)?k(e,r):(a.push(new y(e.name,e.file)),
21
+ null):(a.push(new d(t.file)),null);import{isModelDeclaration as oe,getModelMembers as se,getObjectMembers as ne,getPropertyString as ie}from"@ez4/common/library";
22
+ import{isModelProperty as pe,isTypeObject as me,isTypeReference as le}from"@ez4/reflection";var C=(e,t,r,a)=>{if(!le(e))return O(e,t,a);let o=r[e.path];return o?O(o,t,a):null},
23
+ O=(e,t,r)=>me(e)?R(e,ne(e),r):oe(e)?j(e)?R(e,se(e),r):(r.push(new b(e.name,e.file)),
24
+ null):(r.push(new u(t.file)),null),R=(e,t,r)=>{let a={};for(let o of t){if(!pe(o)||
25
+ o.inherited)continue;let n=o.name,i=ie(o);switch(i){case"primary":case"regular":case"\
26
+ unique":case"ttl":a[n]=i;break;default:return r.push(new f(n,e.file)),null}}return a};import{getLinkedVariables as de,getModelMembers as ye,getObjectMembers as xe,getPropertyNumber as ge,
27
+ isModelDeclaration as Se}from"@ez4/common/library";import{isModelProperty as Me,
28
+ isTypeObject as he,isTypeReference as Ie}from"@ez4/reflection";import{IncompleteTypeError as ce,IncorrectTypeError as ue,InvalidTypeError as be}from"@ez4/common/library";
29
+ var x=class extends ce{constructor(t,r){super("Incomplete table stream",t,r)}},g=class extends be{constructor(t){
30
+ super("Invalid table stream type",void 0,"Database.Stream",t)}},S=class extends ue{constructor(r,a){
31
+ super("Incorrect table stream type",r,"Database.Stream",a);this.streamType=r}};import{IncompleteTypeError as fe}from"@ez4/common/library";var M=class extends fe{constructor(t,r){
32
+ super("Incomplete stream handler",t,r)}};var H=(e,t,r)=>{if(!D(e))return null;let a={},o=new Set(["name","file","change"]);
30
33
  return e.description&&(a.description=e.description),(a.name=e.name)&&o.delete("n\
31
34
  ame"),(a.file=e.file)&&o.delete("file"),e.parameters&&o.delete("change"),o.size===
32
- 0&&ce(a)?a:(r.push(new g([...o],e.file)),null)},ce=e=>!!e.name&&!!e.file;var q=(e,t,r)=>{if(!xe(e))return H(e,t,r);let a=t[e.path];return a?H(a,t,r):null},
33
- ge=e=>!!e.handler,H=(e,t,r)=>E(e)?N(e,be(e),t,r):ye(e)?N(e,fe(e),t,r):null,N=(e,t,r,a)=>{
34
- let o={},s=new Set(["handler"]);for(let i of t)if(de(i))switch(i.name){case"time\
35
- out":case"memory":{let n=Te(i);n!=null&&(o[i.name]=n);break}case"handler":o.handler=
36
- C(i.value,r,a);break;case"variables":o.variables=ue(i,a);break}return ge(o)?o:(a.
37
- push(new x([...s],e.file)),null)};var U=(e,t,r)=>{if(!De(e))return F(e,t,r);let a=t[e.path];return a?F(a,t,r):null},
38
- je=e=>!!e.name&&!!e.schema&&!!e.indexes,F=(e,t,r)=>I(e)?V(e,Se(e),t,r):Ie(e)?V(e,
39
- Me(e),t,r):null,V=(e,t,r,a)=>{let o={},s=new Set(["name","schema","indexes"]);for(let n of t)
40
- if(ve(n))switch(n.name){case"name":(o.name=he(n))&&s.delete(n.name);break;case"s\
41
- chema":{(o.schema=O(n.value,e,r,a))&&s.delete(n.name);break}case"indexes":{(o.indexes=
42
- R(n.value,e,r,a))&&s.delete(n.name);break}case"stream":{o.stream=q(n.value,r,a);
43
- break}}if(!je(o))return a.push(new l([...s],e.file)),null;let i=Ee(e,o.indexes,o.
44
- schema);return i.length?(a.push(...i),null):o},Ee=(e,t,r)=>{let a=r.properties,o=[];
45
- for(let s in t)for(let i of s.split(":"))a[i]||o.push(new f(s,e.file));return o};var $=e=>{let t={},r=[];for(let a in e){let o=e[a];if(!T(o))continue;let s={type:S},
46
- i=new Set(["tables"]);s.name=o.name;for(let n of ke(o))if(we(n))switch(n.name){case"\
47
- tables":(s.tables=Re(n,e,r))&&i.delete(n.name);break;case"variables":s.variables=
48
- Pe(n,r);break;case"services":s.services=Ae(n,e,r);break}if(!ze(s)){r.push(new m(
49
- [...i],o.file));continue}t[o.name]=s}return{services:t,errors:r}},ze=e=>!!e.name&&
50
- !!e.tables,Re=(e,t,r)=>{let a=Oe(e)??[],o=[];for(let s of a){let i=U(s,t,r);i&&o.
51
- push(i)}return o};var _=e=>T(e)?e.name:null;var M=!1,Kr=()=>(M||(Ce(),He(),Ne("@ez4/database",{"metadata:getServices":$,"met\
52
- adata:getLinkedService":_}),M=!0),M);export{g as IncompleteHandlerError,m as IncompleteServiceError,x as IncompleteStreamError,
53
- l as IncompleteTableError,u as IncorrectIndexesTypeError,y as IncorrectSchemaTypeError,
54
- f as InvalidIndexReferenceError,b as InvalidIndexTypeError,c as InvalidIndexesTypeError,
55
- d as InvalidSchemaTypeError,S as ServiceType,$ as getDatabaseServices,U as getDatabaseTable,
56
- O as getTableSchema,qe as isDatabaseService,Kr as registerTriggers};
35
+ 0&&Te(a)?a:(r.push(new M([...o],e.file)),null)},Te=e=>!!e.name&&!!e.file;var F=(e,t,r,a)=>{if(!Ie(e))return N(e,t,r,a);let o=r[e.path];return o?N(o,t,r,a):
36
+ null},ve=e=>!!e.handler,N=(e,t,r,a)=>he(e)?q(e,xe(e),r,a):Se(e)?P(e)?q(e,ye(e),r,
37
+ a):(a.push(new S(e.name,e.file)),null):(a.push(new g(t.file)),null),q=(e,t,r,a)=>{
38
+ let o={},n=new Set(["handler"]);for(let i of t)if(!(!Me(i)||i.inherited))switch(i.
39
+ name){case"handler":o.handler=H(i.value,r,a);break;case"timeout":case"memory":{let s=ge(
40
+ i);s!=null&&(o[i.name]=s);break}case"variables":o.variables=de(i,a);break}return ve(
41
+ o)?o:(a.push(new x([...n],e.file)),null)};var $=(e,t,r)=>{if(!ke(e))return V(e,t,r);let a=t[e.path];return a?V(a,t,r):null},
42
+ we=e=>!!e.name&&!!e.schema&&!!e.indexes,V=(e,t,r)=>v(e)?U(e,De(e),t,r):Ae(e)?U(e,
43
+ je(e),t,r):null,U=(e,t,r,a)=>{let o={},n=new Set(["name","schema","indexes"]);for(let s of t)
44
+ if(!(!Pe(s)||s.inherited))switch(s.name){case"name":(o.name=Ee(s))&&n.delete(s.name);
45
+ break;case"indexes":{(o.indexes=C(s.value,e,r,a))&&n.delete(s.name);break}case"s\
46
+ chema":{(o.schema=z(s.value,e,r,a))&&n.delete(s.name);break}case"stream":{o.stream=
47
+ F(s.value,e,r,a);break}}if(!we(o))return a.push(new c([...n],e.file)),null;let i=ze(
48
+ e,o.indexes,o.schema);return i.length?(a.push(...i),null):o},ze=(e,t,r)=>{let a=r.
49
+ properties,o=[];for(let n in t)for(let i of n.split(":"))a[i]||o.push(new T(n,e.
50
+ file));return o};var _=e=>{let t={},r=[];for(let a in e){let o=e[a];if(!l(o))continue;let n={type:h},
51
+ i=new Set(["tables"]);n.name=o.name;for(let s of Ce(o))if(!(!Ne(s)||s.inherited))
52
+ switch(s.name){case"tables":(n.tables=Fe(s,e,r))&&i.delete(s.name);break;case"va\
53
+ riables":n.variables=Re(s,r);break;case"services":n.services=Oe(s,e,r);break}if(!qe(
54
+ n)){r.push(new m([...i],o.file));continue}t[o.name]=n}return{services:t,errors:r}},
55
+ qe=e=>!!e.name&&!!e.tables,Fe=(e,t,r)=>{let a=He(e)??[],o=[];for(let n of a){let i=$(
56
+ n,t,r);i&&o.push(i)}return o};var B=e=>l(e)?e.name:null;var I=!1,Zr=()=>(I||(Ve(),Ue(),$e("@ez4/database",{"metadata:getServices":_,"met\
57
+ adata:getLinkedService":B}),I=!0),I);export{M as IncompleteHandlerError,m as IncompleteServiceError,x as IncompleteStreamError,
58
+ c as IncompleteTableError,b as IncorrectIndexesTypeError,y as IncorrectSchemaTypeError,
59
+ S as IncorrectStreamTypeError,T as InvalidIndexReferenceError,f as InvalidIndexTypeError,
60
+ u as InvalidIndexesTypeError,d as InvalidSchemaTypeError,g as InvalidStreamTypeError,
61
+ h as ServiceType,_ as getDatabaseServices,$ as getDatabaseTable,z as getTableSchema,
62
+ _e as isDatabaseService,Zr as registerTriggers};
@@ -1,3 +1,5 @@
1
- import type { AllType, SourceMap } from '@ez4/reflection';
1
+ import type { AllType, SourceMap, TypeModel, TypeObject } from '@ez4/reflection';
2
2
  import type { TableStream } from '../types/stream.js';
3
- export declare const getTableStream: (type: AllType, reflection: SourceMap, errorList: Error[]) => TableStream | null;
3
+ type TypeParent = TypeModel | TypeObject;
4
+ export declare const getTableStream: (type: AllType, parent: TypeParent, reflection: SourceMap, errorList: Error[]) => TableStream | null;
5
+ export {};
@@ -1,7 +1,7 @@
1
1
  import type { AllType, TypeCallback, TypeClass, TypeFunction, TypeModel } from '@ez4/reflection';
2
2
  export declare const isDatabaseService: (type: AllType) => type is TypeClass;
3
3
  export declare const isDatabaseTable: (type: AllType) => type is TypeModel;
4
- export declare const isTableSchema: (type: TypeModel) => boolean;
5
- export declare const isTableIndexes: (type: TypeModel) => boolean;
6
- export declare const isTableStream: (type: AllType) => type is TypeModel;
7
4
  export declare const isStreamHandler: (type: AllType) => type is TypeCallback | TypeFunction;
5
+ export declare const isTableIndexes: (type: TypeModel) => boolean;
6
+ export declare const isTableSchema: (type: TypeModel) => boolean;
7
+ export declare const isTableStream: (type: TypeModel) => boolean;
package/package.json CHANGED
@@ -1,10 +1,13 @@
1
1
  {
2
2
  "name": "@ez4/database",
3
3
  "description": "EZ4: Components to build database services",
4
- "version": "0.3.0",
4
+ "version": "0.4.0",
5
5
  "author": "Silas B.",
6
6
  "license": "MIT",
7
7
  "type": "module",
8
+ "engines": {
9
+ "node": ">=20.15.0"
10
+ },
8
11
  "exports": {
9
12
  ".": {
10
13
  "types": "./dist/main.d.ts",
@@ -31,10 +34,10 @@
31
34
  "live:publish": "npm run test && npm publish --access public"
32
35
  },
33
36
  "dependencies": {
34
- "@ez4/common": "^0.3.0",
35
- "@ez4/project": "^0.3.0",
36
- "@ez4/reflection": "^0.3.0",
37
- "@ez4/schema": "^0.3.0",
38
- "@ez4/utils": "^0.3.0"
37
+ "@ez4/common": "^0.4.0",
38
+ "@ez4/project": "^0.4.0",
39
+ "@ez4/reflection": "^0.4.0",
40
+ "@ez4/schema": "^0.4.0",
41
+ "@ez4/utils": "^0.4.0"
39
42
  }
40
43
  }