@zmdb/cli 1.0.0-beta.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/LICENSE +674 -0
- package/README.md +19 -0
- package/dist/__fixtures__/http-client/src/contract.d.ts +38 -0
- package/dist/__fixtures__/http-client/src/contract.d.ts.map +1 -0
- package/dist/__fixtures__/http-client/src/contract.js +121 -0
- package/dist/__fixtures__/http-client/src/contract.js.map +1 -0
- package/dist/__fixtures__/http-client/src/models.d.ts +11 -0
- package/dist/__fixtures__/http-client/src/models.d.ts.map +1 -0
- package/dist/__fixtures__/http-client/src/models.js +2 -0
- package/dist/__fixtures__/http-client/src/models.js.map +1 -0
- package/dist/__fixtures__/http-client/src/schema.d.ts +4 -0
- package/dist/__fixtures__/http-client/src/schema.d.ts.map +1 -0
- package/dist/__fixtures__/http-client/src/schema.js +2 -0
- package/dist/__fixtures__/http-client/src/schema.js.map +1 -0
- package/dist/__fixtures__/http-client/src/unrelated.d.ts +2 -0
- package/dist/__fixtures__/http-client/src/unrelated.d.ts.map +1 -0
- package/dist/__fixtures__/http-client/src/unrelated.js +2 -0
- package/dist/__fixtures__/http-client/src/unrelated.js.map +1 -0
- package/dist/__fixtures__/http-client/zmdb.config.d.ts +16 -0
- package/dist/__fixtures__/http-client/zmdb.config.d.ts.map +1 -0
- package/dist/__fixtures__/http-client/zmdb.config.js +12 -0
- package/dist/__fixtures__/http-client/zmdb.config.js.map +1 -0
- package/dist/__fixtures__/project/src/schema.d.ts +6 -0
- package/dist/__fixtures__/project/src/schema.d.ts.map +1 -0
- package/dist/__fixtures__/project/src/schema.js +2 -0
- package/dist/__fixtures__/project/src/schema.js.map +1 -0
- package/dist/__fixtures__/project/zmdb.config.d.ts +22 -0
- package/dist/__fixtures__/project/zmdb.config.d.ts.map +1 -0
- package/dist/__fixtures__/project/zmdb.config.js +55 -0
- package/dist/__fixtures__/project/zmdb.config.js.map +1 -0
- package/dist/application-loader.d.ts +4 -0
- package/dist/application-loader.d.ts.map +1 -0
- package/dist/application-loader.js +102 -0
- package/dist/application-loader.js.map +1 -0
- package/dist/args.d.ts +23 -0
- package/dist/args.d.ts.map +1 -0
- package/dist/args.js +353 -0
- package/dist/args.js.map +1 -0
- package/dist/atomic.d.ts +13 -0
- package/dist/atomic.d.ts.map +1 -0
- package/dist/atomic.js +28 -0
- package/dist/atomic.js.map +1 -0
- package/dist/bin.d.ts +3 -0
- package/dist/bin.d.ts.map +1 -0
- package/dist/bin.js +4 -0
- package/dist/bin.js.map +1 -0
- package/dist/commands/check.d.ts +5 -0
- package/dist/commands/check.d.ts.map +1 -0
- package/dist/commands/check.js +7 -0
- package/dist/commands/check.js.map +1 -0
- package/dist/commands/client.d.ts +38 -0
- package/dist/commands/client.d.ts.map +1 -0
- package/dist/commands/client.js +347 -0
- package/dist/commands/client.js.map +1 -0
- package/dist/commands/codegen.d.ts +9 -0
- package/dist/commands/codegen.d.ts.map +1 -0
- package/dist/commands/codegen.js +56 -0
- package/dist/commands/codegen.js.map +1 -0
- package/dist/commands/embed.d.ts +8 -0
- package/dist/commands/embed.d.ts.map +1 -0
- package/dist/commands/embed.js +17 -0
- package/dist/commands/embed.js.map +1 -0
- package/dist/commands/export.d.ts +5 -0
- package/dist/commands/export.d.ts.map +1 -0
- package/dist/commands/export.js +6 -0
- package/dist/commands/export.js.map +1 -0
- package/dist/commands/generate.d.ts +5 -0
- package/dist/commands/generate.d.ts.map +1 -0
- package/dist/commands/generate.js +6 -0
- package/dist/commands/generate.js.map +1 -0
- package/dist/commands/migrate.d.ts +9 -0
- package/dist/commands/migrate.d.ts.map +1 -0
- package/dist/commands/migrate.js +18 -0
- package/dist/commands/migrate.js.map +1 -0
- package/dist/commands/new.d.ts +4 -0
- package/dist/commands/new.d.ts.map +1 -0
- package/dist/commands/new.js +35 -0
- package/dist/commands/new.js.map +1 -0
- package/dist/commands/pull.d.ts +5 -0
- package/dist/commands/pull.d.ts.map +1 -0
- package/dist/commands/pull.js +14 -0
- package/dist/commands/pull.js.map +1 -0
- package/dist/commands/push.d.ts +6 -0
- package/dist/commands/push.d.ts.map +1 -0
- package/dist/commands/push.js +11 -0
- package/dist/commands/push.js.map +1 -0
- package/dist/commands/studio.d.ts +31 -0
- package/dist/commands/studio.d.ts.map +1 -0
- package/dist/commands/studio.js +154 -0
- package/dist/commands/studio.js.map +1 -0
- package/dist/commands/upgrade.d.ts +5 -0
- package/dist/commands/upgrade.d.ts.map +1 -0
- package/dist/commands/upgrade.js +11 -0
- package/dist/commands/upgrade.js.map +1 -0
- package/dist/database.d.ts +4 -0
- package/dist/database.d.ts.map +1 -0
- package/dist/database.js +8 -0
- package/dist/database.js.map +1 -0
- package/dist/errors.d.ts +7 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +20 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +34 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +626 -0
- package/dist/index.js.map +1 -0
- package/dist/lifecycle.d.ts +6 -0
- package/dist/lifecycle.d.ts.map +1 -0
- package/dist/lifecycle.js +75 -0
- package/dist/lifecycle.js.map +1 -0
- package/dist/migration-project.d.ts +14 -0
- package/dist/migration-project.d.ts.map +1 -0
- package/dist/migration-project.js +74 -0
- package/dist/migration-project.js.map +1 -0
- package/dist/output.d.ts +27 -0
- package/dist/output.d.ts.map +1 -0
- package/dist/output.js +60 -0
- package/dist/output.js.map +1 -0
- package/dist/repl.d.ts +48 -0
- package/dist/repl.d.ts.map +1 -0
- package/dist/repl.js +265 -0
- package/dist/repl.js.map +1 -0
- package/dist/scaffold.d.ts +28 -0
- package/dist/scaffold.d.ts.map +1 -0
- package/dist/scaffold.js +414 -0
- package/dist/scaffold.js.map +1 -0
- package/dist/studio/index.d.ts +20 -0
- package/dist/studio/index.d.ts.map +1 -0
- package/dist/studio/index.js +607 -0
- package/dist/studio/index.js.map +1 -0
- package/dist/templates/command.d.ts +3 -0
- package/dist/templates/command.d.ts.map +1 -0
- package/dist/templates/command.js +65 -0
- package/dist/templates/command.js.map +1 -0
- package/dist/templates/controller.d.ts +3 -0
- package/dist/templates/controller.d.ts.map +1 -0
- package/dist/templates/controller.js +41 -0
- package/dist/templates/controller.js.map +1 -0
- package/dist/templates/index.d.ts +4 -0
- package/dist/templates/index.d.ts.map +1 -0
- package/dist/templates/index.js +18 -0
- package/dist/templates/index.js.map +1 -0
- package/dist/templates/module.d.ts +3 -0
- package/dist/templates/module.d.ts.map +1 -0
- package/dist/templates/module.js +41 -0
- package/dist/templates/module.js.map +1 -0
- package/dist/templates/project.d.ts +3 -0
- package/dist/templates/project.d.ts.map +1 -0
- package/dist/templates/project.js +280 -0
- package/dist/templates/project.js.map +1 -0
- package/dist/templates/repository.d.ts +3 -0
- package/dist/templates/repository.d.ts.map +1 -0
- package/dist/templates/repository.js +66 -0
- package/dist/templates/repository.js.map +1 -0
- package/dist/templates/schema.d.ts +3 -0
- package/dist/templates/schema.d.ts.map +1 -0
- package/dist/templates/schema.js +36 -0
- package/dist/templates/schema.js.map +1 -0
- package/dist/templates/types.d.ts +25 -0
- package/dist/templates/types.d.ts.map +1 -0
- package/dist/templates/types.js +17 -0
- package/dist/templates/types.js.map +1 -0
- package/package.json +72 -0
- package/src/__fixtures__/http-client/package.json +5 -0
- package/src/__fixtures__/http-client/src/contract.ts +85 -0
- package/src/__fixtures__/http-client/src/models.ts +12 -0
- package/src/__fixtures__/http-client/src/schema.ts +3 -0
- package/src/__fixtures__/http-client/src/unrelated.ts +1 -0
- package/src/__fixtures__/http-client/tsconfig.json +17 -0
- package/src/__fixtures__/http-client/zmdb.config.ts +12 -0
- package/src/__fixtures__/project/package.json +5 -0
- package/src/__fixtures__/project/src/schema.ts +6 -0
- package/src/__fixtures__/project/tsconfig.json +24 -0
- package/src/__fixtures__/project/zmdb.config.ts +57 -0
- package/src/application-loader.ts +108 -0
- package/src/args.ts +391 -0
- package/src/atomic.ts +43 -0
- package/src/bin.ts +5 -0
- package/src/commands/check.ts +11 -0
- package/src/commands/client.ts +415 -0
- package/src/commands/codegen.ts +73 -0
- package/src/commands/embed.ts +36 -0
- package/src/commands/export.ts +10 -0
- package/src/commands/generate.ts +14 -0
- package/src/commands/migrate.ts +38 -0
- package/src/commands/new.ts +48 -0
- package/src/commands/pull.ts +32 -0
- package/src/commands/push.ts +21 -0
- package/src/commands/studio.ts +200 -0
- package/src/commands/upgrade.ts +14 -0
- package/src/database.ts +9 -0
- package/src/errors.ts +19 -0
- package/src/index.ts +710 -0
- package/src/lifecycle.ts +73 -0
- package/src/migration-project.ts +91 -0
- package/src/output.ts +77 -0
- package/src/repl.ts +328 -0
- package/src/scaffold.ts +485 -0
- package/src/studio/index.ts +674 -0
- package/src/templates/command.ts +66 -0
- package/src/templates/controller.ts +42 -0
- package/src/templates/index.ts +29 -0
- package/src/templates/module.ts +42 -0
- package/src/templates/project.ts +281 -0
- package/src/templates/repository.ts +67 -0
- package/src/templates/schema.ts +37 -0
- package/src/templates/types.ts +46 -0
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
export const commandTemplate = ({ name }) => ({
|
|
2
|
+
files: [
|
|
3
|
+
{
|
|
4
|
+
path: `src/${name.fileStem}.command.ts`,
|
|
5
|
+
source: `import { assert } from 'zmdb';
|
|
6
|
+
import { Command } from '@zmdb/app/commands';
|
|
7
|
+
|
|
8
|
+
export interface ${name.pascal}Args {
|
|
9
|
+
readonly dryRun?: boolean;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export let ${name.camel}Runs = 0;
|
|
13
|
+
|
|
14
|
+
@Command<${name.pascal}Args>({
|
|
15
|
+
name: '${name.fileStem}',
|
|
16
|
+
description: 'Run the ${name.fileStem} command',
|
|
17
|
+
args: {
|
|
18
|
+
type: 'object',
|
|
19
|
+
properties: {
|
|
20
|
+
dryRun: { type: 'boolean' },
|
|
21
|
+
},
|
|
22
|
+
required: [],
|
|
23
|
+
},
|
|
24
|
+
validate: raw => assert<${name.pascal}Args>(raw),
|
|
25
|
+
})
|
|
26
|
+
export class ${name.pascal}Command {
|
|
27
|
+
run(_args: ${name.pascal}Args): number {
|
|
28
|
+
${name.camel}Runs += 1;
|
|
29
|
+
return 0;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
`,
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
path: `src/${name.fileStem}.command.spec.ts`,
|
|
36
|
+
source: `import { createCommandApp } from '@zmdb/app/commands';
|
|
37
|
+
import { createTestApp } from 'zmdb/testing';
|
|
38
|
+
import { Module } from 'zmdb';
|
|
39
|
+
import { describe, expect, it } from 'vitest';
|
|
40
|
+
|
|
41
|
+
import {
|
|
42
|
+
${name.pascal}Command,
|
|
43
|
+
${name.camel}Runs,
|
|
44
|
+
} from './${name.fileStem}.command.js';
|
|
45
|
+
|
|
46
|
+
@Module({ commands: [${name.pascal}Command] })
|
|
47
|
+
class ${name.pascal}CommandTestModule {}
|
|
48
|
+
|
|
49
|
+
describe('${name.pascal}Command', () => {
|
|
50
|
+
it('runs through the command application', async () => {
|
|
51
|
+
await using testApp = createTestApp(${name.pascal}CommandTestModule);
|
|
52
|
+
await testApp.init();
|
|
53
|
+
|
|
54
|
+
await using commandApp = createCommandApp(${name.pascal}CommandTestModule);
|
|
55
|
+
await commandApp.init();
|
|
56
|
+
expect(await commandApp.run(['${name.fileStem}', '--dry-run'])).toBe(0);
|
|
57
|
+
expect(${name.camel}Runs).toBe(1);
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
`,
|
|
61
|
+
},
|
|
62
|
+
],
|
|
63
|
+
instructions: [`add to src/app.module.ts, in @Module({ commands: [ … ] }):\n ${name.pascal}Command,`],
|
|
64
|
+
});
|
|
65
|
+
//# sourceMappingURL=command.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"command.js","sourceRoot":"","sources":["../../src/templates/command.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,eAAe,GAAoB,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC;IAC7D,KAAK,EAAE;QACL;YACE,IAAI,EAAE,OAAO,IAAI,CAAC,QAAQ,aAAa;YACvC,MAAM,EAAE;;;mBAGK,IAAI,CAAC,MAAM;;;;aAIjB,IAAI,CAAC,KAAK;;WAEZ,IAAI,CAAC,MAAM;WACX,IAAI,CAAC,QAAQ;0BACE,IAAI,CAAC,QAAQ;;;;;;;;4BAQX,IAAI,CAAC,MAAM;;eAExB,IAAI,CAAC,MAAM;eACX,IAAI,CAAC,MAAM;MACpB,IAAI,CAAC,KAAK;;;;CAIf;SACI;QACD;YACE,IAAI,EAAE,OAAO,IAAI,CAAC,QAAQ,kBAAkB;YAC5C,MAAM,EAAE;;;;;;IAMV,IAAI,CAAC,MAAM;IACX,IAAI,CAAC,KAAK;YACF,IAAI,CAAC,QAAQ;;uBAEF,IAAI,CAAC,MAAM;QAC1B,IAAI,CAAC,MAAM;;YAEP,IAAI,CAAC,MAAM;;0CAEmB,IAAI,CAAC,MAAM;;;gDAGL,IAAI,CAAC,MAAM;;oCAEvB,IAAI,CAAC,QAAQ;aACpC,IAAI,CAAC,KAAK;;;CAGtB;SACI;KACF;IACD,YAAY,EAAE,CAAC,iEAAiE,IAAI,CAAC,MAAM,UAAU,CAAC;CACvG,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"controller.d.ts","sourceRoot":"","sources":["../../src/templates/controller.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAElD,eAAO,MAAM,kBAAkB,EAAE,eAuC/B,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export const controllerTemplate = ({ name }) => ({
|
|
2
|
+
files: [
|
|
3
|
+
{
|
|
4
|
+
path: `src/${name.fileStem}.controller.ts`,
|
|
5
|
+
source: `import { Controller, Get } from 'zmdb';
|
|
6
|
+
|
|
7
|
+
@Controller('/${name.fileStem}')
|
|
8
|
+
export class ${name.pascal}Controller {
|
|
9
|
+
@Get()
|
|
10
|
+
list(): { readonly resource: string; readonly items: readonly unknown[] } {
|
|
11
|
+
return { resource: '${name.fileStem}', items: [] };
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
`,
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
path: `src/${name.fileStem}.controller.spec.ts`,
|
|
18
|
+
source: `import { Module } from 'zmdb';
|
|
19
|
+
import { createTestApp } from 'zmdb/testing';
|
|
20
|
+
import { bodyText } from 'zmdb/web';
|
|
21
|
+
import { describe, expect, it } from 'vitest';
|
|
22
|
+
|
|
23
|
+
import { ${name.pascal}Controller } from './${name.fileStem}.controller.js';
|
|
24
|
+
|
|
25
|
+
@Module({ controllers: [${name.pascal}Controller] })
|
|
26
|
+
class ${name.pascal}ControllerTestModule {}
|
|
27
|
+
|
|
28
|
+
describe('${name.pascal}Controller', () => {
|
|
29
|
+
it('serves its collection route', async () => {
|
|
30
|
+
await using app = createTestApp(${name.pascal}ControllerTestModule);
|
|
31
|
+
const response = await app.request({ method: 'GET', path: '/${name.fileStem}', headers: {} });
|
|
32
|
+
expect(response.status).toBe(200);
|
|
33
|
+
expect(JSON.parse(await bodyText(response))).toEqual({ resource: '${name.fileStem}', items: [] });
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
`,
|
|
37
|
+
},
|
|
38
|
+
],
|
|
39
|
+
instructions: [`add to src/app.module.ts, in @Module({ controllers: [ … ] }):\n ${name.pascal}Controller,`],
|
|
40
|
+
});
|
|
41
|
+
//# sourceMappingURL=controller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"controller.js","sourceRoot":"","sources":["../../src/templates/controller.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,kBAAkB,GAAoB,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC;IAChE,KAAK,EAAE;QACL;YACE,IAAI,EAAE,OAAO,IAAI,CAAC,QAAQ,gBAAgB;YAC1C,MAAM,EAAE;;gBAEE,IAAI,CAAC,QAAQ;eACd,IAAI,CAAC,MAAM;;;0BAGA,IAAI,CAAC,QAAQ;;;CAGtC;SACI;QACD;YACE,IAAI,EAAE,OAAO,IAAI,CAAC,QAAQ,qBAAqB;YAC/C,MAAM,EAAE;;;;;WAKH,IAAI,CAAC,MAAM,wBAAwB,IAAI,CAAC,QAAQ;;0BAEjC,IAAI,CAAC,MAAM;QAC7B,IAAI,CAAC,MAAM;;YAEP,IAAI,CAAC,MAAM;;sCAEe,IAAI,CAAC,MAAM;kEACiB,IAAI,CAAC,QAAQ;;wEAEP,IAAI,CAAC,QAAQ;;;CAGpF;SACI;KACF;IACD,YAAY,EAAE,CAAC,oEAAoE,IAAI,CAAC,MAAM,aAAa,CAAC;CAC7G,CAAC,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ScaffoldKind, TemplateFactory } from './types.js';
|
|
2
|
+
export declare function templateFor(kind: ScaffoldKind): TemplateFactory;
|
|
3
|
+
export type { ScaffoldKind, ScaffoldName, TemplateContext, TemplateFactory, TemplateFile, TemplatePlan, } from './types.js';
|
|
4
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/templates/index.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAWhE,wBAAgB,WAAW,CAAC,IAAI,EAAE,YAAY,GAAG,eAAe,CAE/D;AAED,YAAY,EACV,YAAY,EACZ,YAAY,EACZ,eAAe,EACf,eAAe,EACf,YAAY,EACZ,YAAY,GACb,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { commandTemplate } from './command.js';
|
|
2
|
+
import { controllerTemplate } from './controller.js';
|
|
3
|
+
import { moduleTemplate } from './module.js';
|
|
4
|
+
import { projectTemplate } from './project.js';
|
|
5
|
+
import { repositoryTemplate } from './repository.js';
|
|
6
|
+
import { schemaTemplate } from './schema.js';
|
|
7
|
+
const TEMPLATES = {
|
|
8
|
+
command: commandTemplate,
|
|
9
|
+
controller: controllerTemplate,
|
|
10
|
+
module: moduleTemplate,
|
|
11
|
+
project: projectTemplate,
|
|
12
|
+
repository: repositoryTemplate,
|
|
13
|
+
schema: schemaTemplate,
|
|
14
|
+
};
|
|
15
|
+
export function templateFor(kind) {
|
|
16
|
+
return TEMPLATES[kind];
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/templates/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAG7C,MAAM,SAAS,GAAoD;IACjE,OAAO,EAAE,eAAe;IACxB,UAAU,EAAE,kBAAkB;IAC9B,MAAM,EAAE,cAAc;IACtB,OAAO,EAAE,eAAe;IACxB,UAAU,EAAE,kBAAkB;IAC9B,MAAM,EAAE,cAAc;CACvB,CAAC;AAEF,MAAM,UAAU,WAAW,CAAC,IAAkB;IAC5C,OAAO,SAAS,CAAC,IAAI,CAAC,CAAC;AACzB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../../src/templates/module.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAElD,eAAO,MAAM,cAAc,EAAE,eAuC3B,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export const moduleTemplate = ({ name }) => ({
|
|
2
|
+
files: [
|
|
3
|
+
{
|
|
4
|
+
path: `src/${name.fileStem}.module.ts`,
|
|
5
|
+
source: `import { Module } from 'zmdb';
|
|
6
|
+
import { createToken } from 'zmdb/web';
|
|
7
|
+
|
|
8
|
+
export interface ${name.pascal}Status {
|
|
9
|
+
readonly name: '${name.fileStem}';
|
|
10
|
+
readonly ready: true;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export const ${name.constant}_STATUS = createToken<${name.pascal}Status>('${name.pascal}Status');
|
|
14
|
+
|
|
15
|
+
@Module({
|
|
16
|
+
providers: [{ token: ${name.constant}_STATUS, useValue: { name: '${name.fileStem}', ready: true } }],
|
|
17
|
+
exports: [${name.constant}_STATUS],
|
|
18
|
+
})
|
|
19
|
+
export class ${name.pascal}Module {}
|
|
20
|
+
`,
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
path: `src/${name.fileStem}.module.spec.ts`,
|
|
24
|
+
source: `import { createTestApp } from 'zmdb/testing';
|
|
25
|
+
import { describe, expect, it } from 'vitest';
|
|
26
|
+
|
|
27
|
+
import { ${name.constant}_STATUS, ${name.pascal}Module } from './${name.fileStem}.module.js';
|
|
28
|
+
|
|
29
|
+
describe('${name.pascal}Module', () => {
|
|
30
|
+
it('registers its status provider', async () => {
|
|
31
|
+
await using app = createTestApp(${name.pascal}Module);
|
|
32
|
+
const status = app.get(${name.constant}_STATUS);
|
|
33
|
+
expect(status).toEqual({ name: '${name.fileStem}', ready: true });
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
`,
|
|
37
|
+
},
|
|
38
|
+
],
|
|
39
|
+
instructions: [`add to src/app.module.ts, in @Module({ imports: [ … ] }):\n ${name.pascal}Module,`],
|
|
40
|
+
});
|
|
41
|
+
//# sourceMappingURL=module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module.js","sourceRoot":"","sources":["../../src/templates/module.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,cAAc,GAAoB,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC;IAC5D,KAAK,EAAE;QACL;YACE,IAAI,EAAE,OAAO,IAAI,CAAC,QAAQ,YAAY;YACtC,MAAM,EAAE;;;mBAGK,IAAI,CAAC,MAAM;oBACV,IAAI,CAAC,QAAQ;;;;eAIlB,IAAI,CAAC,QAAQ,yBAAyB,IAAI,CAAC,MAAM,YAAY,IAAI,CAAC,MAAM;;;yBAG9D,IAAI,CAAC,QAAQ,+BAA+B,IAAI,CAAC,QAAQ;cACpE,IAAI,CAAC,QAAQ;;eAEZ,IAAI,CAAC,MAAM;CACzB;SACI;QACD;YACE,IAAI,EAAE,OAAO,IAAI,CAAC,QAAQ,iBAAiB;YAC3C,MAAM,EAAE;;;WAGH,IAAI,CAAC,QAAQ,YAAY,IAAI,CAAC,MAAM,oBAAoB,IAAI,CAAC,QAAQ;;YAEpE,IAAI,CAAC,MAAM;;sCAEe,IAAI,CAAC,MAAM;6BACpB,IAAI,CAAC,QAAQ;sCACJ,IAAI,CAAC,QAAQ;;;CAGlD;SACI;KACF;IACD,YAAY,EAAE,CAAC,gEAAgE,IAAI,CAAC,MAAM,SAAS,CAAC;CACrG,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"project.d.ts","sourceRoot":"","sources":["../../src/templates/project.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,KAAK,eAAe,EAAE,MAAM,YAAY,CAAC;AAElE,eAAO,MAAM,eAAe,EAAE,eAsR5B,CAAC"}
|
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
import { FORMAT_OPTIONS } from './types.js';
|
|
2
|
+
export const projectTemplate = ({ name, packageVersion }) => ({
|
|
3
|
+
files: [
|
|
4
|
+
{
|
|
5
|
+
path: 'package.json',
|
|
6
|
+
source: `${JSON.stringify({
|
|
7
|
+
name: name.fileStem,
|
|
8
|
+
private: true,
|
|
9
|
+
version: '0.1.0',
|
|
10
|
+
type: 'module',
|
|
11
|
+
scripts: {
|
|
12
|
+
build: 'node scripts/build.mjs app',
|
|
13
|
+
check: 'node scripts/build.mjs fmt-check && tsc --noEmit && oxlint . && node scripts/build.mjs test && vitest run --config vitest.config.ts',
|
|
14
|
+
fmt: 'node scripts/build.mjs fmt',
|
|
15
|
+
'fmt:check': 'node scripts/build.mjs fmt-check',
|
|
16
|
+
lint: 'oxlint .',
|
|
17
|
+
start: 'node dist/main.mjs',
|
|
18
|
+
test: 'node scripts/build.mjs test && vitest run --config vitest.config.ts',
|
|
19
|
+
typecheck: 'tsc --noEmit',
|
|
20
|
+
},
|
|
21
|
+
dependencies: {
|
|
22
|
+
'@zmdb/sqlite': packageVersion,
|
|
23
|
+
zmdb: packageVersion,
|
|
24
|
+
},
|
|
25
|
+
devDependencies: {
|
|
26
|
+
'@types/node': '26.4.1',
|
|
27
|
+
esbuild: '0.28.2',
|
|
28
|
+
oxfmt: '0.66.0',
|
|
29
|
+
oxlint: '1.81.0',
|
|
30
|
+
typescript: '7.0.2',
|
|
31
|
+
vitest: '5.0.0',
|
|
32
|
+
},
|
|
33
|
+
engines: {
|
|
34
|
+
node: '>=26',
|
|
35
|
+
},
|
|
36
|
+
})}\n`,
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
path: 'tsconfig.json',
|
|
40
|
+
source: `${JSON.stringify({
|
|
41
|
+
compilerOptions: {
|
|
42
|
+
allowImportingTsExtensions: false,
|
|
43
|
+
exactOptionalPropertyTypes: true,
|
|
44
|
+
isolatedModules: true,
|
|
45
|
+
lib: ['ESNext', 'DOM', 'DOM.Iterable'],
|
|
46
|
+
module: 'NodeNext',
|
|
47
|
+
moduleResolution: 'NodeNext',
|
|
48
|
+
noEmit: true,
|
|
49
|
+
noImplicitOverride: true,
|
|
50
|
+
noUncheckedIndexedAccess: true,
|
|
51
|
+
skipLibCheck: true,
|
|
52
|
+
strict: true,
|
|
53
|
+
target: 'ESNext',
|
|
54
|
+
types: ['node'],
|
|
55
|
+
verbatimModuleSyntax: true,
|
|
56
|
+
},
|
|
57
|
+
include: ['src/**/*.ts', 'vitest.config.ts', 'zmdb.config.ts'],
|
|
58
|
+
})}\n`,
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
path: 'scripts/build.mjs',
|
|
62
|
+
source: `import { glob, readFile, rm, writeFile } from 'node:fs/promises';
|
|
63
|
+
import { dirname, join } from 'node:path';
|
|
64
|
+
import { fileURLToPath } from 'node:url';
|
|
65
|
+
|
|
66
|
+
import { build } from 'esbuild';
|
|
67
|
+
import { format } from 'oxfmt';
|
|
68
|
+
import { zmdbAot } from 'zmdb/compiler';
|
|
69
|
+
|
|
70
|
+
const root = dirname(dirname(fileURLToPath(import.meta.url)));
|
|
71
|
+
const formatOptions = ${JSON.stringify(FORMAT_OPTIONS)};
|
|
72
|
+
|
|
73
|
+
async function formatProject(check) {
|
|
74
|
+
const paths = glob(['**/*.ts', '**/*.mjs', '**/*.json'], {
|
|
75
|
+
cwd: root,
|
|
76
|
+
exclude: ['**/node_modules/**', '**/dist/**', '**/generated-tests/**', '**/.cache/**', '**/package-lock.json', '**/npm-shrinkwrap.json'],
|
|
77
|
+
});
|
|
78
|
+
for await (const path of paths) {
|
|
79
|
+
const absolute = join(root, path);
|
|
80
|
+
const source = await readFile(absolute, 'utf8');
|
|
81
|
+
const result = await format(path, source, formatOptions);
|
|
82
|
+
if (result.errors.length > 0) throw new Error(JSON.stringify(result.errors));
|
|
83
|
+
if (result.code === source) continue;
|
|
84
|
+
if (check) {
|
|
85
|
+
process.stderr.write(path + '\\n');
|
|
86
|
+
process.exitCode = 1;
|
|
87
|
+
} else {
|
|
88
|
+
await writeFile(absolute, result.code);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
async function aotPlugin() {
|
|
94
|
+
const plugin = await zmdbAot({ cwd: root });
|
|
95
|
+
return {
|
|
96
|
+
name: plugin.name,
|
|
97
|
+
setup(esbuild) {
|
|
98
|
+
esbuild.onLoad({ filter: /\\.[cm]?tsx?$/ }, async ({ path }) => {
|
|
99
|
+
const code = await readFile(path, 'utf8');
|
|
100
|
+
const result = plugin.transform(code, path);
|
|
101
|
+
return { contents: result?.code ?? code, loader: path.endsWith('x') ? 'tsx' : 'ts' };
|
|
102
|
+
});
|
|
103
|
+
esbuild.onEnd(() => plugin.buildEnd?.());
|
|
104
|
+
},
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const common = {
|
|
109
|
+
bundle: true,
|
|
110
|
+
format: 'esm',
|
|
111
|
+
packages: 'external',
|
|
112
|
+
platform: 'node',
|
|
113
|
+
target: 'es2022',
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
const mode = process.argv[2];
|
|
117
|
+
if (mode === 'fmt' || mode === 'fmt-check') {
|
|
118
|
+
await formatProject(mode === 'fmt-check');
|
|
119
|
+
} else if (mode === 'app') {
|
|
120
|
+
await build({
|
|
121
|
+
...common,
|
|
122
|
+
entryPoints: [join(root, 'src', 'main.ts')],
|
|
123
|
+
outfile: join(root, 'dist', 'main.mjs'),
|
|
124
|
+
plugins: [await aotPlugin()],
|
|
125
|
+
});
|
|
126
|
+
} else if (mode === 'test') {
|
|
127
|
+
const entryPoints = [];
|
|
128
|
+
for await (const path of glob('src/**/*.spec.ts', { cwd: root })) {
|
|
129
|
+
entryPoints.push(join(root, path));
|
|
130
|
+
}
|
|
131
|
+
const outdir = join(root, 'generated-tests');
|
|
132
|
+
await rm(outdir, { recursive: true, force: true });
|
|
133
|
+
await build({
|
|
134
|
+
...common,
|
|
135
|
+
entryPoints,
|
|
136
|
+
outbase: join(root, 'src'),
|
|
137
|
+
outdir,
|
|
138
|
+
outExtension: { '.js': '.mjs' },
|
|
139
|
+
plugins: [await aotPlugin()],
|
|
140
|
+
});
|
|
141
|
+
} else {
|
|
142
|
+
throw new Error('usage: node scripts/build.mjs <app|test|fmt|fmt-check>');
|
|
143
|
+
}
|
|
144
|
+
`,
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
path: 'vitest.config.ts',
|
|
148
|
+
source: `import { defineConfig } from 'vitest/config';
|
|
149
|
+
|
|
150
|
+
export default defineConfig({
|
|
151
|
+
test: {
|
|
152
|
+
include: ['generated-tests/**/*.spec.mjs'],
|
|
153
|
+
},
|
|
154
|
+
});
|
|
155
|
+
`,
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
path: 'zmdb.config.ts',
|
|
159
|
+
source: `import { DatabaseSync } from 'node:sqlite';
|
|
160
|
+
import { fileURLToPath } from 'node:url';
|
|
161
|
+
|
|
162
|
+
import { defineConfig } from 'zmdb';
|
|
163
|
+
import { sqlite, sqliteDriver } from 'zmdb/sqlite';
|
|
164
|
+
|
|
165
|
+
const databasePath = fileURLToPath(new URL('./database.sqlite', import.meta.url));
|
|
166
|
+
|
|
167
|
+
export default defineConfig({
|
|
168
|
+
schema: ['src/**/*.ts'],
|
|
169
|
+
dialect: sqlite,
|
|
170
|
+
project: './tsconfig.json',
|
|
171
|
+
out: './migrations',
|
|
172
|
+
driver: () => sqliteDriver(new DatabaseSync(databasePath)),
|
|
173
|
+
});
|
|
174
|
+
`,
|
|
175
|
+
},
|
|
176
|
+
{
|
|
177
|
+
path: 'src/app.module.ts',
|
|
178
|
+
source: `import { Module } from 'zmdb';
|
|
179
|
+
|
|
180
|
+
import { HealthController } from './health.controller.js';
|
|
181
|
+
|
|
182
|
+
@Module({ controllers: [HealthController] })
|
|
183
|
+
export class AppModule {}
|
|
184
|
+
`,
|
|
185
|
+
},
|
|
186
|
+
{
|
|
187
|
+
path: 'src/main.ts',
|
|
188
|
+
source: `import { createServer } from 'node:http';
|
|
189
|
+
|
|
190
|
+
import { compileModule, createRouter, toNodeHandler } from 'zmdb/web';
|
|
191
|
+
|
|
192
|
+
import { AppModule } from './app.module.js';
|
|
193
|
+
|
|
194
|
+
const port = Number(process.env.PORT ?? '3000');
|
|
195
|
+
if (!Number.isInteger(port) || port < 0 || port > 65_535) {
|
|
196
|
+
throw new RangeError(\`PORT must be an integer from 0 through 65535, received \${String(process.env.PORT)}\`);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
const compiled = compileModule(AppModule);
|
|
200
|
+
const router = createRouter();
|
|
201
|
+
for (const controller of compiled.controllers) {
|
|
202
|
+
router.register(controller);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
const handle = toNodeHandler(router);
|
|
206
|
+
const server = createServer((request, response) => {
|
|
207
|
+
const method = request.method;
|
|
208
|
+
if (method === undefined) {
|
|
209
|
+
response.writeHead(400).end('request method is required');
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
handle(
|
|
213
|
+
{
|
|
214
|
+
method,
|
|
215
|
+
headers: request.headers,
|
|
216
|
+
...(request.url === undefined ? {} : { url: request.url }),
|
|
217
|
+
on(event, listener) {
|
|
218
|
+
request.on(event, listener);
|
|
219
|
+
},
|
|
220
|
+
setEncoding() {
|
|
221
|
+
request.setEncoding('utf8');
|
|
222
|
+
},
|
|
223
|
+
},
|
|
224
|
+
response,
|
|
225
|
+
);
|
|
226
|
+
});
|
|
227
|
+
server.listen(port, '127.0.0.1', () => {
|
|
228
|
+
const address = server.address();
|
|
229
|
+
const selectedPort = typeof address === 'object' && address !== null ? address.port : port;
|
|
230
|
+
console.log(\`listening on http://127.0.0.1:\${String(selectedPort)}\`);
|
|
231
|
+
});
|
|
232
|
+
`,
|
|
233
|
+
},
|
|
234
|
+
{
|
|
235
|
+
path: 'src/health.controller.ts',
|
|
236
|
+
source: `import { Controller, Get } from 'zmdb';
|
|
237
|
+
|
|
238
|
+
@Controller('/health')
|
|
239
|
+
export class HealthController {
|
|
240
|
+
@Get()
|
|
241
|
+
check(): { readonly ok: true } {
|
|
242
|
+
return { ok: true };
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
`,
|
|
246
|
+
},
|
|
247
|
+
{
|
|
248
|
+
path: 'src/health.controller.spec.ts',
|
|
249
|
+
source: `import { createTestApp } from 'zmdb/testing';
|
|
250
|
+
import { bodyText } from 'zmdb/web';
|
|
251
|
+
import { describe, expect, it } from 'vitest';
|
|
252
|
+
|
|
253
|
+
import config from '../zmdb.config.js';
|
|
254
|
+
import { AppModule } from './app.module.js';
|
|
255
|
+
|
|
256
|
+
describe('generated project', () => {
|
|
257
|
+
it('serves health and opens its sqlite database', async () => {
|
|
258
|
+
await using app = createTestApp(AppModule);
|
|
259
|
+
const response = await app.request({ method: 'GET', path: '/health', headers: {} });
|
|
260
|
+
expect(response.status).toBe(200);
|
|
261
|
+
expect(JSON.parse(await bodyText(response))).toEqual({ ok: true });
|
|
262
|
+
|
|
263
|
+
const rows = await config.driver().execute({ text: 'SELECT 1 AS ok', parameters: [] });
|
|
264
|
+
expect(Reflect.get(rows[0] ?? {}, 'ok')).toBe(1);
|
|
265
|
+
});
|
|
266
|
+
});
|
|
267
|
+
`,
|
|
268
|
+
},
|
|
269
|
+
{
|
|
270
|
+
path: '.gitignore',
|
|
271
|
+
source: `node_modules
|
|
272
|
+
dist
|
|
273
|
+
generated-tests
|
|
274
|
+
coverage
|
|
275
|
+
database.sqlite
|
|
276
|
+
`,
|
|
277
|
+
},
|
|
278
|
+
],
|
|
279
|
+
});
|
|
280
|
+
//# sourceMappingURL=project.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"project.js","sourceRoot":"","sources":["../../src/templates/project.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAwB,MAAM,YAAY,CAAC;AAElE,MAAM,CAAC,MAAM,eAAe,GAAoB,CAAC,EAAE,IAAI,EAAE,cAAc,EAAE,EAAE,EAAE,CAAC,CAAC;IAC7E,KAAK,EAAE;QACL;YACE,IAAI,EAAE,cAAc;YACpB,MAAM,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC;gBACxB,IAAI,EAAE,IAAI,CAAC,QAAQ;gBACnB,OAAO,EAAE,IAAI;gBACb,OAAO,EAAE,OAAO;gBAChB,IAAI,EAAE,QAAQ;gBACd,OAAO,EAAE;oBACP,KAAK,EAAE,4BAA4B;oBACnC,KAAK,EACH,qIAAqI;oBACvI,GAAG,EAAE,4BAA4B;oBACjC,WAAW,EAAE,kCAAkC;oBAC/C,IAAI,EAAE,UAAU;oBAChB,KAAK,EAAE,oBAAoB;oBAC3B,IAAI,EAAE,qEAAqE;oBAC3E,SAAS,EAAE,cAAc;iBAC1B;gBACD,YAAY,EAAE;oBACZ,cAAc,EAAE,cAAc;oBAC9B,IAAI,EAAE,cAAc;iBACrB;gBACD,eAAe,EAAE;oBACf,aAAa,EAAE,QAAQ;oBACvB,OAAO,EAAE,QAAQ;oBACjB,KAAK,EAAE,QAAQ;oBACf,MAAM,EAAE,QAAQ;oBAChB,UAAU,EAAE,OAAO;oBACnB,MAAM,EAAE,OAAO;iBAChB;gBACD,OAAO,EAAE;oBACP,IAAI,EAAE,MAAM;iBACb;aACF,CAAC,IAAI;SACP;QACD;YACE,IAAI,EAAE,eAAe;YACrB,MAAM,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC;gBACxB,eAAe,EAAE;oBACf,0BAA0B,EAAE,KAAK;oBACjC,0BAA0B,EAAE,IAAI;oBAChC,eAAe,EAAE,IAAI;oBACrB,GAAG,EAAE,CAAC,QAAQ,EAAE,KAAK,EAAE,cAAc,CAAC;oBACtC,MAAM,EAAE,UAAU;oBAClB,gBAAgB,EAAE,UAAU;oBAC5B,MAAM,EAAE,IAAI;oBACZ,kBAAkB,EAAE,IAAI;oBACxB,wBAAwB,EAAE,IAAI;oBAC9B,YAAY,EAAE,IAAI;oBAClB,MAAM,EAAE,IAAI;oBACZ,MAAM,EAAE,QAAQ;oBAChB,KAAK,EAAE,CAAC,MAAM,CAAC;oBACf,oBAAoB,EAAE,IAAI;iBAC3B;gBACD,OAAO,EAAE,CAAC,aAAa,EAAE,kBAAkB,EAAE,gBAAgB,CAAC;aAC/D,CAAC,IAAI;SACP;QACD;YACE,IAAI,EAAE,mBAAmB;YACzB,MAAM,EAAE;;;;;;;;;wBASU,IAAI,CAAC,SAAS,CAAC,cAAc,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAyErD;SACI;QACD;YACE,IAAI,EAAE,kBAAkB;YACxB,MAAM,EAAE;;;;;;;CAOb;SACI;QACD;YACE,IAAI,EAAE,gBAAgB;YACtB,MAAM,EAAE;;;;;;;;;;;;;;;CAeb;SACI;QACD;YACE,IAAI,EAAE,mBAAmB;YACzB,MAAM,EAAE;;;;;;CAMb;SACI;QACD;YACE,IAAI,EAAE,aAAa;YACnB,MAAM,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA4Cb;SACI;QACD;YACE,IAAI,EAAE,0BAA0B;YAChC,MAAM,EAAE;;;;;;;;;CASb;SACI;QACD;YACE,IAAI,EAAE,+BAA+B;YACrC,MAAM,EAAE;;;;;;;;;;;;;;;;;;CAkBb;SACI;QACD;YACE,IAAI,EAAE,YAAY;YAClB,MAAM,EAAE;;;;;CAKb;SACI;KACF;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"repository.d.ts","sourceRoot":"","sources":["../../src/templates/repository.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAElD,eAAO,MAAM,kBAAkB,EAAE,eAgE/B,CAAC"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
export const repositoryTemplate = ({ name }) => ({
|
|
2
|
+
files: [
|
|
3
|
+
{
|
|
4
|
+
path: `src/${name.fileStem}.repository.ts`,
|
|
5
|
+
source: `import { defineRepository, schemaOf, type Driver } from 'zmdb';
|
|
6
|
+
import type { BaseRepository } from 'zmdb/orm';
|
|
7
|
+
import { repositoryToken } from 'zmdb/app/data';
|
|
8
|
+
import type { ProviderDef } from 'zmdb/app/modules';
|
|
9
|
+
|
|
10
|
+
import type { ${name.pascal} } from './${name.fileStem}.js';
|
|
11
|
+
|
|
12
|
+
const ${name.camel}Schema = schemaOf<${name.pascal}>();
|
|
13
|
+
|
|
14
|
+
export const ${name.constant}_REPOSITORY = repositoryToken<${name.pascal}>('${name.pascal}Repository');
|
|
15
|
+
|
|
16
|
+
export function ${name.camel}RepositoryProvider(driver: Driver): ProviderDef<BaseRepository<${name.pascal}>> {
|
|
17
|
+
return {
|
|
18
|
+
token: ${name.constant}_REPOSITORY,
|
|
19
|
+
useFactory: () => defineRepository(${name.camel}Schema, driver),
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
`,
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
path: `src/${name.fileStem}.repository.spec.ts`,
|
|
26
|
+
source: `import { DatabaseSync } from 'node:sqlite';
|
|
27
|
+
|
|
28
|
+
import { sqliteDriver } from 'zmdb/sqlite';
|
|
29
|
+
import { createTestApp } from 'zmdb/testing';
|
|
30
|
+
import { Module } from 'zmdb';
|
|
31
|
+
import { describe, expect, it } from 'vitest';
|
|
32
|
+
|
|
33
|
+
import {
|
|
34
|
+
${name.constant}_REPOSITORY,
|
|
35
|
+
${name.camel}RepositoryProvider,
|
|
36
|
+
} from './${name.fileStem}.repository.js';
|
|
37
|
+
|
|
38
|
+
describe('${name.pascal} repository provider', () => {
|
|
39
|
+
it('creates and reads a row through sqlite', async () => {
|
|
40
|
+
const database = new DatabaseSync(':memory:');
|
|
41
|
+
try {
|
|
42
|
+
database.exec(
|
|
43
|
+
'CREATE TABLE "${name.table}" ("id" INTEGER PRIMARY KEY AUTOINCREMENT, "name" TEXT NOT NULL)',
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
@Module({ providers: [${name.camel}RepositoryProvider(sqliteDriver(database))] })
|
|
47
|
+
class ${name.pascal}RepositoryTestModule {}
|
|
48
|
+
|
|
49
|
+
await using app = createTestApp(${name.pascal}RepositoryTestModule);
|
|
50
|
+
const repository = app.get(${name.constant}_REPOSITORY);
|
|
51
|
+
const created = await repository.create({ name: 'Ada' });
|
|
52
|
+
expect(created.name).toBe('Ada');
|
|
53
|
+
expect((await repository.findById(created.id))?.name).toBe('Ada');
|
|
54
|
+
} finally {
|
|
55
|
+
database.close();
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
`,
|
|
60
|
+
},
|
|
61
|
+
],
|
|
62
|
+
instructions: [
|
|
63
|
+
`add to src/app.module.ts, in @Module({ providers: [ … ] }):\n ${name.camel}RepositoryProvider(driver),`,
|
|
64
|
+
],
|
|
65
|
+
});
|
|
66
|
+
//# sourceMappingURL=repository.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"repository.js","sourceRoot":"","sources":["../../src/templates/repository.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,kBAAkB,GAAoB,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC;IAChE,KAAK,EAAE;QACL;YACE,IAAI,EAAE,OAAO,IAAI,CAAC,QAAQ,gBAAgB;YAC1C,MAAM,EAAE;;;;;gBAKE,IAAI,CAAC,MAAM,cAAc,IAAI,CAAC,QAAQ;;QAE9C,IAAI,CAAC,KAAK,qBAAqB,IAAI,CAAC,MAAM;;eAEnC,IAAI,CAAC,QAAQ,iCAAiC,IAAI,CAAC,MAAM,MAAM,IAAI,CAAC,MAAM;;kBAEvE,IAAI,CAAC,KAAK,kEAAkE,IAAI,CAAC,MAAM;;aAE5F,IAAI,CAAC,QAAQ;yCACe,IAAI,CAAC,KAAK;;;CAGlD;SACI;QACD;YACE,IAAI,EAAE,OAAO,IAAI,CAAC,QAAQ,qBAAqB;YAC/C,MAAM,EAAE;;;;;;;;IAQV,IAAI,CAAC,QAAQ;IACb,IAAI,CAAC,KAAK;YACF,IAAI,CAAC,QAAQ;;YAEb,IAAI,CAAC,MAAM;;;;;yBAKE,IAAI,CAAC,KAAK;;;8BAGL,IAAI,CAAC,KAAK;cAC1B,IAAI,CAAC,MAAM;;wCAEe,IAAI,CAAC,MAAM;mCAChB,IAAI,CAAC,QAAQ;;;;;;;;;CAS/C;SACI;KACF;IACD,YAAY,EAAE;QACZ,kEAAkE,IAAI,CAAC,KAAK,6BAA6B;KAC1G;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/templates/schema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAElD,eAAO,MAAM,cAAc,EAAE,eAkC3B,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export const schemaTemplate = ({ name }) => ({
|
|
2
|
+
files: [
|
|
3
|
+
{
|
|
4
|
+
path: `src/${name.fileStem}.ts`,
|
|
5
|
+
source: `import type { PrimaryKey, Serial, Sql, Table } from 'zmdb';
|
|
6
|
+
|
|
7
|
+
export interface ${name.pascal} extends Table<'${name.table}'> {
|
|
8
|
+
id: number & Sql<'integer'> & Serial & PrimaryKey;
|
|
9
|
+
name: string & Sql<'text'>;
|
|
10
|
+
}
|
|
11
|
+
`,
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
path: `src/${name.fileStem}.spec.ts`,
|
|
15
|
+
source: `import { Module, is, schemaOf } from 'zmdb';
|
|
16
|
+
import { createTestApp } from 'zmdb/testing';
|
|
17
|
+
import { describe, expect, it } from 'vitest';
|
|
18
|
+
|
|
19
|
+
import type { ${name.pascal} } from './${name.fileStem}.js';
|
|
20
|
+
|
|
21
|
+
@Module({})
|
|
22
|
+
class ${name.pascal}SchemaTestModule {}
|
|
23
|
+
|
|
24
|
+
describe('${name.pascal} schema', () => {
|
|
25
|
+
it('emits the table declaration and validates through the transformer', async () => {
|
|
26
|
+
await using app = createTestApp(${name.pascal}SchemaTestModule);
|
|
27
|
+
await app.init();
|
|
28
|
+
expect(schemaOf<${name.pascal}>().table).toBe('${name.table}');
|
|
29
|
+
expect(is<{ id: number }>({ id: 'x' })).toBe(false);
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
`,
|
|
33
|
+
},
|
|
34
|
+
],
|
|
35
|
+
});
|
|
36
|
+
//# sourceMappingURL=schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../src/templates/schema.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,cAAc,GAAoB,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC;IAC5D,KAAK,EAAE;QACL;YACE,IAAI,EAAE,OAAO,IAAI,CAAC,QAAQ,KAAK;YAC/B,MAAM,EAAE;;mBAEK,IAAI,CAAC,MAAM,mBAAmB,IAAI,CAAC,KAAK;;;;CAI1D;SACI;QACD;YACE,IAAI,EAAE,OAAO,IAAI,CAAC,QAAQ,UAAU;YACpC,MAAM,EAAE;;;;gBAIE,IAAI,CAAC,MAAM,cAAc,IAAI,CAAC,QAAQ;;;QAG9C,IAAI,CAAC,MAAM;;YAEP,IAAI,CAAC,MAAM;;sCAEe,IAAI,CAAC,MAAM;;sBAE3B,IAAI,CAAC,MAAM,oBAAoB,IAAI,CAAC,KAAK;;;;CAI9D;SACI;KACF;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { FormatConfig } from 'oxfmt';
|
|
2
|
+
export declare const FORMAT_OPTIONS: FormatConfig;
|
|
3
|
+
export type ScaffoldKind = 'command' | 'controller' | 'module' | 'project' | 'repository' | 'schema';
|
|
4
|
+
export interface ScaffoldName {
|
|
5
|
+
readonly input: string;
|
|
6
|
+
readonly fileStem: string;
|
|
7
|
+
readonly pascal: string;
|
|
8
|
+
readonly camel: string;
|
|
9
|
+
readonly constant: string;
|
|
10
|
+
readonly table: string;
|
|
11
|
+
}
|
|
12
|
+
export interface TemplateContext {
|
|
13
|
+
readonly name: ScaffoldName;
|
|
14
|
+
readonly packageVersion: string;
|
|
15
|
+
}
|
|
16
|
+
export interface TemplateFile {
|
|
17
|
+
readonly path: string;
|
|
18
|
+
readonly source: string;
|
|
19
|
+
}
|
|
20
|
+
export interface TemplatePlan {
|
|
21
|
+
readonly files: readonly TemplateFile[];
|
|
22
|
+
readonly instructions?: readonly string[];
|
|
23
|
+
}
|
|
24
|
+
export type TemplateFactory = (context: TemplateContext) => TemplatePlan;
|
|
25
|
+
//# sourceMappingURL=types.d.ts.map
|