@ez4/database 0.1.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/LICENSE +21 -0
- package/README.md +1 -0
- package/dist/errors/handler.d.ts +4 -0
- package/dist/errors/indexes.d.ts +16 -0
- package/dist/errors/schema.d.ts +8 -0
- package/dist/errors/service.d.ts +4 -0
- package/dist/errors/stream.d.ts +4 -0
- package/dist/errors/table.d.ts +4 -0
- package/dist/library.cjs +65 -0
- package/dist/library.d.ts +13 -0
- package/dist/library.mjs +56 -0
- package/dist/main.cjs +4 -0
- package/dist/main.d.ts +5 -0
- package/dist/main.mjs +2 -0
- package/dist/metadata/handler.d.ts +3 -0
- package/dist/metadata/indexes.d.ts +5 -0
- package/dist/metadata/schema.d.ts +4 -0
- package/dist/metadata/service.d.ts +6 -0
- package/dist/metadata/stream.d.ts +3 -0
- package/dist/metadata/table.d.ts +3 -0
- package/dist/metadata/utils.d.ts +7 -0
- package/dist/richtypes/schema.d.ts +10 -0
- package/dist/richtypes/utils.d.ts +104 -0
- package/dist/services/client.d.ts +119 -0
- package/dist/services/database.d.ts +80 -0
- package/dist/services/helpers.d.ts +30 -0
- package/dist/services/indexes.d.ts +9 -0
- package/dist/services/stream.d.ts +34 -0
- package/dist/triggers/register.d.ts +4 -0
- package/dist/triggers/richtypes.d.ts +100 -0
- package/dist/triggers/service.d.ts +2 -0
- package/dist/types/handler.d.ts +5 -0
- package/dist/types/indexes.d.ts +2 -0
- package/dist/types/schema.d.ts +2 -0
- package/dist/types/service.d.ts +9 -0
- package/dist/types/stream.d.ts +8 -0
- package/dist/types/table.d.ts +9 -0
- package/package.json +40 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Silas B.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# EZ4: Database
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { IncorrectTypeError, InvalidTypeError, TypeError } from '@ez4/common/library';
|
|
2
|
+
export declare class InvalidIndexesTypeError extends InvalidTypeError {
|
|
3
|
+
constructor(fileName?: string);
|
|
4
|
+
}
|
|
5
|
+
export declare class IncorrectIndexesTypeError extends IncorrectTypeError {
|
|
6
|
+
schemaType: string;
|
|
7
|
+
constructor(schemaType: string, fileName?: string);
|
|
8
|
+
}
|
|
9
|
+
export declare class InvalidIndexTypeError extends TypeError {
|
|
10
|
+
indexName: string;
|
|
11
|
+
constructor(indexName: string, fileName?: string);
|
|
12
|
+
}
|
|
13
|
+
export declare class InvalidIndexReferenceError extends TypeError {
|
|
14
|
+
indexName: string;
|
|
15
|
+
constructor(indexName: string, fileName?: string);
|
|
16
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { IncorrectTypeError, InvalidTypeError } from '@ez4/common/library';
|
|
2
|
+
export declare class InvalidSchemaTypeError extends InvalidTypeError {
|
|
3
|
+
constructor(fileName?: string);
|
|
4
|
+
}
|
|
5
|
+
export declare class IncorrectSchemaTypeError extends IncorrectTypeError {
|
|
6
|
+
schemaType: string;
|
|
7
|
+
constructor(schemaType: string, fileName?: string);
|
|
8
|
+
}
|
package/dist/library.cjs
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";var P=Object.defineProperty;var me=Object.getOwnPropertyDescriptor;var le=Object.getOwnPropertyNames;var ce=Object.prototype.hasOwnProperty;var ue=(e,t)=>{for(var r in t)P(e,r,{get:t[r],enumerable:!0})},be=(e,t,r,o)=>{if(t&&
|
|
2
|
+
typeof t=="object"||typeof t=="function")for(let a of le(t))!ce.call(e,a)&&a!==r&&
|
|
3
|
+
P(e,a,{get:()=>t[a],enumerable:!(o=me(t,a))||o.enumerable});return e};var fe=e=>be(P({},"__esModule",{value:!0}),e);var ve={};ue(ve,{IncompleteHandlerError:()=>j,IncompleteServiceError:()=>y,IncompleteStreamError:()=>D,
|
|
4
|
+
IncompleteTableError:()=>g,IncorrectIndexesTypeError:()=>x,IncorrectSchemaTypeError:()=>I,
|
|
5
|
+
InvalidIndexReferenceError:()=>h,InvalidIndexTypeError:()=>M,InvalidIndexesTypeError:()=>S,
|
|
6
|
+
InvalidSchemaTypeError:()=>v,ServiceType:()=>E,getDatabaseServices:()=>R,getDatabaseTable:()=>H,
|
|
7
|
+
getTableSchema:()=>C,isDatabaseService:()=>Te,registerTriggers:()=>he});module.exports=
|
|
8
|
+
fe(ve);var ne=require("@ez4/common/library"),ie=require("@ez4/schema/library"),pe=require("@ez4/project");var c=require("@ez4/common/library"),ae=require("@ez4/reflection");var E="@ez4/database",Te=e=>e.type===E;var V=require("@ez4/common/library"),y=class extends V.IncompleteTypeError{constructor(t,r){
|
|
9
|
+
super("Incomplete database service",t,r)}};var T=require("@ez4/common/library"),d=require("@ez4/reflection");var N=require("@ez4/common/library"),g=class extends N.IncompleteTypeError{constructor(t,r){
|
|
10
|
+
super("Incomplete database table",t,r)}};var u=require("@ez4/common/library"),S=class extends u.InvalidTypeError{constructor(t){
|
|
11
|
+
super("Invalid table indexes type",void 0,"Database.Indexes",t)}},x=class extends u.IncorrectTypeError{constructor(r,o){
|
|
12
|
+
super("Incorrect table indexes type",r,"Database.Indexes",o);this.schemaType=r}},
|
|
13
|
+
M=class extends u.TypeError{constructor(r,o){super(`Invalid index type, ${r} mus\
|
|
14
|
+
t follow one of the Index options.`,o);this.indexName=r}},h=class extends u.TypeError{constructor(r,o){
|
|
15
|
+
super(`Invalid index reference, ${r} must be valid column.`,o);this.indexName=r}};var p=require("@ez4/common/library"),k=require("@ez4/reflection"),A=e=>(0,p.isClassDeclaration)(
|
|
16
|
+
e)&&(0,p.hasHeritageType)(e,"Database.Service"),q=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,k.isTypeCallback)(e)||(0,k.isTypeFunction)(
|
|
20
|
+
e);var w=require("@ez4/reflection"),J=require("@ez4/common/library"),z=require("@ez4/schema/library");var O=require("@ez4/common/library"),v=class extends O.InvalidTypeError{constructor(t){
|
|
21
|
+
super("Invalid table schema type",void 0,"Database.Schema",t)}},I=class extends O.IncorrectTypeError{constructor(r,o){
|
|
22
|
+
super("Incorrect table schema type",r,"Database.Schema",o);this.schemaType=r}};var C=(e,t,r,o)=>{if(!(0,w.isTypeReference)(e))return G(e,t,r,o);let a=r[e.path];
|
|
23
|
+
return a?G(a,t,r,o):null},G=(e,t,r,o)=>(0,w.isTypeObject)(e)?(0,z.getObjectSchema)(
|
|
24
|
+
e,r):(0,J.isModelDeclaration)(e)?U(e)?(0,z.getObjectSchema)(e,r):(o.push(new I(e.
|
|
25
|
+
name,e.file)),null):(o.push(new v(t.file)),null);var m=require("@ez4/common/library"),b=require("@ez4/reflection");var W=(e,t,r,o)=>{if(!(0,b.isTypeReference)(e))return K(e,t,o);let a=r[e.path];return a?
|
|
26
|
+
K(a,t,o):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 x(e.
|
|
28
|
+
name,e.file)),null):(r.push(new S(t.file)),null),Q=(e,t,r)=>{let o={};for(let a of t){
|
|
29
|
+
if(!(0,b.isModelProperty)(a))continue;let s=a.name,i=(0,m.getPropertyString)(a);
|
|
30
|
+
switch(i){case"primary":case"regular":case"unique":case"ttl":o[s]=i;break;default:
|
|
31
|
+
return r.push(new M(s,e.file)),null}}return o};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 o={},a=new Set(["name","file","change"]);
|
|
34
|
+
return e.description&&(o.description=e.description),(o.name=e.name)&&a.delete("n\
|
|
35
|
+
ame"),(o.file=e.file)&&a.delete("file"),e.parameters&&a.delete("change"),a.size===
|
|
36
|
+
0&&de(o)?o:(r.push(new j([...a],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 o=t[e.path];return o?
|
|
37
|
+
L(o,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,o)=>{
|
|
39
|
+
let a={},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&&(a[i.
|
|
41
|
+
name]=n);break}case"handler":a.handler=Z(i.value,r,o);break;case"variables":a.variables=
|
|
42
|
+
(0,l.getLinkedVariables)(i,o);break}return ye(a)?a:(o.push(new D([...s],e.file)),
|
|
43
|
+
null)};var H=(e,t,r)=>{if(!(0,d.isTypeReference)(e))return te(e,t,r);let o=t[e.path];return o?
|
|
44
|
+
te(o,t,r):null},ge=e=>!!e.name&&!!e.schema&&!!e.indexes,te=(e,t,r)=>q(e)?oe(e,(0,T.getModelMembers)(
|
|
45
|
+
e),t,r):(0,d.isTypeObject)(e)?oe(e,(0,T.getObjectMembers)(e),t,r):null,oe=(e,t,r,o)=>{
|
|
46
|
+
let a={},s=new Set(["name","schema","indexes"]);for(let n of t)if((0,d.isModelProperty)(
|
|
47
|
+
n))switch(n.name){case"name":(a.name=(0,T.getPropertyString)(n))&&s.delete(n.name);
|
|
48
|
+
break;case"schema":{(a.schema=C(n.value,e,r,o))&&s.delete(n.name);break}case"ind\
|
|
49
|
+
exes":{(a.indexes=W(n.value,e,r,o))&&s.delete(n.name);break}case"stream":{a.stream=
|
|
50
|
+
re(n.value,r,o);break}}if(!ge(a))return o.push(new g([...s],e.file)),null;let i=Se(
|
|
51
|
+
e,a.indexes,a.schema);return i.length?(o.push(...i),null):a},Se=(e,t,r)=>{let o=r.
|
|
52
|
+
properties,a=[];for(let s in t)for(let i of s.split(":"))o[i]||a.push(new h(s,e.
|
|
53
|
+
file));return a};var R=e=>{let t={},r=[];for(let o in e){let a=e[o];if(!A(a))continue;let s={type:E},
|
|
54
|
+
i=new Set(["tables"]);s.name=a.name;for(let n of(0,c.getModelMembers)(a))if((0,ae.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(!xe(s)){r.push(new y([...i],a.file));continue}
|
|
58
|
+
t[a.name]=s}return{services:t,errors:r}},xe=e=>!!e.name&&!!e.tables,Me=(e,t,r)=>{
|
|
59
|
+
let o=(0,c.getPropertyTuple)(e)??[],a=[];for(let s of o){let i=H(s,t,r);i&&a.push(
|
|
60
|
+
i)}return a};var se=e=>A(e)?e.name:null;var F=!1,he=()=>(F||((0,ne.registerTriggers)(),(0,ie.registerTriggers)(),(0,pe.createTrigger)(
|
|
61
|
+
"@ez4/database",{"metadata:getServices":R,"metadata:getLinkedService":se}),F=!0),
|
|
62
|
+
F);0&&(module.exports={IncompleteHandlerError,IncompleteServiceError,IncompleteStreamError,
|
|
63
|
+
IncompleteTableError,IncorrectIndexesTypeError,IncorrectSchemaTypeError,InvalidIndexReferenceError,
|
|
64
|
+
InvalidIndexTypeError,InvalidIndexesTypeError,InvalidSchemaTypeError,ServiceType,
|
|
65
|
+
getDatabaseServices,getDatabaseTable,getTableSchema,isDatabaseService,registerTriggers});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export * from './triggers/register.js';
|
|
2
|
+
export * from './metadata/service.js';
|
|
3
|
+
export * from './metadata/table.js';
|
|
4
|
+
export * from './metadata/schema.js';
|
|
5
|
+
export * from './errors/service.js';
|
|
6
|
+
export * from './errors/table.js';
|
|
7
|
+
export * from './errors/schema.js';
|
|
8
|
+
export * from './errors/indexes.js';
|
|
9
|
+
export * from './errors/stream.js';
|
|
10
|
+
export * from './errors/handler.js';
|
|
11
|
+
export * from './types/service.js';
|
|
12
|
+
export * from './types/table.js';
|
|
13
|
+
export * from './types/schema.js';
|
package/dist/library.mjs
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import{registerTriggers as He}from"@ez4/common/library";import{registerTriggers as Re}from"@ez4/schema/library";
|
|
2
|
+
import{createTrigger as Fe}from"@ez4/project";import{getLinkedServices as ke,getLinkedVariables as Ae,getModelMembers as Oe,getPropertyTuple as we}from"@ez4/common/library";
|
|
3
|
+
import{isModelProperty as Pe}from"@ez4/reflection";var x="@ez4/database",Ve=e=>e.type===x;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 xe,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,o){super("Incorrect table\
|
|
9
|
+
indexes type",r,"Database.Indexes",o);this.schemaType=r}},b=class extends h{constructor(r,o){
|
|
10
|
+
super(`Invalid index type, ${r} must follow one of the Index options.`,o);this.indexName=
|
|
11
|
+
r}},f=class extends h{constructor(r,o){super(`Invalid index reference, ${r} must\
|
|
12
|
+
be valid column.`,o);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"),k=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 A}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,o){
|
|
19
|
+
super("Incorrect table schema type",r,"Database.Schema",o);this.schemaType=r}};var w=(e,t,r,o)=>{if(!ee(e))return O(e,t,r,o);let a=r[e.path];return a?O(a,t,r,o):
|
|
20
|
+
null},O=(e,t,r,o)=>L(e)?A(e,r):re(e)?D(e)?A(e,r):(o.push(new y(e.name,e.file)),null):
|
|
21
|
+
(o.push(new d(t.file)),null);import{isModelDeclaration as te,getModelMembers as oe,getObjectMembers as ae,getPropertyString as se}from"@ez4/common/library";
|
|
22
|
+
import{isModelProperty as ne,isTypeObject as ie,isTypeReference as pe}from"@ez4/reflection";var C=(e,t,r,o)=>{if(!pe(e))return P(e,t,o);let a=r[e.path];return a?P(a,t,o):null},
|
|
23
|
+
P=(e,t,r)=>ie(e)?z(e,ae(e),r):te(e)?j(e)?z(e,oe(e),r):(r.push(new u(e.name,e.file)),
|
|
24
|
+
null):(r.push(new c(t.file)),null),z=(e,t,r)=>{let o={};for(let a of t){if(!ne(a))
|
|
25
|
+
continue;let s=a.name,i=se(a);switch(i){case"primary":case"regular":case"unique":case"\
|
|
26
|
+
ttl":o[s]=i;break;default:return r.push(new b(s,e.file)),null}}return o};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 ge}from"@ez4/reflection";import{IncompleteTypeError as me}from"@ez4/common/library";var g=class extends me{constructor(t,r){
|
|
28
|
+
super("Incomplete table stream",t,r)}};import{IncompleteTypeError as le}from"@ez4/common/library";var S=class extends le{constructor(t,r){
|
|
29
|
+
super("Incomplete stream handler",t,r)}};var H=(e,t,r)=>{if(!k(e))return null;let o={},a=new Set(["name","file","change"]);
|
|
30
|
+
return e.description&&(o.description=e.description),(o.name=e.name)&&a.delete("n\
|
|
31
|
+
ame"),(o.file=e.file)&&a.delete("file"),e.parameters&&a.delete("change"),a.size===
|
|
32
|
+
0&&ce(o)?o:(r.push(new S([...a],e.file)),null)},ce=e=>!!e.name&&!!e.file;var V=(e,t,r)=>{if(!ge(e))return R(e,t,r);let o=t[e.path];return o?R(o,t,r):null},
|
|
33
|
+
Se=e=>!!e.handler,R=(e,t,r)=>E(e)?F(e,be(e),t,r):ye(e)?F(e,fe(e),t,r):null,F=(e,t,r,o)=>{
|
|
34
|
+
let a={},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&&(a[i.name]=n);break}case"handler":a.handler=
|
|
36
|
+
H(i.value,r,o);break;case"variables":a.variables=ue(i,o);break}return Se(a)?a:(o.
|
|
37
|
+
push(new g([...s],e.file)),null)};var U=(e,t,r)=>{if(!De(e))return N(e,t,r);let o=t[e.path];return o?N(o,t,r):null},
|
|
38
|
+
je=e=>!!e.name&&!!e.schema&&!!e.indexes,N=(e,t,r)=>I(e)?q(e,xe(e),t,r):Ie(e)?q(e,
|
|
39
|
+
Me(e),t,r):null,q=(e,t,r,o)=>{let a={},s=new Set(["name","schema","indexes"]);for(let n of t)
|
|
40
|
+
if(ve(n))switch(n.name){case"name":(a.name=he(n))&&s.delete(n.name);break;case"s\
|
|
41
|
+
chema":{(a.schema=w(n.value,e,r,o))&&s.delete(n.name);break}case"indexes":{(a.indexes=
|
|
42
|
+
C(n.value,e,r,o))&&s.delete(n.name);break}case"stream":{a.stream=V(n.value,r,o);
|
|
43
|
+
break}}if(!je(a))return o.push(new l([...s],e.file)),null;let i=Ee(e,a.indexes,a.
|
|
44
|
+
schema);return i.length?(o.push(...i),null):a},Ee=(e,t,r)=>{let o=r.properties,a=[];
|
|
45
|
+
for(let s in t)for(let i of s.split(":"))o[i]||a.push(new f(s,e.file));return a};var $=e=>{let t={},r=[];for(let o in e){let a=e[o];if(!T(a))continue;let s={type:x},
|
|
46
|
+
i=new Set(["tables"]);s.name=a.name;for(let n of Oe(a))if(Pe(n))switch(n.name){case"\
|
|
47
|
+
tables":(s.tables=Ce(n,e,r))&&i.delete(n.name);break;case"variables":s.variables=
|
|
48
|
+
Ae(n,r);break;case"services":s.services=ke(n,e,r);break}if(!ze(s)){r.push(new m(
|
|
49
|
+
[...i],a.file));continue}t[a.name]=s}return{services:t,errors:r}},ze=e=>!!e.name&&
|
|
50
|
+
!!e.tables,Ce=(e,t,r)=>{let o=we(e)??[],a=[];for(let s of o){let i=U(s,t,r);i&&a.
|
|
51
|
+
push(i)}return a};var _=e=>T(e)?e.name:null;var M=!1,Kr=()=>(M||(He(),Re(),Fe("@ez4/database",{"metadata:getServices":$,"met\
|
|
52
|
+
adata:getLinkedService":_}),M=!0),M);export{S as IncompleteHandlerError,m as IncompleteServiceError,g 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,x as ServiceType,$ as getDatabaseServices,U as getDatabaseTable,
|
|
56
|
+
w as getTableSchema,Ve as isDatabaseService,Kr as registerTriggers};
|
package/dist/main.cjs
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
"use strict";var o=Object.defineProperty;var s=Object.getOwnPropertyDescriptor;var c=Object.getOwnPropertyNames;var T=Object.prototype.hasOwnProperty;var S=(r,t)=>{for(var m in t)o(r,m,{get:t[m],enumerable:!0})},l=(r,t,m,a)=>{if(t&&
|
|
2
|
+
typeof t=="object"||typeof t=="function")for(let e of c(t))!T.call(r,e)&&e!==m&&
|
|
3
|
+
o(r,e,{get:()=>t[e],enumerable:!(a=s(t,e))||a.enumerable});return r};var x=r=>l(o({},"__esModule",{value:!0}),r);var d={};S(d,{Database:()=>n,Index:()=>p,StreamType:()=>i});module.exports=x(d);var n;(r=>{})(n||={});var p=(e=>(e.Primary="primary",e.Regular="regular",e.Unique="unique",e.TTL="ttl",
|
|
4
|
+
e))(p||{});var i=(a=>(a.Insert="insert",a.Update="update",a.Delete="delete",a))(i||{});0&&(module.exports={Database,Index,StreamType});
|
package/dist/main.d.ts
ADDED
package/dist/main.mjs
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { AllType, SourceMap, TypeModel, TypeObject } from '@ez4/reflection';
|
|
2
|
+
import type { TableIndexes } from '../types/indexes.js';
|
|
3
|
+
type TypeParent = TypeModel | TypeObject;
|
|
4
|
+
export declare const getTableIndexes: (type: AllType, parent: TypeParent, reflection: SourceMap, errorList: Error[]) => TableIndexes | null;
|
|
5
|
+
export {};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { AllType, SourceMap, TypeModel, TypeObject } from '@ez4/reflection';
|
|
2
|
+
type TypeParent = TypeModel | TypeObject;
|
|
3
|
+
export declare const getTableSchema: (type: AllType, parent: TypeParent, reflection: SourceMap, errorList: Error[]) => import("@ez4/schema/library").ObjectSchema | null;
|
|
4
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { AllType, TypeCallback, TypeClass, TypeFunction, TypeModel } from '@ez4/reflection';
|
|
2
|
+
export declare const isDatabaseService: (type: AllType) => type is TypeClass;
|
|
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
|
+
export declare const isStreamHandler: (type: AllType) => type is TypeCallback | TypeFunction;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import type { EveryType, TypeObject } from '@ez4/reflection';
|
|
2
|
+
export type RichTypes = {
|
|
3
|
+
index?: string;
|
|
4
|
+
type: EveryType;
|
|
5
|
+
};
|
|
6
|
+
export declare const getRichTypes: (type: TypeObject) => RichTypes | null;
|
|
7
|
+
export declare const createRichType: (richType: RichTypes) => {
|
|
8
|
+
extra: {
|
|
9
|
+
index: "primary" | "regular";
|
|
10
|
+
};
|
|
11
|
+
type: import("@ez4/reflection").TypeName.Object;
|
|
12
|
+
file?: string;
|
|
13
|
+
members?: import("@ez4/reflection").EveryMemberType[];
|
|
14
|
+
} | {
|
|
15
|
+
extra: {
|
|
16
|
+
index: "primary" | "regular";
|
|
17
|
+
};
|
|
18
|
+
type: import("@ez4/reflection").TypeName.Any;
|
|
19
|
+
} | {
|
|
20
|
+
extra: {
|
|
21
|
+
index: "primary" | "regular";
|
|
22
|
+
};
|
|
23
|
+
type: import("@ez4/reflection").TypeName.Void;
|
|
24
|
+
} | {
|
|
25
|
+
extra: {
|
|
26
|
+
index: "primary" | "regular";
|
|
27
|
+
};
|
|
28
|
+
type: import("@ez4/reflection").TypeName.Never;
|
|
29
|
+
} | {
|
|
30
|
+
extra: {
|
|
31
|
+
index: "primary" | "regular";
|
|
32
|
+
};
|
|
33
|
+
type: import("@ez4/reflection").TypeName.Unknown;
|
|
34
|
+
} | {
|
|
35
|
+
extra: {
|
|
36
|
+
index: "primary" | "regular";
|
|
37
|
+
};
|
|
38
|
+
type: import("@ez4/reflection").TypeName.Undefined;
|
|
39
|
+
} | {
|
|
40
|
+
extra: {
|
|
41
|
+
index: "primary" | "regular";
|
|
42
|
+
};
|
|
43
|
+
type: import("@ez4/reflection").TypeName.Null;
|
|
44
|
+
literal?: boolean;
|
|
45
|
+
default?: boolean;
|
|
46
|
+
} | {
|
|
47
|
+
extra: {
|
|
48
|
+
index: "primary" | "regular";
|
|
49
|
+
};
|
|
50
|
+
type: import("@ez4/reflection").TypeName.Boolean;
|
|
51
|
+
literal?: boolean;
|
|
52
|
+
default?: boolean;
|
|
53
|
+
} | {
|
|
54
|
+
extra: {
|
|
55
|
+
index: "primary" | "regular";
|
|
56
|
+
};
|
|
57
|
+
type: import("@ez4/reflection").TypeName.Number;
|
|
58
|
+
literal?: number;
|
|
59
|
+
default?: number;
|
|
60
|
+
} | {
|
|
61
|
+
extra: {
|
|
62
|
+
index: "primary" | "regular";
|
|
63
|
+
};
|
|
64
|
+
type: import("@ez4/reflection").TypeName.String;
|
|
65
|
+
literal?: string;
|
|
66
|
+
default?: string;
|
|
67
|
+
} | {
|
|
68
|
+
extra: {
|
|
69
|
+
index: "primary" | "regular";
|
|
70
|
+
};
|
|
71
|
+
type: import("@ez4/reflection").TypeName.Reference;
|
|
72
|
+
namespace?: string;
|
|
73
|
+
internal?: boolean;
|
|
74
|
+
path: string;
|
|
75
|
+
} | {
|
|
76
|
+
extra: {
|
|
77
|
+
index: "primary" | "regular";
|
|
78
|
+
};
|
|
79
|
+
type: import("@ez4/reflection").TypeName.Union;
|
|
80
|
+
elements: EveryType[];
|
|
81
|
+
} | {
|
|
82
|
+
extra: {
|
|
83
|
+
index: "primary" | "regular";
|
|
84
|
+
};
|
|
85
|
+
type: import("@ez4/reflection").TypeName.Array;
|
|
86
|
+
element: EveryType;
|
|
87
|
+
spread?: boolean;
|
|
88
|
+
} | {
|
|
89
|
+
extra: {
|
|
90
|
+
index: "primary" | "regular";
|
|
91
|
+
};
|
|
92
|
+
type: import("@ez4/reflection").TypeName.Tuple;
|
|
93
|
+
elements: EveryType[];
|
|
94
|
+
} | {
|
|
95
|
+
extra: {
|
|
96
|
+
index: "primary" | "regular";
|
|
97
|
+
};
|
|
98
|
+
type: import("@ez4/reflection").TypeName.Callback;
|
|
99
|
+
name?: string;
|
|
100
|
+
file?: string;
|
|
101
|
+
description?: string;
|
|
102
|
+
parameters?: import("@ez4/reflection").TypeParameter[];
|
|
103
|
+
return?: EveryType;
|
|
104
|
+
} | null;
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import type { AnyObject, PartialProperties, PartialObject, DeepPartial } from '@ez4/utils';
|
|
2
|
+
import type { TableSchemas } from './helpers.js';
|
|
3
|
+
import type { Database } from './database.js';
|
|
4
|
+
/**
|
|
5
|
+
* Database client.
|
|
6
|
+
*/
|
|
7
|
+
export interface Client<T extends Database.Service<any>> {
|
|
8
|
+
/**
|
|
9
|
+
* Prepare and execute the given query.
|
|
10
|
+
*
|
|
11
|
+
* @param query Query statement.
|
|
12
|
+
* @param values Optional values to prepare the query.
|
|
13
|
+
* @returns Returns the results for the given query.
|
|
14
|
+
*/
|
|
15
|
+
rawQuery(query: string, values?: unknown[]): Promise<Record<string, unknown>[]>;
|
|
16
|
+
/**
|
|
17
|
+
* Table clients.
|
|
18
|
+
*/
|
|
19
|
+
table: ClientTables<T>;
|
|
20
|
+
}
|
|
21
|
+
export type ClientTables<T extends Database.Service<any>> = {
|
|
22
|
+
[P in keyof TableSchemas<T>]: TableSchemas<T>[P] extends Database.Schema ? Table<TableSchemas<T>[P]> : never;
|
|
23
|
+
};
|
|
24
|
+
export interface Table<T extends Database.Schema> {
|
|
25
|
+
insertOne(query: Query.InsertOneInput<T>): Promise<Query.InsertOneResult>;
|
|
26
|
+
updateMany<U extends Query.SelectInput<T>>(query: Query.UpdateManyInput<T, U>): Promise<Query.UpdateManyResult<T, U>>;
|
|
27
|
+
findFirst<U extends Query.SelectInput<T>>(query: Query.FindFirstInput<T, U>): Promise<Query.FindFirstResult<T, U>>;
|
|
28
|
+
findMany<U extends Query.SelectInput<T>>(query: Query.FindManyInput<T, U>): Promise<Query.FindManyResult<T, U>>;
|
|
29
|
+
deleteMany<U extends Query.SelectInput<T>>(query: Query.DeleteManyInput<T, U>): Promise<Query.DeleteManyResult<T, U>>;
|
|
30
|
+
}
|
|
31
|
+
export declare namespace Query {
|
|
32
|
+
type InsertOneInput<T extends Database.Schema> = {
|
|
33
|
+
data: T;
|
|
34
|
+
};
|
|
35
|
+
type UpdateManyInput<T extends Database.Schema, S extends Database.Schema> = {
|
|
36
|
+
select?: S;
|
|
37
|
+
data: DeepPartial<T>;
|
|
38
|
+
where: WhereInput<T>;
|
|
39
|
+
cursor?: number | string;
|
|
40
|
+
limit?: number;
|
|
41
|
+
};
|
|
42
|
+
type FindManyInput<T extends Database.Schema, S extends Database.Schema> = {
|
|
43
|
+
select: S;
|
|
44
|
+
where: WhereInput<T>;
|
|
45
|
+
cursor?: number | string;
|
|
46
|
+
limit?: number;
|
|
47
|
+
};
|
|
48
|
+
type DeleteManyInput<T extends Database.Schema, S extends Database.Schema> = {
|
|
49
|
+
select?: S;
|
|
50
|
+
where: WhereInput<T>;
|
|
51
|
+
cursor?: number | string;
|
|
52
|
+
limit?: number;
|
|
53
|
+
};
|
|
54
|
+
type FindFirstInput<T extends Database.Schema, S extends Database.Schema> = {
|
|
55
|
+
select: S;
|
|
56
|
+
where: WhereInput<T>;
|
|
57
|
+
};
|
|
58
|
+
type InsertOneResult = void;
|
|
59
|
+
type UpdateManyResult<T extends Database.Schema, S extends AnyObject> = Record<T, S>[];
|
|
60
|
+
type FindFirstResult<T extends Database.Schema, S extends AnyObject> = Record<T, S> | undefined;
|
|
61
|
+
type FindManyResult<T extends Database.Schema, S extends AnyObject> = {
|
|
62
|
+
records: Record<T, S>[];
|
|
63
|
+
cursor?: number | string;
|
|
64
|
+
};
|
|
65
|
+
type DeleteManyResult<T extends Database.Schema, S extends AnyObject> = Record<T, S>[];
|
|
66
|
+
type Record<T extends Database.Schema, S extends AnyObject> = PartialObject<T, S, false>;
|
|
67
|
+
type SelectInput<T extends Database.Schema> = PartialProperties<T>;
|
|
68
|
+
type WhereInput<T extends Database.Schema> = WhereFields<T> & WhereNot<T> & WhereAnd<T> & WhereOr<T>;
|
|
69
|
+
type WhereFields<T extends Database.Schema> = {
|
|
70
|
+
[P in keyof T]?: T[P] extends AnyObject ? WhereFields<T[P]> : T[P] | WhereOperations<T[P]>;
|
|
71
|
+
};
|
|
72
|
+
type WhereNot<T extends Database.Schema> = {
|
|
73
|
+
NOT?: WhereInput<T> | WhereAnd<T> | WhereOr<T>;
|
|
74
|
+
};
|
|
75
|
+
type WhereAnd<T extends Database.Schema> = {
|
|
76
|
+
AND?: (WhereInput<T> | WhereOr<T> | WhereNot<T>)[];
|
|
77
|
+
};
|
|
78
|
+
type WhereOr<T extends Database.Schema> = {
|
|
79
|
+
OR?: (WhereInput<T> | WhereAnd<T> | WhereNot<T>)[];
|
|
80
|
+
};
|
|
81
|
+
type WhereOperations<T> = WhereNegate<T> | WhereEqual<T> | WhereGreaterThan<T> | WhereGreaterThanOrEqual<T> | WhereLessThan<T> | WhereLessThanOrEqual<T> | WhereIn<T> | WhereBetween<T> | WhereIsMissing | WhereIsNull | WhereStartsWith | WhereContains;
|
|
82
|
+
type WhereOperators = keyof (WhereNegate<any> & WhereEqual<any> & WhereGreaterThan<any> & WhereGreaterThanOrEqual<any> & WhereLessThan<any> & WhereLessThanOrEqual<any> & WhereIn<any> & WhereBetween<any> & WhereIsMissing & WhereIsNull & WhereStartsWith & WhereContains);
|
|
83
|
+
type WhereNegate<T> = {
|
|
84
|
+
not: T | WhereOperations<T>;
|
|
85
|
+
};
|
|
86
|
+
type WhereEqual<T> = {
|
|
87
|
+
equal: T;
|
|
88
|
+
};
|
|
89
|
+
type WhereGreaterThan<T> = {
|
|
90
|
+
gt: T;
|
|
91
|
+
};
|
|
92
|
+
type WhereGreaterThanOrEqual<T> = {
|
|
93
|
+
gte: T;
|
|
94
|
+
};
|
|
95
|
+
type WhereLessThan<T> = {
|
|
96
|
+
lt: T;
|
|
97
|
+
};
|
|
98
|
+
type WhereLessThanOrEqual<T> = {
|
|
99
|
+
lte: T;
|
|
100
|
+
};
|
|
101
|
+
type WhereIn<T> = {
|
|
102
|
+
isIn: T[];
|
|
103
|
+
};
|
|
104
|
+
type WhereBetween<T> = {
|
|
105
|
+
isBetween: [T, T];
|
|
106
|
+
};
|
|
107
|
+
type WhereIsMissing = {
|
|
108
|
+
isMissing: boolean;
|
|
109
|
+
};
|
|
110
|
+
type WhereIsNull = {
|
|
111
|
+
isNull: boolean;
|
|
112
|
+
};
|
|
113
|
+
type WhereStartsWith = {
|
|
114
|
+
startsWith: string;
|
|
115
|
+
};
|
|
116
|
+
type WhereContains = {
|
|
117
|
+
contains: string;
|
|
118
|
+
};
|
|
119
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import type { Service } from '@ez4/common';
|
|
2
|
+
import type { LinkedVariables } from '@ez4/project';
|
|
3
|
+
import type { TableTypes } from './helpers.js';
|
|
4
|
+
import type { StreamChange } from './stream.js';
|
|
5
|
+
import type { Index } from './indexes.js';
|
|
6
|
+
import type { Client } from './client.js';
|
|
7
|
+
/**
|
|
8
|
+
* Provide all contracts for a self-managed database service.
|
|
9
|
+
*/
|
|
10
|
+
export declare namespace Database {
|
|
11
|
+
/**
|
|
12
|
+
* Table schema.
|
|
13
|
+
*/
|
|
14
|
+
interface Schema {
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Table indexes.
|
|
18
|
+
*/
|
|
19
|
+
type Indexes<T extends Schema = Schema> = {
|
|
20
|
+
[P in `${string & keyof T}:${string & keyof T}` | keyof T]?: Index;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Table stream.
|
|
24
|
+
*/
|
|
25
|
+
interface Stream<T extends Schema = Schema> {
|
|
26
|
+
/**
|
|
27
|
+
* Stream handler.
|
|
28
|
+
*
|
|
29
|
+
* @param change Stream change.
|
|
30
|
+
* @param context Handler context.
|
|
31
|
+
*/
|
|
32
|
+
handler: (change: StreamChange<T>, context: Service.Context<Service<any>>) => void | Promise<void>;
|
|
33
|
+
/**
|
|
34
|
+
* Variables associated to the route.
|
|
35
|
+
*/
|
|
36
|
+
variables?: LinkedVariables;
|
|
37
|
+
/**
|
|
38
|
+
* Max route execution time (in seconds) for the handler.
|
|
39
|
+
*/
|
|
40
|
+
timeout?: number;
|
|
41
|
+
/**
|
|
42
|
+
* Amount of memory available for the handler.
|
|
43
|
+
*/
|
|
44
|
+
memory?: number;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Database table.
|
|
48
|
+
*/
|
|
49
|
+
interface Table<T extends Schema = Schema> {
|
|
50
|
+
/**
|
|
51
|
+
* Table name.
|
|
52
|
+
*/
|
|
53
|
+
name: string;
|
|
54
|
+
/**
|
|
55
|
+
* Table schema.
|
|
56
|
+
*/
|
|
57
|
+
schema: T;
|
|
58
|
+
/**
|
|
59
|
+
* Table indexes.
|
|
60
|
+
*/
|
|
61
|
+
indexes: Indexes<T>;
|
|
62
|
+
/**
|
|
63
|
+
* Table stream configuration.
|
|
64
|
+
*/
|
|
65
|
+
stream?: Stream<T>;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Database service.
|
|
69
|
+
*/
|
|
70
|
+
abstract class Service<T extends Schema[] = [Schema]> implements Service.Provider {
|
|
71
|
+
/**
|
|
72
|
+
* All service tables.
|
|
73
|
+
*/
|
|
74
|
+
abstract tables: TableTypes<T>[];
|
|
75
|
+
/**
|
|
76
|
+
* Service client.
|
|
77
|
+
*/
|
|
78
|
+
client: Client<Service<T>>;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { ArrayRest, IsArrayEmpty, IsAny } from '@ez4/utils';
|
|
2
|
+
import type { Database } from './database.js';
|
|
3
|
+
/**
|
|
4
|
+
* Given an array of schemas `T`, it returns an union of `Database.Table` for each schema.
|
|
5
|
+
*/
|
|
6
|
+
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>>;
|
|
7
|
+
/**
|
|
8
|
+
* Given a database service `T`, it returns a map containing all its tables and schemas.
|
|
9
|
+
*/
|
|
10
|
+
export type TableSchemas<T extends Database.Service<any>> = MergeTables<ServiceTables<T>>;
|
|
11
|
+
/**
|
|
12
|
+
* Given a database service `T`, it returns all its table types.
|
|
13
|
+
*/
|
|
14
|
+
type ServiceTables<T> = T extends {
|
|
15
|
+
tables: infer U;
|
|
16
|
+
} ? U : [];
|
|
17
|
+
/**
|
|
18
|
+
* Given a list of database tables `T`, it returns an object containing all table names and schemas.
|
|
19
|
+
*/
|
|
20
|
+
type MergeTables<T extends Database.Table[]> = IsArrayEmpty<T> extends true ? {} : TableRecord<T[0]> & MergeTables<ArrayRest<T>>;
|
|
21
|
+
/**
|
|
22
|
+
* Given a database table `T`, it returns a table record containing its `name` and `schema`.
|
|
23
|
+
*/
|
|
24
|
+
type TableRecord<T> = T extends {
|
|
25
|
+
name: infer N;
|
|
26
|
+
schema: infer S;
|
|
27
|
+
} ? N extends string ? {
|
|
28
|
+
[P in N]: S;
|
|
29
|
+
} : {} : {};
|
|
30
|
+
export {};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stream change for `insert`, `update` or `delete` operations.
|
|
3
|
+
*/
|
|
4
|
+
export type StreamChange<T> = StreamInsertChange<T> | StreamUpdateChange<T> | StreamDeleteChange<T>;
|
|
5
|
+
/**
|
|
6
|
+
* Stream change for an `insert` operation.
|
|
7
|
+
*/
|
|
8
|
+
export type StreamInsertChange<T> = {
|
|
9
|
+
type: StreamType.Insert;
|
|
10
|
+
record: T;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Stream change for an `update` operation.
|
|
14
|
+
*/
|
|
15
|
+
export type StreamUpdateChange<T> = {
|
|
16
|
+
type: StreamType.Update;
|
|
17
|
+
oldRecord: T;
|
|
18
|
+
newRecord: T;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Stream change for an `delete` operation.
|
|
22
|
+
*/
|
|
23
|
+
export type StreamDeleteChange<T> = {
|
|
24
|
+
type: StreamType.Delete;
|
|
25
|
+
record: T;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Stream change types.
|
|
29
|
+
*/
|
|
30
|
+
export declare const enum StreamType {
|
|
31
|
+
Insert = "insert",
|
|
32
|
+
Update = "update",
|
|
33
|
+
Delete = "delete"
|
|
34
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import type { TypeObject } from '@ez4/reflection';
|
|
2
|
+
export declare const applyRichTypePath: (file: string) => string | null;
|
|
3
|
+
export declare const applyRichTypeObject: (type: TypeObject) => {
|
|
4
|
+
extra: {
|
|
5
|
+
index: "primary" | "regular";
|
|
6
|
+
};
|
|
7
|
+
type: import("@ez4/reflection").TypeName.Object;
|
|
8
|
+
file?: string;
|
|
9
|
+
members?: import("@ez4/reflection").EveryMemberType[];
|
|
10
|
+
} | {
|
|
11
|
+
extra: {
|
|
12
|
+
index: "primary" | "regular";
|
|
13
|
+
};
|
|
14
|
+
type: import("@ez4/reflection").TypeName.Any;
|
|
15
|
+
} | {
|
|
16
|
+
extra: {
|
|
17
|
+
index: "primary" | "regular";
|
|
18
|
+
};
|
|
19
|
+
type: import("@ez4/reflection").TypeName.Void;
|
|
20
|
+
} | {
|
|
21
|
+
extra: {
|
|
22
|
+
index: "primary" | "regular";
|
|
23
|
+
};
|
|
24
|
+
type: import("@ez4/reflection").TypeName.Never;
|
|
25
|
+
} | {
|
|
26
|
+
extra: {
|
|
27
|
+
index: "primary" | "regular";
|
|
28
|
+
};
|
|
29
|
+
type: import("@ez4/reflection").TypeName.Unknown;
|
|
30
|
+
} | {
|
|
31
|
+
extra: {
|
|
32
|
+
index: "primary" | "regular";
|
|
33
|
+
};
|
|
34
|
+
type: import("@ez4/reflection").TypeName.Undefined;
|
|
35
|
+
} | {
|
|
36
|
+
extra: {
|
|
37
|
+
index: "primary" | "regular";
|
|
38
|
+
};
|
|
39
|
+
type: import("@ez4/reflection").TypeName.Null;
|
|
40
|
+
literal?: boolean;
|
|
41
|
+
default?: boolean;
|
|
42
|
+
} | {
|
|
43
|
+
extra: {
|
|
44
|
+
index: "primary" | "regular";
|
|
45
|
+
};
|
|
46
|
+
type: import("@ez4/reflection").TypeName.Boolean;
|
|
47
|
+
literal?: boolean;
|
|
48
|
+
default?: boolean;
|
|
49
|
+
} | {
|
|
50
|
+
extra: {
|
|
51
|
+
index: "primary" | "regular";
|
|
52
|
+
};
|
|
53
|
+
type: import("@ez4/reflection").TypeName.Number;
|
|
54
|
+
literal?: number;
|
|
55
|
+
default?: number;
|
|
56
|
+
} | {
|
|
57
|
+
extra: {
|
|
58
|
+
index: "primary" | "regular";
|
|
59
|
+
};
|
|
60
|
+
type: import("@ez4/reflection").TypeName.String;
|
|
61
|
+
literal?: string;
|
|
62
|
+
default?: string;
|
|
63
|
+
} | {
|
|
64
|
+
extra: {
|
|
65
|
+
index: "primary" | "regular";
|
|
66
|
+
};
|
|
67
|
+
type: import("@ez4/reflection").TypeName.Reference;
|
|
68
|
+
namespace?: string;
|
|
69
|
+
internal?: boolean;
|
|
70
|
+
path: string;
|
|
71
|
+
} | {
|
|
72
|
+
extra: {
|
|
73
|
+
index: "primary" | "regular";
|
|
74
|
+
};
|
|
75
|
+
type: import("@ez4/reflection").TypeName.Union;
|
|
76
|
+
elements: import("@ez4/reflection").EveryType[];
|
|
77
|
+
} | {
|
|
78
|
+
extra: {
|
|
79
|
+
index: "primary" | "regular";
|
|
80
|
+
};
|
|
81
|
+
type: import("@ez4/reflection").TypeName.Array;
|
|
82
|
+
element: import("@ez4/reflection").EveryType;
|
|
83
|
+
spread?: boolean;
|
|
84
|
+
} | {
|
|
85
|
+
extra: {
|
|
86
|
+
index: "primary" | "regular";
|
|
87
|
+
};
|
|
88
|
+
type: import("@ez4/reflection").TypeName.Tuple;
|
|
89
|
+
elements: import("@ez4/reflection").EveryType[];
|
|
90
|
+
} | {
|
|
91
|
+
extra: {
|
|
92
|
+
index: "primary" | "regular";
|
|
93
|
+
};
|
|
94
|
+
type: import("@ez4/reflection").TypeName.Callback;
|
|
95
|
+
name?: string;
|
|
96
|
+
file?: string;
|
|
97
|
+
description?: string;
|
|
98
|
+
parameters?: import("@ez4/reflection").TypeParameter[];
|
|
99
|
+
return?: import("@ez4/reflection").EveryType;
|
|
100
|
+
} | null;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ServiceMetadata } from '@ez4/project';
|
|
2
|
+
import type { DatabaseTable } from './table.js';
|
|
3
|
+
export declare const ServiceType = "@ez4/database";
|
|
4
|
+
export type DatabaseService = ServiceMetadata & {
|
|
5
|
+
type: typeof ServiceType;
|
|
6
|
+
name: string;
|
|
7
|
+
tables: DatabaseTable[];
|
|
8
|
+
};
|
|
9
|
+
export declare const isDatabaseService: (service: ServiceMetadata) => service is DatabaseService;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { TableSchema } from './schema.js';
|
|
2
|
+
import type { TableIndexes } from './indexes.js';
|
|
3
|
+
import type { TableStream } from './stream.js';
|
|
4
|
+
export type DatabaseTable = {
|
|
5
|
+
name: string;
|
|
6
|
+
schema: TableSchema;
|
|
7
|
+
indexes: TableIndexes;
|
|
8
|
+
stream?: TableStream;
|
|
9
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ez4/database",
|
|
3
|
+
"description": "EZ4: Components to build database services",
|
|
4
|
+
"version": "0.1.0",
|
|
5
|
+
"author": "Silas B.",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/main.d.ts",
|
|
11
|
+
"require": "./dist/main.cjs",
|
|
12
|
+
"import": "./dist/main.mjs"
|
|
13
|
+
},
|
|
14
|
+
"./library": {
|
|
15
|
+
"types": "./dist/library.d.ts",
|
|
16
|
+
"require": "./dist/library.cjs",
|
|
17
|
+
"import": "./dist/library.mjs"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"workspaces": [
|
|
21
|
+
"packages/*"
|
|
22
|
+
],
|
|
23
|
+
"scripts": {
|
|
24
|
+
"clean": "rm -f *.tsbuildinfo && rm -rf dist/*",
|
|
25
|
+
"build": "tsc -p tsconfig.json && node tools/bundler.mjs",
|
|
26
|
+
"test": "npm run test:types && node --test --import ../../tools/tsnode.mjs test/*.spec.ts",
|
|
27
|
+
"test:only": "npm run test:types && node --test-only --test --import ../../tools/tsnode.mjs test/*.spec.ts",
|
|
28
|
+
"test:types": "npm run build && tsc -p tsconfig.test.json",
|
|
29
|
+
"local:publish": "npm run build && npm run clean:registry && npm publish --registry http://localhost:4873",
|
|
30
|
+
"clean:registry": "rm -rf ../../.registry/@ez4/database",
|
|
31
|
+
"live:publish": "npm run test && npm publish --access public"
|
|
32
|
+
},
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"@ez4/common": "^0.1.0",
|
|
35
|
+
"@ez4/project": "^0.1.0",
|
|
36
|
+
"@ez4/reflection": "^0.1.0",
|
|
37
|
+
"@ez4/schema": "^0.1.0",
|
|
38
|
+
"@ez4/utils": "^0.1.0"
|
|
39
|
+
}
|
|
40
|
+
}
|