rads-db 0.1.63 → 0.1.64
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/index.cjs +95 -21
- package/dist/index.d.ts +14 -1
- package/dist/index.mjs +91 -21
- package/package.json +5 -2
package/dist/index.cjs
CHANGED
|
@@ -1,16 +1,24 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const _ = require('lodash');
|
|
4
3
|
const h3 = require('h3');
|
|
5
4
|
const zod = require('zod');
|
|
5
|
+
const _ = require('lodash');
|
|
6
6
|
const createMerge = require('@fastify/deepmerge');
|
|
7
7
|
const uuid = require('uuid');
|
|
8
|
+
const fs = require('node:fs/promises');
|
|
9
|
+
const path = require('node:path');
|
|
10
|
+
const klaw = require('klaw');
|
|
11
|
+
const ignore = require('ignore');
|
|
8
12
|
const _radsDb = require('_rads-db');
|
|
9
13
|
|
|
10
14
|
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
|
11
15
|
|
|
12
16
|
const ___default = /*#__PURE__*/_interopDefaultCompat(_);
|
|
13
17
|
const createMerge__default = /*#__PURE__*/_interopDefaultCompat(createMerge);
|
|
18
|
+
const fs__default = /*#__PURE__*/_interopDefaultCompat(fs);
|
|
19
|
+
const path__default = /*#__PURE__*/_interopDefaultCompat(path);
|
|
20
|
+
const klaw__default = /*#__PURE__*/_interopDefaultCompat(klaw);
|
|
21
|
+
const ignore__default = /*#__PURE__*/_interopDefaultCompat(ignore);
|
|
14
22
|
|
|
15
23
|
function generateValidators(schema) {
|
|
16
24
|
const zodSchemas = {};
|
|
@@ -879,6 +887,89 @@ function getDriverInstanceInner(schema, key, driverConstructor) {
|
|
|
879
887
|
};
|
|
880
888
|
}
|
|
881
889
|
|
|
890
|
+
let gitignore;
|
|
891
|
+
const radsTunnelSvcDev = {
|
|
892
|
+
async fsGetFileTree() {
|
|
893
|
+
const results = [];
|
|
894
|
+
await ensureGitignoreCreated();
|
|
895
|
+
const klawIterator = await klaw__default(".", {
|
|
896
|
+
depthLimit: 15,
|
|
897
|
+
preserveSymlinks: true,
|
|
898
|
+
filter: (p) => {
|
|
899
|
+
const rp = path__default.relative(".", p);
|
|
900
|
+
if (rp.startsWith(".git"))
|
|
901
|
+
return false;
|
|
902
|
+
return !gitignore.ignores(rp);
|
|
903
|
+
}
|
|
904
|
+
});
|
|
905
|
+
for await (const file of klawIterator) {
|
|
906
|
+
if (file.stats.isSymbolicLink())
|
|
907
|
+
continue;
|
|
908
|
+
const rp = path__default.relative(".", file.path);
|
|
909
|
+
results.push({
|
|
910
|
+
sha: rp,
|
|
911
|
+
mode: `${file.stats.mode}`,
|
|
912
|
+
path: rp,
|
|
913
|
+
type: file.stats.isDirectory() ? "tree" : "blob",
|
|
914
|
+
size: file.stats.size
|
|
915
|
+
});
|
|
916
|
+
}
|
|
917
|
+
return results;
|
|
918
|
+
},
|
|
919
|
+
async fsGetBlobContent(args) {
|
|
920
|
+
const text = await fs__default.readFile(args.path, "utf-8");
|
|
921
|
+
return { text };
|
|
922
|
+
},
|
|
923
|
+
async fsPutFile(args) {
|
|
924
|
+
await fs__default.writeFile(args.path, args.content, "utf-8");
|
|
925
|
+
return {};
|
|
926
|
+
}
|
|
927
|
+
};
|
|
928
|
+
async function ensureGitignoreCreated() {
|
|
929
|
+
if (gitignore)
|
|
930
|
+
return;
|
|
931
|
+
const gitignoreStr = await fs__default.readFile("./.gitignore", "utf-8");
|
|
932
|
+
gitignore = ignore__default().add(gitignoreStr.split("\n").filter((x) => x));
|
|
933
|
+
}
|
|
934
|
+
|
|
935
|
+
const radsTunnelSvc = {
|
|
936
|
+
getRadsTunnelHandler(db) {
|
|
937
|
+
return async function radsTunnelHandler(request, ctx) {
|
|
938
|
+
const { method, entity, args, uploadArgs } = request?.body || {};
|
|
939
|
+
if (method === "uploadFile") {
|
|
940
|
+
const blob = getBlobFromDataUrl$1(uploadArgs?.blobDataUrl);
|
|
941
|
+
if (!blob)
|
|
942
|
+
throw h3.createError({ statusCode: 400, message: 'Malformed request - "blobDataUrl" is required' });
|
|
943
|
+
return db.uploadFile({ blob, ...uploadArgs }, ctx);
|
|
944
|
+
}
|
|
945
|
+
if (method === "_schema") {
|
|
946
|
+
return db._schema;
|
|
947
|
+
}
|
|
948
|
+
if (process.env.NODE_ENV === "development") {
|
|
949
|
+
const devHandler = radsTunnelSvcDev[method];
|
|
950
|
+
if (devHandler)
|
|
951
|
+
return devHandler(args);
|
|
952
|
+
}
|
|
953
|
+
if (!method || !entity)
|
|
954
|
+
throw h3.createError({ statusCode: 400, message: 'Malformed request - missing "method" or "entity"' });
|
|
955
|
+
const handle = db[___default.lowerFirst(entity)];
|
|
956
|
+
if (!handle)
|
|
957
|
+
throw h3.createError({ statusCode: 400, message: `Malformed request - entity "${entity}" not found` });
|
|
958
|
+
if (!handle[method])
|
|
959
|
+
throw h3.createError({ statusCode: 400, message: `Unknown method - ${method}` });
|
|
960
|
+
return await handle[method](args, ctx);
|
|
961
|
+
};
|
|
962
|
+
}
|
|
963
|
+
};
|
|
964
|
+
function getBlobFromDataUrl$1(dataUrl) {
|
|
965
|
+
const [header, b64string] = dataUrl?.split(",");
|
|
966
|
+
const [protocol, format] = header?.split(":");
|
|
967
|
+
const [type, algorithm] = format?.split(";");
|
|
968
|
+
if (protocol !== "data" || algorithm !== "base64" || !b64string)
|
|
969
|
+
throw h3.createError({ statusCode: 400, message: "Malformed request - bad dataUrl" });
|
|
970
|
+
return new Blob([Buffer.from(b64string, "base64")], { type });
|
|
971
|
+
}
|
|
972
|
+
|
|
882
973
|
function entity(meta) {
|
|
883
974
|
return function(classConstructor, _ctx) {
|
|
884
975
|
};
|
|
@@ -915,7 +1006,9 @@ function getRestRoutes(options) {
|
|
|
915
1006
|
const routes = {};
|
|
916
1007
|
const schema2 = db._schema;
|
|
917
1008
|
routes[`${prefix}me`] = { GET: async (args, ctx) => ({ userId: ctx?.getUser?.()?.id }) };
|
|
918
|
-
routes[`${prefix}radsTunnel`] = {
|
|
1009
|
+
routes[`${prefix}radsTunnel`] = {
|
|
1010
|
+
POST: radsTunnelSvc.getRadsTunnelHandler(db)
|
|
1011
|
+
};
|
|
919
1012
|
routes[`${prefix}uploadFile`] = { POST: getUploadFileHandler(db) };
|
|
920
1013
|
for (const key in schema2) {
|
|
921
1014
|
const entity = schema2[key];
|
|
@@ -948,25 +1041,6 @@ function getUploadFileHandler(db) {
|
|
|
948
1041
|
);
|
|
949
1042
|
};
|
|
950
1043
|
}
|
|
951
|
-
function getRadsTunnelHandler(db) {
|
|
952
|
-
return async function radsTunnelHandler(request, ctx) {
|
|
953
|
-
const { method, entity, args, uploadArgs } = request?.body || {};
|
|
954
|
-
if (method === "uploadFile") {
|
|
955
|
-
const blob = getBlobFromDataUrl(uploadArgs?.blobDataUrl);
|
|
956
|
-
if (!blob)
|
|
957
|
-
throw h3.createError({ statusCode: 400, message: 'Malformed request - "blobDataUrl" is required' });
|
|
958
|
-
return db.uploadFile({ blob, ...uploadArgs }, ctx);
|
|
959
|
-
}
|
|
960
|
-
if (!method || !entity)
|
|
961
|
-
throw h3.createError({ statusCode: 400, message: 'Malformed request - missing "method" or "entity"' });
|
|
962
|
-
const handle = db[___default.lowerFirst(entity)];
|
|
963
|
-
if (!handle)
|
|
964
|
-
throw h3.createError({ statusCode: 400, message: `Malformed request - entity "${entity}" not found` });
|
|
965
|
-
if (!handle[method])
|
|
966
|
-
throw h3.createError({ statusCode: 400, message: `Unknown method - ${method}` });
|
|
967
|
-
return await handle[method](args, ctx);
|
|
968
|
-
};
|
|
969
|
-
}
|
|
970
1044
|
function getBlobFromDataUrl(dataUrl) {
|
|
971
1045
|
const [header, b64string] = dataUrl?.split(",");
|
|
972
1046
|
const [protocol, format] = header?.split(":");
|
package/dist/index.d.ts
CHANGED
|
@@ -257,6 +257,19 @@ interface RadsRequestContext {
|
|
|
257
257
|
role: string;
|
|
258
258
|
} | undefined;
|
|
259
259
|
}
|
|
260
|
+
interface GithubTreeResponse {
|
|
261
|
+
sha: string;
|
|
262
|
+
tree: GithubTreeItem[];
|
|
263
|
+
truncated: boolean;
|
|
264
|
+
url: string;
|
|
265
|
+
}
|
|
266
|
+
interface GithubTreeItem {
|
|
267
|
+
mode: string;
|
|
268
|
+
path: string;
|
|
269
|
+
sha: string;
|
|
270
|
+
size?: number;
|
|
271
|
+
type: 'blob' | 'tree';
|
|
272
|
+
}
|
|
260
273
|
|
|
261
274
|
declare function entity<T>(meta?: EntityDecoratorArgs): (classConstructor: new () => T, _ctx?: ClassDecoratorContext<any>) => void;
|
|
262
275
|
declare function ui<T>(args: T extends new () => any ? UiDecoratorArgs<InstanceType<T>> : UiFieldDecoratorArgs): (classConstructor: T, _ctx?: ClassDecoratorContext | ClassFieldDecoratorContext) => void;
|
|
@@ -268,4 +281,4 @@ declare function computed(meta?: ComputedDecoratorArgs): (a: any, b?: ClassField
|
|
|
268
281
|
declare function createRads(args?: CreateRadsArgs): RadsDb;
|
|
269
282
|
declare function getRestRoutes(options: GetRestRoutesOptions): GetRestRoutesResponse;
|
|
270
283
|
|
|
271
|
-
export { Change, ComputedContext, ComputedDecoratorArgs, CreateRadsArgs, DeepPartial, DeepPartialNullable, Driver, DriverConstructor, EntityDecoratorArgs, EntityMethods, FieldDecoratorArgs, FieldDefinition, FileUploadArgs, FileUploadDriver, GenerateClientNormalizedOptions, GenerateClientOptions, GetAggArgs, GetAggArgsAgg, GetAggArgsAny, GetAggResponse, GetArgs, GetArgsAny, GetArgsInclude, GetManyArgs, GetManyArgsAny, GetManyResponse, GetResponse, GetResponseInclude, GetResponseIncludeSelect, GetResponseNoInclude, GetRestRoutesArgs, GetRestRoutesOptions, GetRestRoutesResponse, MinimalDriver, PutArgs, PutEffect, RadsRequestContext, RadsVitePluginOptions, Relation, RestFileUploadDriverOptions, Schema, SchemaValidators, TypeDefinition, UiDecoratorArgs, UiFieldDecoratorArgs, ValidateEntityDecoratorArgs, ValidateFieldDecoratorArgs, ValidateStringDecoratorArgs, computed, createRads, entity, field, getRestRoutes, precomputed, ui, validate };
|
|
284
|
+
export { Change, ComputedContext, ComputedDecoratorArgs, CreateRadsArgs, DeepPartial, DeepPartialNullable, Driver, DriverConstructor, EntityDecoratorArgs, EntityMethods, FieldDecoratorArgs, FieldDefinition, FileUploadArgs, FileUploadDriver, GenerateClientNormalizedOptions, GenerateClientOptions, GetAggArgs, GetAggArgsAgg, GetAggArgsAny, GetAggResponse, GetArgs, GetArgsAny, GetArgsInclude, GetManyArgs, GetManyArgsAny, GetManyResponse, GetResponse, GetResponseInclude, GetResponseIncludeSelect, GetResponseNoInclude, GetRestRoutesArgs, GetRestRoutesOptions, GetRestRoutesResponse, GithubTreeItem, GithubTreeResponse, MinimalDriver, PutArgs, PutEffect, RadsRequestContext, RadsVitePluginOptions, Relation, RestFileUploadDriverOptions, Schema, SchemaValidators, TypeDefinition, UiDecoratorArgs, UiFieldDecoratorArgs, ValidateEntityDecoratorArgs, ValidateFieldDecoratorArgs, ValidateStringDecoratorArgs, computed, createRads, entity, field, getRestRoutes, precomputed, ui, validate };
|
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
|
-
import _ from 'lodash';
|
|
2
1
|
import { createError } from 'h3';
|
|
3
2
|
import { z } from 'zod';
|
|
3
|
+
import _ from 'lodash';
|
|
4
4
|
import createMerge from '@fastify/deepmerge';
|
|
5
5
|
import { v4 } from 'uuid';
|
|
6
|
+
import fs from 'node:fs/promises';
|
|
7
|
+
import path from 'node:path';
|
|
8
|
+
import klaw from 'klaw';
|
|
9
|
+
import ignore from 'ignore';
|
|
6
10
|
import { schema } from '_rads-db';
|
|
7
11
|
|
|
8
12
|
function generateValidators(schema) {
|
|
@@ -872,6 +876,89 @@ function getDriverInstanceInner(schema, key, driverConstructor) {
|
|
|
872
876
|
};
|
|
873
877
|
}
|
|
874
878
|
|
|
879
|
+
let gitignore;
|
|
880
|
+
const radsTunnelSvcDev = {
|
|
881
|
+
async fsGetFileTree() {
|
|
882
|
+
const results = [];
|
|
883
|
+
await ensureGitignoreCreated();
|
|
884
|
+
const klawIterator = await klaw(".", {
|
|
885
|
+
depthLimit: 15,
|
|
886
|
+
preserveSymlinks: true,
|
|
887
|
+
filter: (p) => {
|
|
888
|
+
const rp = path.relative(".", p);
|
|
889
|
+
if (rp.startsWith(".git"))
|
|
890
|
+
return false;
|
|
891
|
+
return !gitignore.ignores(rp);
|
|
892
|
+
}
|
|
893
|
+
});
|
|
894
|
+
for await (const file of klawIterator) {
|
|
895
|
+
if (file.stats.isSymbolicLink())
|
|
896
|
+
continue;
|
|
897
|
+
const rp = path.relative(".", file.path);
|
|
898
|
+
results.push({
|
|
899
|
+
sha: rp,
|
|
900
|
+
mode: `${file.stats.mode}`,
|
|
901
|
+
path: rp,
|
|
902
|
+
type: file.stats.isDirectory() ? "tree" : "blob",
|
|
903
|
+
size: file.stats.size
|
|
904
|
+
});
|
|
905
|
+
}
|
|
906
|
+
return results;
|
|
907
|
+
},
|
|
908
|
+
async fsGetBlobContent(args) {
|
|
909
|
+
const text = await fs.readFile(args.path, "utf-8");
|
|
910
|
+
return { text };
|
|
911
|
+
},
|
|
912
|
+
async fsPutFile(args) {
|
|
913
|
+
await fs.writeFile(args.path, args.content, "utf-8");
|
|
914
|
+
return {};
|
|
915
|
+
}
|
|
916
|
+
};
|
|
917
|
+
async function ensureGitignoreCreated() {
|
|
918
|
+
if (gitignore)
|
|
919
|
+
return;
|
|
920
|
+
const gitignoreStr = await fs.readFile("./.gitignore", "utf-8");
|
|
921
|
+
gitignore = ignore().add(gitignoreStr.split("\n").filter((x) => x));
|
|
922
|
+
}
|
|
923
|
+
|
|
924
|
+
const radsTunnelSvc = {
|
|
925
|
+
getRadsTunnelHandler(db) {
|
|
926
|
+
return async function radsTunnelHandler(request, ctx) {
|
|
927
|
+
const { method, entity, args, uploadArgs } = request?.body || {};
|
|
928
|
+
if (method === "uploadFile") {
|
|
929
|
+
const blob = getBlobFromDataUrl$1(uploadArgs?.blobDataUrl);
|
|
930
|
+
if (!blob)
|
|
931
|
+
throw createError({ statusCode: 400, message: 'Malformed request - "blobDataUrl" is required' });
|
|
932
|
+
return db.uploadFile({ blob, ...uploadArgs }, ctx);
|
|
933
|
+
}
|
|
934
|
+
if (method === "_schema") {
|
|
935
|
+
return db._schema;
|
|
936
|
+
}
|
|
937
|
+
if (process.env.NODE_ENV === "development") {
|
|
938
|
+
const devHandler = radsTunnelSvcDev[method];
|
|
939
|
+
if (devHandler)
|
|
940
|
+
return devHandler(args);
|
|
941
|
+
}
|
|
942
|
+
if (!method || !entity)
|
|
943
|
+
throw createError({ statusCode: 400, message: 'Malformed request - missing "method" or "entity"' });
|
|
944
|
+
const handle = db[_.lowerFirst(entity)];
|
|
945
|
+
if (!handle)
|
|
946
|
+
throw createError({ statusCode: 400, message: `Malformed request - entity "${entity}" not found` });
|
|
947
|
+
if (!handle[method])
|
|
948
|
+
throw createError({ statusCode: 400, message: `Unknown method - ${method}` });
|
|
949
|
+
return await handle[method](args, ctx);
|
|
950
|
+
};
|
|
951
|
+
}
|
|
952
|
+
};
|
|
953
|
+
function getBlobFromDataUrl$1(dataUrl) {
|
|
954
|
+
const [header, b64string] = dataUrl?.split(",");
|
|
955
|
+
const [protocol, format] = header?.split(":");
|
|
956
|
+
const [type, algorithm] = format?.split(";");
|
|
957
|
+
if (protocol !== "data" || algorithm !== "base64" || !b64string)
|
|
958
|
+
throw createError({ statusCode: 400, message: "Malformed request - bad dataUrl" });
|
|
959
|
+
return new Blob([Buffer.from(b64string, "base64")], { type });
|
|
960
|
+
}
|
|
961
|
+
|
|
875
962
|
function entity(meta) {
|
|
876
963
|
return function(classConstructor, _ctx) {
|
|
877
964
|
};
|
|
@@ -908,7 +995,9 @@ function getRestRoutes(options) {
|
|
|
908
995
|
const routes = {};
|
|
909
996
|
const schema2 = db._schema;
|
|
910
997
|
routes[`${prefix}me`] = { GET: async (args, ctx) => ({ userId: ctx?.getUser?.()?.id }) };
|
|
911
|
-
routes[`${prefix}radsTunnel`] = {
|
|
998
|
+
routes[`${prefix}radsTunnel`] = {
|
|
999
|
+
POST: radsTunnelSvc.getRadsTunnelHandler(db)
|
|
1000
|
+
};
|
|
912
1001
|
routes[`${prefix}uploadFile`] = { POST: getUploadFileHandler(db) };
|
|
913
1002
|
for (const key in schema2) {
|
|
914
1003
|
const entity = schema2[key];
|
|
@@ -941,25 +1030,6 @@ function getUploadFileHandler(db) {
|
|
|
941
1030
|
);
|
|
942
1031
|
};
|
|
943
1032
|
}
|
|
944
|
-
function getRadsTunnelHandler(db) {
|
|
945
|
-
return async function radsTunnelHandler(request, ctx) {
|
|
946
|
-
const { method, entity, args, uploadArgs } = request?.body || {};
|
|
947
|
-
if (method === "uploadFile") {
|
|
948
|
-
const blob = getBlobFromDataUrl(uploadArgs?.blobDataUrl);
|
|
949
|
-
if (!blob)
|
|
950
|
-
throw createError({ statusCode: 400, message: 'Malformed request - "blobDataUrl" is required' });
|
|
951
|
-
return db.uploadFile({ blob, ...uploadArgs }, ctx);
|
|
952
|
-
}
|
|
953
|
-
if (!method || !entity)
|
|
954
|
-
throw createError({ statusCode: 400, message: 'Malformed request - missing "method" or "entity"' });
|
|
955
|
-
const handle = db[_.lowerFirst(entity)];
|
|
956
|
-
if (!handle)
|
|
957
|
-
throw createError({ statusCode: 400, message: `Malformed request - entity "${entity}" not found` });
|
|
958
|
-
if (!handle[method])
|
|
959
|
-
throw createError({ statusCode: 400, message: `Unknown method - ${method}` });
|
|
960
|
-
return await handle[method](args, ctx);
|
|
961
|
-
};
|
|
962
|
-
}
|
|
963
1033
|
function getBlobFromDataUrl(dataUrl) {
|
|
964
1034
|
const [header, b64string] = dataUrl?.split(",");
|
|
965
1035
|
const [protocol, format] = header?.split(":");
|
package/package.json
CHANGED
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"require": "./integrations/*.cjs"
|
|
35
35
|
}
|
|
36
36
|
},
|
|
37
|
-
"version": "0.1.
|
|
37
|
+
"version": "0.1.64",
|
|
38
38
|
"description": "Say goodbye to boilerplate code and hello to efficient and elegant syntax.",
|
|
39
39
|
"keywords": [],
|
|
40
40
|
"author": "",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"peerDependencies": {
|
|
43
43
|
"@azure/cosmos": ">=3",
|
|
44
44
|
"@azure/storage-blob": ">=12",
|
|
45
|
-
"h3": "
|
|
45
|
+
"h3": ">=1.6.0",
|
|
46
46
|
"typescript": ">=5.0.0"
|
|
47
47
|
},
|
|
48
48
|
"peerDependenciesMeta": {
|
|
@@ -59,6 +59,7 @@
|
|
|
59
59
|
"packageManager": "pnpm@8.6.1",
|
|
60
60
|
"devDependencies": {
|
|
61
61
|
"@azure/cosmos": "^3.17.3",
|
|
62
|
+
"@types/klaw": "^3.0.3",
|
|
62
63
|
"@types/lodash": "4.14.191",
|
|
63
64
|
"@types/pluralize": "^0.0.29",
|
|
64
65
|
"@types/uuid": "^9.0.2",
|
|
@@ -77,6 +78,8 @@
|
|
|
77
78
|
"@fastify/deepmerge": "^1.3.0",
|
|
78
79
|
"@nuxt/kit": "^3.5.1",
|
|
79
80
|
"dataloader": "^2.2.2",
|
|
81
|
+
"ignore": "^5.2.4",
|
|
82
|
+
"klaw": "^4.1.0",
|
|
80
83
|
"lodash": "^4.17.21",
|
|
81
84
|
"pluralize": "^8.0.0",
|
|
82
85
|
"uuid": ">=8",
|