@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.
Files changed (47) hide show
  1. package/README.md +84 -2
  2. package/dist/bin.js +6 -0
  3. package/dist/cli/args.js +108 -0
  4. package/dist/cli/output.js +31 -0
  5. package/dist/cli/tui.js +84 -0
  6. package/dist/generate.js +31 -0
  7. package/dist/index.js +8 -0
  8. package/dist/naming.js +51 -0
  9. package/dist/options.js +34 -0
  10. package/dist/package-meta.js +46 -0
  11. package/dist/plan.js +36 -0
  12. package/dist/run.js +60 -0
  13. package/dist/template-engine.js +48 -0
  14. package/dist/types.js +1 -0
  15. package/dist/variants.js +40 -0
  16. package/package.json +39 -5
  17. package/templates/a/src/action.ts +99 -0
  18. package/templates/a/src/index.ts +20 -0
  19. package/templates/a/src/types.ts +3 -0
  20. package/templates/a/valthera-e2e/index.ts +18 -0
  21. package/templates/b/src/action.ts +139 -0
  22. package/templates/b/src/file/index.ts +91 -0
  23. package/templates/b/src/format.ts +13 -0
  24. package/templates/b/src/index.ts +22 -0
  25. package/templates/b/src/types.ts +3 -0
  26. package/templates/b/valthera-e2e/index.ts +18 -0
  27. package/templates/c/src/action.ts +91 -0
  28. package/templates/c/src/index.ts +21 -0
  29. package/templates/c/src/translate.ts +8 -0
  30. package/templates/c/src/types.ts +3 -0
  31. package/templates/c/valthera-e2e/index.ts +12 -0
  32. package/templates/common/.github/workflows/build.yml +46 -0
  33. package/templates/common/LICENSE +21 -0
  34. package/templates/common/README.md +33 -0
  35. package/templates/common/biome.json.tmpl +6 -0
  36. package/templates/common/package.json +49 -0
  37. package/templates/common/rusalka/build.ts +1 -0
  38. package/templates/common/src/version.ts +1 -0
  39. package/templates/common/suglite.json5 +6 -0
  40. package/templates/common/tsconfig.json.tmpl +27 -0
  41. package/templates/common/valthera-e2e/config.json +6 -0
  42. package/templates/common/valthera-e2e/tsconfig.json.tmpl +18 -0
  43. package/templates/d/src/action.ts +106 -0
  44. package/templates/d/src/index.ts +22 -0
  45. package/templates/d/src/types.ts +3 -0
  46. package/templates/d/valthera-e2e/config.json +9 -0
  47. package/templates/d/valthera-e2e/index.ts +12 -0
@@ -0,0 +1,33 @@
1
+ # ___package___
2
+
3
+ ___description___
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ bun add ___package___
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```typescript
14
+ import { ___factory___ } from "___package___";
15
+ import { ValtheraClass } from "@wxn0brp/db-core";
16
+
17
+ const adapter = ___factory___();
18
+ const db = new ValtheraClass({ adapter });
19
+ ```
20
+
21
+ ## Development
22
+
23
+ ```bash
24
+ bun install
25
+ bun run build
26
+ valthera-e2e
27
+ ```
28
+
29
+ See the [adapter guide](https://github.com/wxn0brP/ValtheraDB/blob/master/valthera/docs/dev/adapter.md) for the contract details.
30
+
31
+ ## License
32
+
33
+ MIT
@@ -0,0 +1,6 @@
1
+ {
2
+ "$schema": "https://biomejs.dev/schemas/2.5.15/schema.json",
3
+ "extends": [
4
+ "@wxn0brp/biome"
5
+ ]
6
+ }
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "___package___",
3
+ "version": "___version___",
4
+ "main": "dist/index.js",
5
+ "types": "dist/index.d.ts",
6
+ "description": "___description___",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "___repo___"
10
+ },
11
+ "homepage": "___homepage___",
12
+ "author": "___author___",
13
+ "license": "MIT",
14
+ "type": "module",
15
+ "keywords": [
16
+ "valthera",
17
+ "valtheradb",
18
+ "___keyword___",
19
+ "___name___"
20
+ ],
21
+ "scripts": {
22
+ "build": "tsc && tsc-alias"
23
+ },
24
+ "peerDependencies": {
25
+ "@wxn0brp/db-core": "___core___"
26
+ },
27
+ "devDependencies": {
28
+ "@types/bun": "*",
29
+ "@wxn0brp/biome": "*",
30
+ "@wxn0brp/db-core": "___core___",
31
+ "tsc-alias": "^1",
32
+ "typescript": "^7"
33
+ },
34
+ "files": [
35
+ "dist"
36
+ ],
37
+ "exports": {
38
+ ".": {
39
+ "types": "./dist/index.d.ts",
40
+ "import": "./dist/index.js",
41
+ "default": "./dist/index.js"
42
+ },
43
+ "./*": {
44
+ "types": "./dist/*.d.ts",
45
+ "import": "./dist/*.js",
46
+ "default": "./dist/*.js"
47
+ }
48
+ }
49
+ }
@@ -0,0 +1 @@
1
+ export const publishToNpm = true;
@@ -0,0 +1 @@
1
+ export const version = "0.0.1";
@@ -0,0 +1,6 @@
1
+ {
2
+ cmd: "tsc --noEmit",
3
+ watch: [
4
+ "src"
5
+ ]
6
+ }
@@ -0,0 +1,27 @@
1
+ {
2
+ "compilerOptions": {
3
+ "module": "ES2022",
4
+ "target": "ES2022",
5
+ "moduleResolution": "bundler",
6
+ "paths": {},
7
+ "esModuleInterop": true,
8
+ "skipLibCheck": true,
9
+ "outDir": "./dist",
10
+ "declaration": true,
11
+ "strict": false,
12
+ "rootDir": "./src",
13
+ "types": [
14
+ "bun-types"
15
+ ]
16
+ },
17
+ "include": [
18
+ "./src"
19
+ ],
20
+ "exclude": [
21
+ "node_modules"
22
+ ],
23
+ "tsc-alias": {
24
+ "resolveFullPaths": true,
25
+ "verbose": false
26
+ }
27
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "skip": {
3
+ "domains": [],
4
+ "tests": []
5
+ }
6
+ }
@@ -0,0 +1,18 @@
1
+ {
2
+ "compilerOptions": {
3
+ "module": "ES2022",
4
+ "target": "ES2022",
5
+ "moduleResolution": "bundler",
6
+ "esModuleInterop": true,
7
+ "skipLibCheck": true,
8
+ "strict": false,
9
+ "rootDir": "..",
10
+ "types": [
11
+ "bun-types"
12
+ ]
13
+ },
14
+ "include": [
15
+ ".",
16
+ "../src"
17
+ ]
18
+ }
@@ -0,0 +1,106 @@
1
+ import { AdapterBase } from "@wxn0brp/db-core/base/adapter";
2
+ import { addId } from "@wxn0brp/db-core/helpers/addId";
3
+ import type { Data, DataInternal } from "@wxn0brp/db-core/types/data";
4
+ import type { VQueryT } from "@wxn0brp/db-core/types/query";
5
+ import { findUtil } from "@wxn0brp/db-core/utils/findUtil";
6
+ import { matchObj, updateObj } from "@wxn0brp/db-core/utils/process";
7
+ import { updateFindObject } from "@wxn0brp/db-core/utils/projection";
8
+ import type { ___pascal___Opts } from "./types";
9
+ import { version } from "./version";
10
+
11
+ export class DbSpec___pascal___ extends AdapterBase {
12
+ version = version;
13
+ capabilities = {
14
+ transactions: false,
15
+ indexes: false,
16
+ persistent: false,
17
+ };
18
+ _collections = new Map<string, Data[]>();
19
+
20
+ constructor(public opts: ___pascal___Opts = {}) {
21
+ super();
22
+ }
23
+
24
+ async getCollections(): Promise<string[]> {
25
+ return [ ...this._collections.keys() ];
26
+ }
27
+
28
+ async ensureCollection(collection: string): Promise<boolean> {
29
+ if (this._collections.has(collection)) return false;
30
+ this._collections.set(collection, []);
31
+ return true;
32
+ }
33
+
34
+ async issetCollection(collection: string): Promise<boolean> {
35
+ return this._collections.has(collection);
36
+ }
37
+
38
+ async removeCollection(collection: string): Promise<boolean> {
39
+ return this._collections.delete(collection);
40
+ }
41
+
42
+ async add(config: VQueryT.Add): Promise<DataInternal> {
43
+ await this.ensureCollection(config.collection);
44
+ await addId(config, this);
45
+ this._collections.get(config.collection)!.push(config.data as Data);
46
+ return config.data as DataInternal;
47
+ }
48
+
49
+ async find(config: VQueryT.Find): Promise<DataInternal[]> {
50
+ const entries = this._collections.get(config.collection) ?? [];
51
+ const matched: Data[] = [];
52
+ for (const entry of entries) {
53
+ if (matchObj(config, entry))
54
+ matched.push(updateFindObject(entry, config.findOpts ?? {}) as Data);
55
+ }
56
+ return findUtil(config, matched, []) as Promise<DataInternal[]>;
57
+ }
58
+
59
+ async findOne(config: VQueryT.FindOne): Promise<DataInternal | null> {
60
+ const entries = this._collections.get(config.collection) ?? [];
61
+ for (const entry of entries) {
62
+ if (matchObj(config, entry))
63
+ return updateFindObject(entry, config.findOpts ?? {}) as DataInternal;
64
+ }
65
+ return null;
66
+ }
67
+
68
+ async remove(config: VQueryT.Remove): Promise<DataInternal[]> {
69
+ const entries = this._collections.get(config.collection) ?? [];
70
+ const removed: DataInternal[] = [];
71
+ const kept = entries.filter(entry => {
72
+ if (matchObj(config, entry)) {
73
+ removed.push(entry);
74
+ return false;
75
+ }
76
+ return true;
77
+ });
78
+ this._collections.set(config.collection, kept);
79
+ return removed;
80
+ }
81
+
82
+ async removeOne(config: VQueryT.Remove): Promise<DataInternal | null> {
83
+ const entries = this._collections.get(config.collection) ?? [];
84
+ const index = entries.findIndex(entry => matchObj(config, entry));
85
+ if (index === -1) return null;
86
+ const [ removed ] = entries.splice(index, 1);
87
+ return removed as DataInternal;
88
+ }
89
+
90
+ async update(config: VQueryT.Update): Promise<DataInternal[]> {
91
+ const entries = this._collections.get(config.collection) ?? [];
92
+ const updated: DataInternal[] = [];
93
+ for (const entry of entries) {
94
+ if (matchObj(config, entry)) updated.push(updateObj(config, entry));
95
+ }
96
+ return updated;
97
+ }
98
+
99
+ async updateOne(config: VQueryT.Update): Promise<DataInternal | null> {
100
+ const entries = this._collections.get(config.collection) ?? [];
101
+ for (const entry of entries) {
102
+ if (matchObj(config, entry)) return updateObj(config, entry);
103
+ }
104
+ return null;
105
+ }
106
+ }
@@ -0,0 +1,22 @@
1
+ import { forgeTypedValthera, ValtheraClass } from "@wxn0brp/db-core";
2
+ import { DbSpec___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 DbSpec___pascal___(opts);
10
+ }
11
+
12
+ export function create___pascal___Valthera(opts: ___pascal___Opts = {}) {
13
+ return forgeTypedValthera(
14
+ new ValtheraClass({
15
+ adapter: new DbSpec___pascal___(opts),
16
+ }),
17
+ );
18
+ }
19
+
20
+ export const DYNAMIC = {
21
+ def: create___pascal___Adapter,
22
+ };
@@ -0,0 +1,3 @@
1
+ export interface ___pascal___Opts {
2
+ path?: string;
3
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "skip": {
3
+ "domains": [
4
+ "find-options",
5
+ "transaction"
6
+ ],
7
+ "tests": []
8
+ }
9
+ }
@@ -0,0 +1,12 @@
1
+ import { DbSpec___pascal___ } from "../src/action";
2
+
3
+ const TEST_DIR = "/tmp/valthera-e2e-___name___-test";
4
+
5
+ export default async () => {
6
+ const actions = new DbSpec___pascal___({
7
+ path: TEST_DIR,
8
+ });
9
+ await actions.init();
10
+ actions._inited = true;
11
+ return actions;
12
+ };