@dashild/prisma 0.0.0-stage → 0.1.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +58 -2
- package/dist/extract.d.ts +24 -0
- package/dist/extract.d.ts.map +1 -0
- package/dist/extract.js +96 -0
- package/dist/extract.js.map +1 -0
- package/dist/generator.d.ts +25 -0
- package/dist/generator.d.ts.map +1 -0
- package/dist/generator.js +59 -0
- package/dist/generator.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -0
- package/package.json +54 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Daljomar Morillo
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,59 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @dashild/prisma
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Generador oficial de Prisma. Se declara en `schema.prisma`:
|
|
4
|
+
|
|
5
|
+
```prisma
|
|
6
|
+
generator client {
|
|
7
|
+
provider = "prisma-client"
|
|
8
|
+
output = "../src/generated/prisma"
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
generator dashild {
|
|
12
|
+
provider = "dashild-prisma-generator"
|
|
13
|
+
output = "../src/generated/dashild"
|
|
14
|
+
}
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Escribe **un solo archivo**: `dashild-metadata.json`. No genera recursos, ni páginas, ni clientes.
|
|
18
|
+
|
|
19
|
+
## Qué contiene el artefacto
|
|
20
|
+
|
|
21
|
+
| Campo | Para qué |
|
|
22
|
+
| --- | --- |
|
|
23
|
+
| `formatVersion` | Dashild rechaza metadatos de un formato que no entiende |
|
|
24
|
+
| `schemaPath` | Ruta absoluta del schema de origen |
|
|
25
|
+
| `clientOutput` | Ruta absoluta del cliente Prisma, si hay un generador `prisma-client` |
|
|
26
|
+
| `engineVersion` | Hash del engine con el que Prisma generó (diagnóstico) |
|
|
27
|
+
| `models` | Campos, tipos, enums, relaciones, `nativeType`, marcas de solo lectura |
|
|
28
|
+
| `enums` | Nombre y valores |
|
|
29
|
+
|
|
30
|
+
`engineVersion` no es la versión de Prisma: `options.version` de Prisma 7 es el commit del engine. La versión del paquete no se expone al generador.
|
|
31
|
+
|
|
32
|
+
## Resolución del provider (verificado con Prisma 7.10.1)
|
|
33
|
+
|
|
34
|
+
**Prisma no resuelve `provider` como módulo de Node.** Ejecuta la cadena tal cual con `/bin/sh`. Por eso `provider = "dashild-prisma-generator"` funciona únicamente porque el paquete publica un `bin` con ese nombre y npm/pnpm ponen `node_modules/.bin` en el `PATH` al correr scripts.
|
|
35
|
+
|
|
36
|
+
Consecuencia: `pnpm prisma generate` (o `npm run ...`) funciona; invocar el binario de Prisma desde un entorno sin ese `PATH` falla con `dashild-prisma-generator: orden no encontrada`. El error es explícito, no silencioso.
|
|
37
|
+
|
|
38
|
+
## Prisma 7
|
|
39
|
+
|
|
40
|
+
- La `url` del datasource ya no se declara en el schema: va en `prisma.config.ts` o en el constructor del cliente. El fixture no la declara porque `generate` no se conecta.
|
|
41
|
+
- `@prisma/generator-helper` es CommonJS: el entrypoint lo carga con `createRequire`, no con un import nombrado de ESM.
|
|
42
|
+
|
|
43
|
+
## Código
|
|
44
|
+
|
|
45
|
+
- `src/generator.ts` — entrypoint. Solo registra el handler y escribe el archivo.
|
|
46
|
+
- `src/extract.ts` — DMMF → `DashildMetadata`. Funciones puras, probadas aparte.
|
|
47
|
+
|
|
48
|
+
## Tests
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
pnpm --filter @dashild/prisma test
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Dos niveles:
|
|
55
|
+
|
|
56
|
+
- **Integración**: ejecuta `prisma generate` de verdad sobre `test/fixtures/hostile/schema.prisma` (enum, opcionales, `Decimal`, `BigInt`, `Json`, `Bytes`, `@db.Text`, `@db.Uuid`, m2o, o2m y auto-relación) y verifica el JSON.
|
|
57
|
+
- **Unidad**: `resolveClientOutput` con generadores sintéticos, incluido el caso de `provider` por variable de entorno.
|
|
58
|
+
|
|
59
|
+
El test necesita el `bin` del generador en el `PATH`; lo resuelve desde el `.bin` de la raíz del monorepo, que es donde pnpm enlaza `@dashild/prisma` (declarado como devDependency de la raíz precisamente para esto).
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DMMF extraction into the Dashild artifact.
|
|
3
|
+
*
|
|
4
|
+
* It lives outside the entrypoint (`generator.ts`) so it can be tested without
|
|
5
|
+
* starting Prisma's protocol. Everything here is a pure function over input
|
|
6
|
+
* data: same DMMF, same JSON.
|
|
7
|
+
*/
|
|
8
|
+
import type { GeneratorOptions } from "@prisma/generator-helper";
|
|
9
|
+
import { type DashildMetadata } from "@dashild/core";
|
|
10
|
+
/** Generator configuration as Prisma sees it. */
|
|
11
|
+
export type GeneratorConfig = GeneratorOptions["otherGenerators"][number];
|
|
12
|
+
export declare function extractMetadata(options: GeneratorOptions): DashildMetadata;
|
|
13
|
+
/**
|
|
14
|
+
* Path to the generated Prisma client, without assuming `node_modules`
|
|
15
|
+
* (spike §7).
|
|
16
|
+
*
|
|
17
|
+
* Prisma resolves the client generator's `output` relative to the schema. This
|
|
18
|
+
* does the same and returns an absolute path so the runtime does not depend on
|
|
19
|
+
* the starting directory.
|
|
20
|
+
*/
|
|
21
|
+
export declare function resolveClientOutput(schemaPath: string, generators: readonly GeneratorConfig[]): {
|
|
22
|
+
clientOutput?: string;
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=extract.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extract.d.ts","sourceRoot":"","sources":["../src/extract.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,OAAO,KAAK,EAAQ,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAEvE,OAAO,EAEL,KAAK,eAAe,EAKrB,MAAM,eAAe,CAAC;AAEvB,iDAAiD;AACjD,MAAM,MAAM,eAAe,GAAG,gBAAgB,CAAC,iBAAiB,CAAC,CAAC,MAAM,CAAC,CAAC;AAE1E,wBAAgB,eAAe,CAAC,OAAO,EAAE,gBAAgB,GAAG,eAAe,CAS1E;AAmED;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CACjC,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,SAAS,eAAe,EAAE,GACrC;IAAE,YAAY,CAAC,EAAE,MAAM,CAAA;CAAE,CAa3B"}
|
package/dist/extract.js
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DMMF extraction into the Dashild artifact.
|
|
3
|
+
*
|
|
4
|
+
* It lives outside the entrypoint (`generator.ts`) so it can be tested without
|
|
5
|
+
* starting Prisma's protocol. Everything here is a pure function over input
|
|
6
|
+
* data: same DMMF, same JSON.
|
|
7
|
+
*/
|
|
8
|
+
import { dirname, isAbsolute, resolve } from "node:path";
|
|
9
|
+
import { METADATA_FORMAT_VERSION, } from "@dashild/core";
|
|
10
|
+
export function extractMetadata(options) {
|
|
11
|
+
return {
|
|
12
|
+
formatVersion: METADATA_FORMAT_VERSION,
|
|
13
|
+
schemaPath: options.schemaPath,
|
|
14
|
+
...resolveClientOutput(options.schemaPath, options.otherGenerators),
|
|
15
|
+
...(options.version ? { engineVersion: options.version } : {}),
|
|
16
|
+
models: options.dmmf.datamodel.models.map(toModelMetadata),
|
|
17
|
+
enums: options.dmmf.datamodel.enums.map(toEnumMetadata),
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
function toModelMetadata(model) {
|
|
21
|
+
// Foreign keys are written by the relation, not the form. If
|
|
22
|
+
// `organizationId` appeared as an editable field, the panel would offer two
|
|
23
|
+
// controls for the same data and one of them could drift.
|
|
24
|
+
const foreignKeys = new Set();
|
|
25
|
+
for (const field of model.fields) {
|
|
26
|
+
if (field.kind !== "object")
|
|
27
|
+
continue;
|
|
28
|
+
for (const name of field.relationFromFields ?? []) {
|
|
29
|
+
foreignKeys.add(name);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return {
|
|
33
|
+
name: model.name,
|
|
34
|
+
fields: model.fields.map((field) => toFieldMetadata(field, foreignKeys)),
|
|
35
|
+
...(model.documentation ? { documentation: model.documentation } : {}),
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
function toFieldMetadata(field, foreignKeys) {
|
|
39
|
+
// `nativeType` arrives as a `[name, args]` tuple; the mapping only cares
|
|
40
|
+
// about names (`Text`, `Date`, `Uuid`), not precision.
|
|
41
|
+
const nativeType = field.nativeType?.[0];
|
|
42
|
+
return {
|
|
43
|
+
name: field.name,
|
|
44
|
+
type: field.type,
|
|
45
|
+
kind: field.kind,
|
|
46
|
+
isRequired: field.isRequired,
|
|
47
|
+
isList: field.isList,
|
|
48
|
+
isId: field.isId,
|
|
49
|
+
isUnique: field.isUnique,
|
|
50
|
+
isReadOnly: field.isId ||
|
|
51
|
+
(field.isUpdatedAt ?? false) ||
|
|
52
|
+
(field.isGenerated ?? false) ||
|
|
53
|
+
foreignKeys.has(field.name),
|
|
54
|
+
...(field.isGenerated ? { isGenerated: true } : {}),
|
|
55
|
+
...(field.isUpdatedAt ? { isUpdatedAt: true } : {}),
|
|
56
|
+
...(nativeType ? { nativeType } : {}),
|
|
57
|
+
hasDefaultValue: field.hasDefaultValue,
|
|
58
|
+
...(field.hasDefaultValue && field.default !== undefined
|
|
59
|
+
? { default: field.default }
|
|
60
|
+
: {}),
|
|
61
|
+
...(field.documentation ? { documentation: field.documentation } : {}),
|
|
62
|
+
...(field.relationName ? { relationName: field.relationName } : {}),
|
|
63
|
+
...(field.relationFromFields?.length
|
|
64
|
+
? { relationFromFields: [...field.relationFromFields] }
|
|
65
|
+
: {}),
|
|
66
|
+
...(field.relationToFields?.length
|
|
67
|
+
? { relationToFields: [...field.relationToFields] }
|
|
68
|
+
: {}),
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
function toEnumMetadata(value) {
|
|
72
|
+
return {
|
|
73
|
+
name: value.name,
|
|
74
|
+
values: value.values.map((entry) => entry.name),
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Path to the generated Prisma client, without assuming `node_modules`
|
|
79
|
+
* (spike §7).
|
|
80
|
+
*
|
|
81
|
+
* Prisma resolves the client generator's `output` relative to the schema. This
|
|
82
|
+
* does the same and returns an absolute path so the runtime does not depend on
|
|
83
|
+
* the starting directory.
|
|
84
|
+
*/
|
|
85
|
+
export function resolveClientOutput(schemaPath, generators) {
|
|
86
|
+
const client = generators.find((generator) => (generator.provider.value ?? "").includes("prisma-client"));
|
|
87
|
+
const output = client?.output?.value;
|
|
88
|
+
if (!output)
|
|
89
|
+
return {};
|
|
90
|
+
return {
|
|
91
|
+
clientOutput: isAbsolute(output)
|
|
92
|
+
? output
|
|
93
|
+
: resolve(dirname(schemaPath), output),
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
//# sourceMappingURL=extract.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extract.js","sourceRoot":"","sources":["../src/extract.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAIzD,OAAO,EACL,uBAAuB,GAMxB,MAAM,eAAe,CAAC;AAKvB,MAAM,UAAU,eAAe,CAAC,OAAyB;IACvD,OAAO;QACL,aAAa,EAAE,uBAAuB;QACtC,UAAU,EAAE,OAAO,CAAC,UAAU;QAC9B,GAAG,mBAAmB,CAAC,OAAO,CAAC,UAAU,EAAE,OAAO,CAAC,eAAe,CAAC;QACnE,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,aAAa,EAAE,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC9D,MAAM,EAAE,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,GAAG,CAAC,eAAe,CAAC;QAC1D,KAAK,EAAE,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,cAAc,CAAC;KACxD,CAAC;AACJ,CAAC;AAED,SAAS,eAAe,CAAC,KAAiB;IACxC,6DAA6D;IAC7D,4EAA4E;IAC5E,0DAA0D;IAC1D,MAAM,WAAW,GAAG,IAAI,GAAG,EAAU,CAAC;IACtC,KAAK,MAAM,KAAK,IAAI,KAAK,CAAC,MAAM,EAAE,CAAC;QACjC,IAAI,KAAK,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AM,UAAU,mBAAmB,CACjC,UAAkB,EAClB,UAAsC;IAEtC,MAAM,MAAM,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,CAC3C,CAAC,SAAS,CAAC,QAAQ,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,QAAQ,CAAC,eAAe,CAAC,CAC3D,CAAC;IAEF,MAAM,MAAM,GAAG,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC;IACrC,IAAI,CAAC,MAAM;QAAE,OAAO,EAAE,CAAC;IAEvB,OAAO;QACL,YAAY,EAAE,UAAU,CAAC,MAAM,CAAC;YAC9B,CAAC,CAAC,MAAM;YACR,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;KACzC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Dashild's official Prisma generator.
|
|
4
|
+
*
|
|
5
|
+
* Prisma runs it as a child process during `prisma generate` and passes the
|
|
6
|
+
* DMMF over stdio. It does not generate resources or pages: it writes a single
|
|
7
|
+
* artifact, `dashild-metadata.json`, which feeds the scaffold, server
|
|
8
|
+
* validation, query includes and `dashild doctor`.
|
|
9
|
+
*
|
|
10
|
+
* Declared in `schema.prisma`:
|
|
11
|
+
*
|
|
12
|
+
* generator dashild {
|
|
13
|
+
* provider = "dashild-prisma-generator"
|
|
14
|
+
* output = "../src/generated/dashild"
|
|
15
|
+
* }
|
|
16
|
+
*
|
|
17
|
+
* Provider resolution: Prisma does not resolve `provider` as a Node module. It
|
|
18
|
+
* executes the string with `/bin/sh`, so `provider` must be an executable on
|
|
19
|
+
* the `PATH`. That works because the package publishes a `bin` with the same
|
|
20
|
+
* name and npm/pnpm add `node_modules/.bin` to `PATH` when running scripts.
|
|
21
|
+
* Running `prisma generate` without that `PATH` fails with an explicit error
|
|
22
|
+
* (`dashild-prisma-generator: command not found`).
|
|
23
|
+
*/
|
|
24
|
+
export {};
|
|
25
|
+
//# sourceMappingURL=generator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../src/generator.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;;;;;;;;;;;GAqBG"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Dashild's official Prisma generator.
|
|
4
|
+
*
|
|
5
|
+
* Prisma runs it as a child process during `prisma generate` and passes the
|
|
6
|
+
* DMMF over stdio. It does not generate resources or pages: it writes a single
|
|
7
|
+
* artifact, `dashild-metadata.json`, which feeds the scaffold, server
|
|
8
|
+
* validation, query includes and `dashild doctor`.
|
|
9
|
+
*
|
|
10
|
+
* Declared in `schema.prisma`:
|
|
11
|
+
*
|
|
12
|
+
* generator dashild {
|
|
13
|
+
* provider = "dashild-prisma-generator"
|
|
14
|
+
* output = "../src/generated/dashild"
|
|
15
|
+
* }
|
|
16
|
+
*
|
|
17
|
+
* Provider resolution: Prisma does not resolve `provider` as a Node module. It
|
|
18
|
+
* executes the string with `/bin/sh`, so `provider` must be an executable on
|
|
19
|
+
* the `PATH`. That works because the package publishes a `bin` with the same
|
|
20
|
+
* name and npm/pnpm add `node_modules/.bin` to `PATH` when running scripts.
|
|
21
|
+
* Running `prisma generate` without that `PATH` fails with an explicit error
|
|
22
|
+
* (`dashild-prisma-generator: command not found`).
|
|
23
|
+
*/
|
|
24
|
+
import { mkdir, writeFile } from "node:fs/promises";
|
|
25
|
+
import { createRequire } from "node:module";
|
|
26
|
+
import { join } from "node:path";
|
|
27
|
+
import { extractMetadata } from "./extract.js";
|
|
28
|
+
const { generatorHandler } = createRequire(import.meta.url)("@prisma/generator-helper");
|
|
29
|
+
const OUTPUT_FILE = "dashild-metadata.json";
|
|
30
|
+
generatorHandler({
|
|
31
|
+
onManifest() {
|
|
32
|
+
return {
|
|
33
|
+
prettyName: "Dashild",
|
|
34
|
+
defaultOutput: "./dashild",
|
|
35
|
+
version: "0.0.0",
|
|
36
|
+
};
|
|
37
|
+
},
|
|
38
|
+
async onGenerate(options) {
|
|
39
|
+
const outputDir = options.generator.output?.value;
|
|
40
|
+
if (!outputDir) {
|
|
41
|
+
throw new Error("Dashild: missing `output` in the `generator dashild` block.");
|
|
42
|
+
}
|
|
43
|
+
const metadata = extractMetadata(options);
|
|
44
|
+
const target = join(outputDir, OUTPUT_FILE);
|
|
45
|
+
await mkdir(outputDir, { recursive: true });
|
|
46
|
+
await writeFile(target, `${JSON.stringify(metadata, jsonReplacer, 2)}\n`, "utf8");
|
|
47
|
+
// Informational: Prisma shows it in `generate` output.
|
|
48
|
+
process.stderr.write(`dashild: ${metadata.models.length} models, ${metadata.enums.length} enums → ${target}\n`);
|
|
49
|
+
},
|
|
50
|
+
});
|
|
51
|
+
/**
|
|
52
|
+
* A `@default(9007199254740993n)` or a `Decimal` may arrive as BigInt and
|
|
53
|
+
* `JSON.stringify` would throw. It is normalized to a string: the metadata is
|
|
54
|
+
* diagnostic and is never used to rebuild the value.
|
|
55
|
+
*/
|
|
56
|
+
function jsonReplacer(_key, value) {
|
|
57
|
+
return typeof value === "bigint" ? value.toString() : value;
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=generator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../src/generator.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAIjC,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAS/C,MAAM,EAAE,gBAAgB,EAAE,GAAG,aAAa,CAAC,OAAO,IAAI,C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.json` artifact.
|
|
3
|
+
*
|
|
4
|
+
* It defines nothing of its own: the metadata contract lives in
|
|
5
|
+
* `@dashild/core` because the generator, the server runtime and the CLI all
|
|
6
|
+
* consume it. This file re-exports it so the generator has a natural local
|
|
7
|
+
* import.
|
|
8
|
+
*/
|
|
9
|
+
export { METADATA_FORMAT_VERSION, type DashildMetadata, type EnumMetadata, type FieldKind, type FieldMetadata, type ModelMetadata, type ScalarKind, } from "@dashild/core";
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EACL,uBAAuB,EACvB,KAAK,eAAe,EACpB,KAAK,YAAY,EACjB,KAAK,SAAS,EACd,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,UAAU,GAChB,MAAM,eAAe,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @dashild/prisma — types for the `dashild-metadata.json` artifact.
|
|
3
|
+
*
|
|
4
|
+
* It defines nothing of its own: the metadata contract lives in
|
|
5
|
+
* `@dashild/core` because the generator, the server runtime and the CLI all
|
|
6
|
+
* consume it. This file re-exports it so the generator has a natural local
|
|
7
|
+
* import.
|
|
8
|
+
*/
|
|
9
|
+
export { METADATA_FORMAT_VERSION, } from "@dashild/core";
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EACL,uBAAuB,GAOxB,MAAM,eAAe,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,57 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dashild/prisma",
|
|
3
|
-
"version": "0.0.0
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
3
|
+
"version": "0.1.0-alpha.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Official Prisma generator that extracts the metadata Dashild consumes",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/generator.d.ts",
|
|
10
|
+
"default": "./dist/generator.js"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"bin": {
|
|
14
|
+
"dashild-prisma-generator": "./dist/generator.js"
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist"
|
|
18
|
+
],
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"@dashild/core": "0.1.0-alpha.0",
|
|
21
|
+
"@prisma/generator-helper": "7.10.1"
|
|
22
|
+
},
|
|
23
|
+
"main": "./dist/generator.js",
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"prisma": "7.10.1"
|
|
26
|
+
},
|
|
27
|
+
"author": "Daljomar Morillo",
|
|
28
|
+
"keywords": [
|
|
29
|
+
"dashild",
|
|
30
|
+
"prisma",
|
|
31
|
+
"generator",
|
|
32
|
+
"admin"
|
|
33
|
+
],
|
|
34
|
+
"repository": {
|
|
35
|
+
"type": "git",
|
|
36
|
+
"url": "git+https://github.com/dashild/dashild.git",
|
|
37
|
+
"directory": "packages/prisma"
|
|
38
|
+
},
|
|
39
|
+
"homepage": "https://github.com/dashild/dashild#readme",
|
|
40
|
+
"bugs": {
|
|
41
|
+
"url": "https://github.com/dashild/dashild/issues"
|
|
42
|
+
},
|
|
43
|
+
"engines": {
|
|
44
|
+
"node": ">=22"
|
|
45
|
+
},
|
|
46
|
+
"publishConfig": {
|
|
47
|
+
"access": "public",
|
|
48
|
+
"tag": "alpha"
|
|
49
|
+
},
|
|
50
|
+
"scripts": {
|
|
51
|
+
"build": "tsc -p tsconfig.json",
|
|
52
|
+
"dev": "tsc -p tsconfig.json --watch",
|
|
53
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
54
|
+
"clean": "rm -rf dist",
|
|
55
|
+
"test": "pnpm build && node --test \"test/*.test.mjs\""
|
|
56
|
+
}
|
|
6
57
|
}
|