@wxn0brp/create-db-adapter 0.0.0-stage → 0.0.1
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/README.md +84 -2
- package/dist/bin.js +6 -0
- package/dist/cli/args.js +108 -0
- package/dist/cli/output.js +31 -0
- package/dist/cli/tui.js +84 -0
- package/dist/generate.js +31 -0
- package/dist/index.js +8 -0
- package/dist/naming.js +51 -0
- package/dist/options.js +34 -0
- package/dist/package-meta.js +46 -0
- package/dist/plan.js +36 -0
- package/dist/run.js +60 -0
- package/dist/template-engine.js +48 -0
- package/dist/types.js +1 -0
- package/dist/variants.js +40 -0
- package/package.json +39 -5
- package/templates/a/src/action.ts +99 -0
- package/templates/a/src/index.ts +20 -0
- package/templates/a/src/types.ts +3 -0
- package/templates/a/valthera-e2e/index.ts +18 -0
- package/templates/b/src/action.ts +139 -0
- package/templates/b/src/file/index.ts +91 -0
- package/templates/b/src/format.ts +13 -0
- package/templates/b/src/index.ts +22 -0
- package/templates/b/src/types.ts +3 -0
- package/templates/b/valthera-e2e/index.ts +18 -0
- package/templates/c/src/action.ts +91 -0
- package/templates/c/src/index.ts +21 -0
- package/templates/c/src/translate.ts +8 -0
- package/templates/c/src/types.ts +3 -0
- package/templates/c/valthera-e2e/index.ts +12 -0
- package/templates/common/.github/workflows/build.yml +46 -0
- package/templates/common/LICENSE +21 -0
- package/templates/common/README.md +33 -0
- package/templates/common/biome.json.tmpl +6 -0
- package/templates/common/package.json +49 -0
- package/templates/common/rusalka/build.ts +1 -0
- package/templates/common/src/version.ts +1 -0
- package/templates/common/suglite.json5 +6 -0
- package/templates/common/tsconfig.json.tmpl +27 -0
- package/templates/common/valthera-e2e/config.json +6 -0
- package/templates/common/valthera-e2e/tsconfig.json.tmpl +18 -0
- package/templates/d/src/action.ts +106 -0
- package/templates/d/src/index.ts +22 -0
- package/templates/d/src/types.ts +3 -0
- package/templates/d/valthera-e2e/config.json +9 -0
- package/templates/d/valthera-e2e/index.ts +12 -0
package/package.json
CHANGED
|
@@ -1,6 +1,40 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
"name": "@wxn0brp/create-db-adapter",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"main": "dist/index.js",
|
|
5
|
+
"description": "Scaffold generator for ValtheraDB storage and specialized adapters",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/wxn0brP/ValtheraDB-create-adapter.git"
|
|
9
|
+
},
|
|
10
|
+
"homepage": "https://github.com/wxn0brP/ValtheraDB-create-adapter",
|
|
11
|
+
"author": "wxn0brP",
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"type": "module",
|
|
14
|
+
"keywords": [
|
|
15
|
+
"valthera",
|
|
16
|
+
"valtheradb",
|
|
17
|
+
"vdb-adapter",
|
|
18
|
+
"scaffold",
|
|
19
|
+
"create"
|
|
20
|
+
],
|
|
21
|
+
"bin": {
|
|
22
|
+
"create-db-adapter": "./dist/bin.js"
|
|
23
|
+
},
|
|
24
|
+
"scripts": {
|
|
25
|
+
"build": "tsc && tsc-alias"
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@inquirer/prompts": "^8.8.1"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@types/bun": "*",
|
|
32
|
+
"@wxn0brp/biome": "*",
|
|
33
|
+
"tsc-alias": "^1",
|
|
34
|
+
"typescript": "^7"
|
|
35
|
+
},
|
|
36
|
+
"files": [
|
|
37
|
+
"dist",
|
|
38
|
+
"templates"
|
|
39
|
+
]
|
|
40
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { CustomAdapterBase } from "@wxn0brp/db-core/base/customAdapter";
|
|
2
|
+
import {
|
|
3
|
+
CustomFileCpu,
|
|
4
|
+
pathRepair,
|
|
5
|
+
} from "@wxn0brp/db-core/base/customFileCpu";
|
|
6
|
+
import { AdapterError, AdapterInitError } from "@wxn0brp/db-core/errors";
|
|
7
|
+
import type { Data } from "@wxn0brp/db-core/types/data";
|
|
8
|
+
import { mkdir, readdir, readFile, rm, writeFile } from "node:fs/promises";
|
|
9
|
+
import { join } from "node:path";
|
|
10
|
+
import type { ___pascal___Opts } from "./types";
|
|
11
|
+
import { version } from "./version";
|
|
12
|
+
|
|
13
|
+
function isMissingFile(err: unknown) {
|
|
14
|
+
return (err as { code?: string })?.code === "ENOENT";
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export class DbStorage___pascal___ extends CustomAdapterBase {
|
|
18
|
+
version = version;
|
|
19
|
+
|
|
20
|
+
constructor(public opts: ___pascal___Opts = {}) {
|
|
21
|
+
super();
|
|
22
|
+
this.fileCpu = new CustomFileCpu(
|
|
23
|
+
this.read.bind(this),
|
|
24
|
+
this.write.bind(this),
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
get folder() {
|
|
29
|
+
return this.opts.folder ?? "./___name___-data";
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async init() {
|
|
33
|
+
try {
|
|
34
|
+
await mkdir(this.folder, {
|
|
35
|
+
recursive: true,
|
|
36
|
+
});
|
|
37
|
+
} catch (err) {
|
|
38
|
+
throw new AdapterInitError(err, {
|
|
39
|
+
folder: this.folder,
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
_path(collection: string) {
|
|
45
|
+
return join(this.folder, `${pathRepair(collection)}.json`);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
async read(collection: string): Promise<Data[]> {
|
|
49
|
+
try {
|
|
50
|
+
const raw = await readFile(this._path(collection), "utf-8");
|
|
51
|
+
return JSON.parse(raw);
|
|
52
|
+
} catch (err) {
|
|
53
|
+
if (isMissingFile(err)) return [];
|
|
54
|
+
throw new AdapterError(err, {
|
|
55
|
+
collection,
|
|
56
|
+
path: this._path(collection),
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
async write(collection: string, data: Data[]): Promise<void> {
|
|
62
|
+
await writeFile(this._path(collection), JSON.stringify(data, null, 2));
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
async getCollections(): Promise<string[]> {
|
|
66
|
+
const entries = await readdir(this.folder, {
|
|
67
|
+
withFileTypes: true,
|
|
68
|
+
});
|
|
69
|
+
return entries
|
|
70
|
+
.filter(entry => entry.isFile() && entry.name.endsWith(".json"))
|
|
71
|
+
.map(entry => entry.name.slice(0, -".json".length));
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
async ensureCollection(collection: string): Promise<boolean> {
|
|
75
|
+
if (await this.issetCollection(collection)) return false;
|
|
76
|
+
await writeFile(this._path(collection), "[]");
|
|
77
|
+
return true;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
async issetCollection(collection: string): Promise<boolean> {
|
|
81
|
+
try {
|
|
82
|
+
await readFile(this._path(collection));
|
|
83
|
+
return true;
|
|
84
|
+
} catch (err) {
|
|
85
|
+
if (isMissingFile(err)) return false;
|
|
86
|
+
throw new AdapterError(err, {
|
|
87
|
+
collection,
|
|
88
|
+
path: this._path(collection),
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
async removeCollection(collection: string): Promise<boolean> {
|
|
94
|
+
await rm(this._path(collection), {
|
|
95
|
+
force: true,
|
|
96
|
+
});
|
|
97
|
+
return true;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ValtheraClass } from "@wxn0brp/db-core";
|
|
2
|
+
import { DbStorage___pascal___ } from "./action";
|
|
3
|
+
import type { ___pascal___Opts } from "./types";
|
|
4
|
+
|
|
5
|
+
export * from "./action";
|
|
6
|
+
export * from "./types";
|
|
7
|
+
|
|
8
|
+
export function create___pascal___Adapter(opts: ___pascal___Opts = {}) {
|
|
9
|
+
return new DbStorage___pascal___(opts);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function create___pascal___Valthera(opts: ___pascal___Opts = {}) {
|
|
13
|
+
return new ValtheraClass({
|
|
14
|
+
adapter: new DbStorage___pascal___(opts),
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export const DYNAMIC = {
|
|
19
|
+
def: create___pascal___Adapter,
|
|
20
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { rm } from "node:fs/promises";
|
|
2
|
+
import { DbStorage___pascal___ } from "../src/action";
|
|
3
|
+
|
|
4
|
+
const TEST_DIR = "/tmp/valthera-e2e-___name___-test";
|
|
5
|
+
|
|
6
|
+
export default async () => {
|
|
7
|
+
await rm(TEST_DIR, {
|
|
8
|
+
recursive: true,
|
|
9
|
+
force: true,
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
const actions = new DbStorage___pascal___({
|
|
13
|
+
folder: TEST_DIR,
|
|
14
|
+
});
|
|
15
|
+
await actions.init();
|
|
16
|
+
actions._inited = true;
|
|
17
|
+
return actions;
|
|
18
|
+
};
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { AdapterBase } from "@wxn0brp/db-core/base/adapter";
|
|
2
|
+
import { pathRepair } from "@wxn0brp/db-core/base/customFileCpu";
|
|
3
|
+
import { AdapterError, AdapterInitError } from "@wxn0brp/db-core/errors";
|
|
4
|
+
import { addId } from "@wxn0brp/db-core/helpers/addId";
|
|
5
|
+
import type { DataInternal } from "@wxn0brp/db-core/types/data";
|
|
6
|
+
import type { VQueryT } from "@wxn0brp/db-core/types/query";
|
|
7
|
+
import { findUtil } from "@wxn0brp/db-core/utils/findUtil";
|
|
8
|
+
import { access, mkdir, readdir, rm, writeFile } from "node:fs/promises";
|
|
9
|
+
import { join } from "node:path";
|
|
10
|
+
import { ___pascal___FileCpu } from "./file";
|
|
11
|
+
import type { ___pascal___Opts } from "./types";
|
|
12
|
+
import { version } from "./version";
|
|
13
|
+
|
|
14
|
+
export class DbStorage___pascal___ extends AdapterBase {
|
|
15
|
+
version = version;
|
|
16
|
+
fileCpu: ___pascal___FileCpu;
|
|
17
|
+
|
|
18
|
+
constructor(public opts: ___pascal___Opts = {}) {
|
|
19
|
+
super();
|
|
20
|
+
this.fileCpu = new ___pascal___FileCpu();
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
get folder() {
|
|
24
|
+
return this.opts.folder ?? "./___name___-data";
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
async init() {
|
|
28
|
+
try {
|
|
29
|
+
await mkdir(this.folder, {
|
|
30
|
+
recursive: true,
|
|
31
|
+
});
|
|
32
|
+
} catch (err) {
|
|
33
|
+
throw new AdapterInitError(err, {
|
|
34
|
+
folder: this.folder,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
_path(collection: string) {
|
|
40
|
+
return join(this.folder, `${pathRepair(collection)}.log`);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
async getCollections(): Promise<string[]> {
|
|
44
|
+
const entries = await readdir(this.folder, {
|
|
45
|
+
withFileTypes: true,
|
|
46
|
+
});
|
|
47
|
+
return entries
|
|
48
|
+
.filter(entry => entry.isFile() && entry.name.endsWith(".log"))
|
|
49
|
+
.map(entry => entry.name.slice(0, -".log".length));
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
async ensureCollection(collection: string): Promise<boolean> {
|
|
53
|
+
if (await this.issetCollection(collection)) return false;
|
|
54
|
+
await writeFile(this._path(collection), "");
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
async issetCollection(collection: string): Promise<boolean> {
|
|
59
|
+
try {
|
|
60
|
+
await access(this._path(collection));
|
|
61
|
+
return true;
|
|
62
|
+
} catch (err) {
|
|
63
|
+
if ((err as { code?: string })?.code === "ENOENT") return false;
|
|
64
|
+
throw new AdapterError(err, {
|
|
65
|
+
collection,
|
|
66
|
+
path: this._path(collection),
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
async removeCollection(collection: string): Promise<boolean> {
|
|
72
|
+
await rm(this._path(collection), {
|
|
73
|
+
force: true,
|
|
74
|
+
});
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
async add(config: VQueryT.Add): Promise<DataInternal> {
|
|
79
|
+
await this.ensureCollection(config.collection);
|
|
80
|
+
await addId(config, this);
|
|
81
|
+
await this.fileCpu.add(this._path(config.collection), config);
|
|
82
|
+
return config.data as DataInternal;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
async find(config: VQueryT.Find): Promise<DataInternal[]> {
|
|
86
|
+
await this.ensureCollection(config.collection);
|
|
87
|
+
const data = await findUtil(config, this.fileCpu, [
|
|
88
|
+
this._path(config.collection),
|
|
89
|
+
]);
|
|
90
|
+
return data ?? [];
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
async findOne(config: VQueryT.FindOne): Promise<DataInternal | null> {
|
|
94
|
+
await this.ensureCollection(config.collection);
|
|
95
|
+
const data = await this.fileCpu.findOne(
|
|
96
|
+
this._path(config.collection),
|
|
97
|
+
config,
|
|
98
|
+
);
|
|
99
|
+
return data || null;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
async update(config: VQueryT.Update): Promise<DataInternal[]> {
|
|
103
|
+
await this.ensureCollection(config.collection);
|
|
104
|
+
return await this.fileCpu.update(
|
|
105
|
+
this._path(config.collection),
|
|
106
|
+
config,
|
|
107
|
+
false,
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
async updateOne(config: VQueryT.Update): Promise<DataInternal | null> {
|
|
112
|
+
await this.ensureCollection(config.collection);
|
|
113
|
+
const res = await this.fileCpu.update(
|
|
114
|
+
this._path(config.collection),
|
|
115
|
+
config,
|
|
116
|
+
true,
|
|
117
|
+
);
|
|
118
|
+
return res.length ? res[0] : null;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
async remove(config: VQueryT.Remove): Promise<DataInternal[]> {
|
|
122
|
+
await this.ensureCollection(config.collection);
|
|
123
|
+
return await this.fileCpu.remove(
|
|
124
|
+
this._path(config.collection),
|
|
125
|
+
config,
|
|
126
|
+
false,
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
async removeOne(config: VQueryT.Remove): Promise<DataInternal | null> {
|
|
131
|
+
await this.ensureCollection(config.collection);
|
|
132
|
+
const res = await this.fileCpu.remove(
|
|
133
|
+
this._path(config.collection),
|
|
134
|
+
config,
|
|
135
|
+
true,
|
|
136
|
+
);
|
|
137
|
+
return res.length ? res[0] : null;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import type { Data, DataInternal } from "@wxn0brp/db-core/types/data";
|
|
2
|
+
import type { FileCpu } from "@wxn0brp/db-core/types/fileCpu";
|
|
3
|
+
import type { VQueryT } from "@wxn0brp/db-core/types/query";
|
|
4
|
+
import { matchObj, updateObj } from "@wxn0brp/db-core/utils/process";
|
|
5
|
+
import { updateFindObject } from "@wxn0brp/db-core/utils/projection";
|
|
6
|
+
import { readFile, writeFile } from "node:fs/promises";
|
|
7
|
+
import { parse, stringify } from "../format";
|
|
8
|
+
|
|
9
|
+
export class ___pascal___FileCpu implements FileCpu {
|
|
10
|
+
async read(path: string): Promise<Data[]> {
|
|
11
|
+
try {
|
|
12
|
+
return parse(await readFile(path, "utf-8"));
|
|
13
|
+
} catch (err) {
|
|
14
|
+
if ((err as { code?: string })?.code === "ENOENT") return [];
|
|
15
|
+
throw err;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
async write(path: string, data: Data[]): Promise<void> {
|
|
20
|
+
await writeFile(path, stringify(data));
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
async add(file: string, config: VQueryT.Add): Promise<void> {
|
|
24
|
+
const entries = await this.read(file);
|
|
25
|
+
entries.push(config.data as Data);
|
|
26
|
+
await this.write(file, entries);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
async find(file: string, config: VQueryT.Find): Promise<DataInternal[]> {
|
|
30
|
+
const entries = await this.read(file);
|
|
31
|
+
const result: DataInternal[] = [];
|
|
32
|
+
for (const entry of entries) {
|
|
33
|
+
if (matchObj(config, entry))
|
|
34
|
+
result.push(
|
|
35
|
+
updateFindObject(entry, config.findOpts ?? {}) as DataInternal,
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
return result;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async findOne(
|
|
42
|
+
file: string,
|
|
43
|
+
config: VQueryT.FindOne,
|
|
44
|
+
): Promise<DataInternal | false> {
|
|
45
|
+
const entries = await this.read(file);
|
|
46
|
+
for (const entry of entries) {
|
|
47
|
+
if (matchObj(config, entry))
|
|
48
|
+
return updateFindObject(entry, config.findOpts ?? {}) as DataInternal;
|
|
49
|
+
}
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
async remove(
|
|
54
|
+
file: string,
|
|
55
|
+
config: VQueryT.Remove,
|
|
56
|
+
one: boolean,
|
|
57
|
+
): Promise<DataInternal[]> {
|
|
58
|
+
const entries = await this.read(file);
|
|
59
|
+
const removed: DataInternal[] = [];
|
|
60
|
+
const kept = entries.filter(entry => {
|
|
61
|
+
if (removed.length && one) return true;
|
|
62
|
+
if (matchObj(config, entry)) {
|
|
63
|
+
removed.push(entry);
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
return true;
|
|
67
|
+
});
|
|
68
|
+
if (removed.length) await this.write(file, kept);
|
|
69
|
+
return removed;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
async update(
|
|
73
|
+
file: string,
|
|
74
|
+
config: VQueryT.Update,
|
|
75
|
+
one: boolean,
|
|
76
|
+
): Promise<DataInternal[]> {
|
|
77
|
+
const entries = await this.read(file);
|
|
78
|
+
const updated: DataInternal[] = [];
|
|
79
|
+
const next = entries.map(entry => {
|
|
80
|
+
if (updated.length && one) return entry;
|
|
81
|
+
if (matchObj(config, entry)) {
|
|
82
|
+
const result = updateObj(config, entry);
|
|
83
|
+
updated.push(result);
|
|
84
|
+
return result;
|
|
85
|
+
}
|
|
86
|
+
return entry;
|
|
87
|
+
});
|
|
88
|
+
if (updated.length) await this.write(file, next);
|
|
89
|
+
return updated;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Data } from "@wxn0brp/db-core/types/data";
|
|
2
|
+
|
|
3
|
+
export function stringify(data: Data[]): string {
|
|
4
|
+
return data.map(record => JSON.stringify(record)).join("\n");
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export function parse(raw: string): Data[] {
|
|
8
|
+
return raw
|
|
9
|
+
.split("\n")
|
|
10
|
+
.map(line => line.trim())
|
|
11
|
+
.filter(Boolean)
|
|
12
|
+
.map(line => JSON.parse(line));
|
|
13
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ValtheraClass } from "@wxn0brp/db-core";
|
|
2
|
+
import { DbStorage___pascal___ } from "./action";
|
|
3
|
+
import type { ___pascal___Opts } from "./types";
|
|
4
|
+
|
|
5
|
+
export * from "./action";
|
|
6
|
+
export * from "./file";
|
|
7
|
+
export * from "./format";
|
|
8
|
+
export * from "./types";
|
|
9
|
+
|
|
10
|
+
export function create___pascal___Adapter(opts: ___pascal___Opts = {}) {
|
|
11
|
+
return new DbStorage___pascal___(opts);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function create___pascal___Valthera(opts: ___pascal___Opts = {}) {
|
|
15
|
+
return new ValtheraClass({
|
|
16
|
+
adapter: new DbStorage___pascal___(opts),
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const DYNAMIC = {
|
|
21
|
+
def: create___pascal___Adapter,
|
|
22
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { rm } from "node:fs/promises";
|
|
2
|
+
import { DbStorage___pascal___ } from "../src/action";
|
|
3
|
+
|
|
4
|
+
const TEST_DIR = "/tmp/valthera-e2e-___name___-test";
|
|
5
|
+
|
|
6
|
+
export default async () => {
|
|
7
|
+
await rm(TEST_DIR, {
|
|
8
|
+
recursive: true,
|
|
9
|
+
force: true,
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
const actions = new DbStorage___pascal___({
|
|
13
|
+
folder: TEST_DIR,
|
|
14
|
+
});
|
|
15
|
+
await actions.init();
|
|
16
|
+
actions._inited = true;
|
|
17
|
+
return actions;
|
|
18
|
+
};
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { AdapterBase } from "@wxn0brp/db-core/base/adapter";
|
|
2
|
+
import { UnsupportedOperationError } from "@wxn0brp/db-core/errors";
|
|
3
|
+
import type { DataInternal } from "@wxn0brp/db-core/types/data";
|
|
4
|
+
import type { VQueryT } from "@wxn0brp/db-core/types/query";
|
|
5
|
+
import type { ___pascal___Opts } from "./types";
|
|
6
|
+
import { version } from "./version";
|
|
7
|
+
|
|
8
|
+
export class DbStorage___pascal___ extends AdapterBase {
|
|
9
|
+
version = version;
|
|
10
|
+
capabilities = {
|
|
11
|
+
transactions: false,
|
|
12
|
+
indexes: false,
|
|
13
|
+
persistent: true,
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
constructor(public opts: ___pascal___Opts = {}) {
|
|
17
|
+
super();
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
async init() {
|
|
21
|
+
// TODO: open the connection / prepare the backend.
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
async close() {
|
|
25
|
+
// TODO: release the connection.
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
async getCollections(): Promise<string[]> {
|
|
29
|
+
throw new UnsupportedOperationError("getCollections");
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async ensureCollection(collection: string): Promise<boolean> {
|
|
33
|
+
throw new UnsupportedOperationError("ensureCollection", {
|
|
34
|
+
collection,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async issetCollection(collection: string): Promise<boolean> {
|
|
39
|
+
throw new UnsupportedOperationError("issetCollection", {
|
|
40
|
+
collection,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
async removeCollection(collection: string): Promise<boolean> {
|
|
45
|
+
throw new UnsupportedOperationError("removeCollection", {
|
|
46
|
+
collection,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async add(config: VQueryT.Add): Promise<DataInternal> {
|
|
51
|
+
throw new UnsupportedOperationError("add", {
|
|
52
|
+
collection: config.collection,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
async find(config: VQueryT.Find): Promise<DataInternal[]> {
|
|
57
|
+
throw new UnsupportedOperationError("find", {
|
|
58
|
+
collection: config.collection,
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
async findOne(config: VQueryT.FindOne): Promise<DataInternal | null> {
|
|
63
|
+
throw new UnsupportedOperationError("findOne", {
|
|
64
|
+
collection: config.collection,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
async update(config: VQueryT.Update): Promise<DataInternal[]> {
|
|
69
|
+
throw new UnsupportedOperationError("update", {
|
|
70
|
+
collection: config.collection,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
async updateOne(config: VQueryT.Update): Promise<DataInternal | null> {
|
|
75
|
+
throw new UnsupportedOperationError("updateOne", {
|
|
76
|
+
collection: config.collection,
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
async remove(config: VQueryT.Remove): Promise<DataInternal[]> {
|
|
81
|
+
throw new UnsupportedOperationError("remove", {
|
|
82
|
+
collection: config.collection,
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
async removeOne(config: VQueryT.Remove): Promise<DataInternal | null> {
|
|
87
|
+
throw new UnsupportedOperationError("removeOne", {
|
|
88
|
+
collection: config.collection,
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ValtheraClass } from "@wxn0brp/db-core";
|
|
2
|
+
import { DbStorage___pascal___ } from "./action";
|
|
3
|
+
import type { ___pascal___Opts } from "./types";
|
|
4
|
+
|
|
5
|
+
export * from "./action";
|
|
6
|
+
export * from "./translate";
|
|
7
|
+
export * from "./types";
|
|
8
|
+
|
|
9
|
+
export function create___pascal___Adapter(opts: ___pascal___Opts = {}) {
|
|
10
|
+
return new DbStorage___pascal___(opts);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function create___pascal___Valthera(opts: ___pascal___Opts = {}) {
|
|
14
|
+
return new ValtheraClass({
|
|
15
|
+
adapter: new DbStorage___pascal___(opts),
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export const DYNAMIC = {
|
|
20
|
+
def: create___pascal___Adapter,
|
|
21
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { VQueryT } from "@wxn0brp/db-core/types/query";
|
|
2
|
+
|
|
3
|
+
export function buildWhere(
|
|
4
|
+
config: VQueryT.Find | VQueryT.Update | VQueryT.Remove,
|
|
5
|
+
): unknown {
|
|
6
|
+
// TODO: map config.search operators ($gt, $in, $regex, ...) to the backend.
|
|
7
|
+
return config.search;
|
|
8
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { DbStorage___pascal___ } from "../src/action";
|
|
2
|
+
|
|
3
|
+
const URI = process.env["VDB___pascal___URI"] ?? "";
|
|
4
|
+
|
|
5
|
+
export default async () => {
|
|
6
|
+
const actions = new DbStorage___pascal___({
|
|
7
|
+
uri: URI,
|
|
8
|
+
});
|
|
9
|
+
await actions.init();
|
|
10
|
+
actions._inited = true;
|
|
11
|
+
return actions;
|
|
12
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
name: Build
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches:
|
|
6
|
+
- master
|
|
7
|
+
tags:
|
|
8
|
+
- "*"
|
|
9
|
+
|
|
10
|
+
workflow_dispatch:
|
|
11
|
+
|
|
12
|
+
concurrency:
|
|
13
|
+
group: build
|
|
14
|
+
cancel-in-progress: true
|
|
15
|
+
|
|
16
|
+
jobs:
|
|
17
|
+
test:
|
|
18
|
+
runs-on: ubuntu-latest
|
|
19
|
+
|
|
20
|
+
steps:
|
|
21
|
+
- name: Checkout code
|
|
22
|
+
uses: actions/checkout@v7
|
|
23
|
+
|
|
24
|
+
- uses: oven-sh/setup-bun@v2
|
|
25
|
+
with:
|
|
26
|
+
bun-version: latest
|
|
27
|
+
|
|
28
|
+
- name: Install dependencies
|
|
29
|
+
run: bun install
|
|
30
|
+
|
|
31
|
+
- name: Run unit tests
|
|
32
|
+
run: bun test
|
|
33
|
+
|
|
34
|
+
- name: Run E2E tests
|
|
35
|
+
uses: wxn0brP/valtheraDB-e2e@master
|
|
36
|
+
|
|
37
|
+
deploy:
|
|
38
|
+
runs-on: ubuntu-latest
|
|
39
|
+
needs: test
|
|
40
|
+
permissions:
|
|
41
|
+
contents: write
|
|
42
|
+
id-token: write
|
|
43
|
+
steps:
|
|
44
|
+
- uses: wxn0brP/rusalka@master
|
|
45
|
+
with:
|
|
46
|
+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) ___year___ ___author___
|
|
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.
|