nitro-drizzle 0.2.13 → 0.2.15
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.
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { dedent } from "strip-indent";
|
|
2
|
+
//#region src/context/internal/format.ts
|
|
3
|
+
function script(strings, ...values) {
|
|
4
|
+
const rawStrings = strings.raw;
|
|
5
|
+
let result = "";
|
|
6
|
+
for (let i = 0; i < rawStrings.length; i++) {
|
|
7
|
+
const string = rawStrings[i];
|
|
8
|
+
result += string;
|
|
9
|
+
if (i < values.length) {
|
|
10
|
+
let valueStr = String(values[i]);
|
|
11
|
+
const match = string.match(/\n([\t\s]*)([^\t\s]*)$/g)?.at(0);
|
|
12
|
+
if (match) valueStr = valueStr.replaceAll("\n", match);
|
|
13
|
+
result += valueStr;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return dedent(result);
|
|
17
|
+
}
|
|
18
|
+
//#endregion
|
|
19
|
+
export { script };
|
|
20
|
+
|
|
21
|
+
//# sourceMappingURL=format.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format.mjs","names":[],"sources":["../../../src/context/internal/format.ts"],"sourcesContent":["import { dedent } from \"strip-indent\";\n\nexport function script(strings: TemplateStringsArray, ...values: unknown[]): string {\n const rawStrings = strings.raw;\n let result = \"\";\n\n for (let i = 0; i < rawStrings.length; i++) {\n const string = rawStrings[i];\n result += string;\n\n if (i < values.length) {\n let valueStr = String(values[i]);\n const match = string.match(/\\n([\\t\\s]*)([^\\t\\s]*)$/g)?.at(0);\n if (match) {\n valueStr = valueStr.replaceAll(\"\\n\", match);\n }\n result += valueStr;\n }\n }\n\n return dedent(result);\n}\n"],"mappings":";;AAEA,SAAgB,OAAO,SAA+B,GAAG,QAA2B;CAClF,MAAM,aAAa,QAAQ;CAC3B,IAAI,SAAS;CAEb,KAAK,IAAI,IAAI,GAAG,IAAI,WAAW,QAAQ,KAAK;EAC1C,MAAM,SAAS,WAAW;EAC1B,UAAU;EAEV,IAAI,IAAI,OAAO,QAAQ;GACrB,IAAI,WAAW,OAAO,OAAO,EAAE;GAC/B,MAAM,QAAQ,OAAO,MAAM,yBAAyB,CAAC,EAAE,GAAG,CAAC;GAC3D,IAAI,OACF,WAAW,SAAS,WAAW,MAAM,KAAK;GAE5C,UAAU;EACZ;CACF;CAEA,OAAO,OAAO,MAAM;AACtB"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { script } from "./format.mjs";
|
|
1
2
|
import { genAugmentation, genExport, genInlineTypeImport, genString, genTypeImport } from "knitwork";
|
|
2
3
|
//#region src/context/internal/templates.ts
|
|
3
4
|
function runtimeDeclarations(datasources) {
|
|
@@ -18,7 +19,7 @@ function genReference(reference) {
|
|
|
18
19
|
function moduleTypeDeclarations(datasources) {
|
|
19
20
|
if (!datasources.length) return {};
|
|
20
21
|
const names = datasources.map((d) => d.name);
|
|
21
|
-
const moduleId = "nitro-drizzle";
|
|
22
|
+
const moduleId = "nitro-drizzle/module";
|
|
22
23
|
return { "nitro-drizzle/module.d.ts": [
|
|
23
24
|
genReference({ types: moduleId }),
|
|
24
25
|
genAugmentation(moduleId, { DatasourceOptions: [{}, { extends: `Record<${names.map((n) => genString(n)).join(" | ")}, { connector: string; }>` }] }),
|
|
@@ -27,7 +28,7 @@ function moduleTypeDeclarations(datasources) {
|
|
|
27
28
|
}
|
|
28
29
|
function dialectDeclarations(datasources) {
|
|
29
30
|
return datasources.filter((d) => d.enabled).map(({ name, dialect }) => {
|
|
30
|
-
return `
|
|
31
|
+
return script`
|
|
31
32
|
declare module "#nitro-drizzle/dialects/${name}" {
|
|
32
33
|
${genExport(`nitro-drizzle/dialects/${dialect}`, "*")}
|
|
33
34
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"templates.mjs","names":[],"sources":["../../../src/context/internal/templates.ts"],"sourcesContent":["import {\n genTypeImport,\n genAugmentation,\n genInlineTypeImport,\n genString,\n genExport,\n} from \"knitwork\";\nimport type { DatasourceInfo } from \"..\";\nimport type { VirtualModules } from \"nitro-drizzle/shared\";\n\nexport function runtimeDeclarations(datasources: readonly DatasourceInfo[]) {\n if (!datasources.length) {\n return \"\";\n }\n\n return [\n genTypeImport(\"nitro-drizzle/runtime\", [\"ToDatasourceProvider\"]),\n genAugmentation(\"nitro-drizzle/runtime\", {\n DatasourceRegistry: Object.fromEntries(\n datasources\n .filter((datasource) => {\n return datasource.enabled;\n })\n .map(({ name, imports }): [string, string] => {\n const schemaType = genSchemaType(imports.schema);\n const driverType = genInlineTypeImport(imports.connector);\n return [name, `${\"ToDatasourceProvider\"}<${schemaType}, ${driverType}<${schemaType}>>`];\n }),\n ),\n }),\n ].join(\"\\n\");\n}\n\nfunction genSchemaType(imports: string[]) {\n return imports.map((id) => `typeof import('${id}')`).join(\" & \");\n}\n\nexport type TypeReference = { types: string };\n\nexport type PathReference = { path: string };\n\nexport function genReference(reference: TypeReference | PathReference) {\n return /* ts */ `/// <reference ${Object.entries(reference)\n .map(([prop, value]) => `${prop}=\"${value}\"`)\n .join(\"\")} />`;\n}\n\nexport function moduleTypeDeclarations(\n datasources: readonly DatasourceInfo[],\n): VirtualModules<`${string}.d.ts`> {\n if (!datasources.length) {\n return {};\n }\n\n const names = datasources.map((d) => d.name);\n\n const moduleId = \"nitro-drizzle\";\n\n const content = [\n genReference({ types: moduleId }),\n genAugmentation(moduleId, {\n DatasourceOptions: [\n {},\n {\n extends: `Record<${names.map((n) => genString(n)).join(\" | \")}, { connector: string; }>`,\n },\n ],\n }),\n /* ts */ `export {};`,\n ].join(\"\\n\");\n\n return {\n \"nitro-drizzle/module.d.ts\": content,\n };\n}\n\nexport function dialectDeclarations(datasources: readonly DatasourceInfo[]) {\n return datasources\n .filter((d) => d.enabled)\n .map(({ name, dialect }) => {\n return /*ts*/ `\n declare module \"#nitro-drizzle/dialects/${name}\" {\n ${genExport(`nitro-drizzle/dialects/${dialect}`, \"*\")}\n }\n `;\n })\n .join(\"\\n\");\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"templates.mjs","names":[],"sources":["../../../src/context/internal/templates.ts"],"sourcesContent":["import {\n genTypeImport,\n genAugmentation,\n genInlineTypeImport,\n genString,\n genExport,\n} from \"knitwork\";\nimport type { DatasourceInfo } from \"..\";\nimport type { VirtualModules } from \"nitro-drizzle/shared\";\nimport { script } from \"./format\";\n\nexport function runtimeDeclarations(datasources: readonly DatasourceInfo[]) {\n if (!datasources.length) {\n return \"\";\n }\n\n return [\n genTypeImport(\"nitro-drizzle/runtime\", [\"ToDatasourceProvider\"]),\n genAugmentation(\"nitro-drizzle/runtime\", {\n DatasourceRegistry: Object.fromEntries(\n datasources\n .filter((datasource) => {\n return datasource.enabled;\n })\n .map(({ name, imports }): [string, string] => {\n const schemaType = genSchemaType(imports.schema);\n const driverType = genInlineTypeImport(imports.connector);\n return [name, `${\"ToDatasourceProvider\"}<${schemaType}, ${driverType}<${schemaType}>>`];\n }),\n ),\n }),\n ].join(\"\\n\");\n}\n\nfunction genSchemaType(imports: string[]) {\n return imports.map((id) => `typeof import('${id}')`).join(\" & \");\n}\n\nexport type TypeReference = { types: string };\n\nexport type PathReference = { path: string };\n\nexport function genReference(reference: TypeReference | PathReference) {\n return /* ts */ `/// <reference ${Object.entries(reference)\n .map(([prop, value]) => `${prop}=\"${value}\"`)\n .join(\"\")} />`;\n}\n\nexport function moduleTypeDeclarations(\n datasources: readonly DatasourceInfo[],\n): VirtualModules<`${string}.d.ts`> {\n if (!datasources.length) {\n return {};\n }\n\n const names = datasources.map((d) => d.name);\n\n const moduleId = \"nitro-drizzle/module\";\n\n const content = [\n genReference({ types: moduleId }),\n genAugmentation(moduleId, {\n DatasourceOptions: [\n {},\n {\n extends: `Record<${names.map((n) => genString(n)).join(\" | \")}, { connector: string; }>`,\n },\n ],\n }),\n /* ts */ `export {};`,\n ].join(\"\\n\");\n\n return {\n \"nitro-drizzle/module.d.ts\": content,\n };\n}\n\nexport function dialectDeclarations(datasources: readonly DatasourceInfo[]) {\n return datasources\n .filter((d) => d.enabled)\n .map(({ name, dialect }) => {\n return script /* ts */ `\n declare module \"#nitro-drizzle/dialects/${name}\" {\n ${genExport(`nitro-drizzle/dialects/${dialect}`, \"*\")}\n }\n `;\n })\n .join(\"\\n\");\n}\n"],"mappings":";;;AAWA,SAAgB,oBAAoB,aAAwC;CAC1E,IAAI,CAAC,YAAY,QACf,OAAO;CAGT,OAAO,CACL,cAAc,yBAAyB,CAAC,sBAAsB,CAAC,GAC/D,gBAAgB,yBAAyB,EACvC,oBAAoB,OAAO,YACzB,YACG,QAAQ,eAAe;EACtB,OAAO,WAAW;CACpB,CAAC,CAAC,CACD,KAAK,EAAE,MAAM,cAAgC;EAC5C,MAAM,aAAa,cAAc,QAAQ,MAAM;EAE/C,OAAO,CAAC,MAAM,wBAA6B,WAAW,IADnC,oBAAoB,QAAQ,SACoB,EAAE,GAAG,WAAW,GAAG;CACxF,CAAC,CACL,EACF,CAAC,CACH,CAAC,CAAC,KAAK,IAAI;AACb;AAEA,SAAS,cAAc,SAAmB;CACxC,OAAO,QAAQ,KAAK,OAAO,kBAAkB,GAAG,GAAG,CAAC,CAAC,KAAK,KAAK;AACjE;AAMA,SAAgB,aAAa,WAA0C;CACrE,OAAgB,kBAAkB,OAAO,QAAQ,SAAS,CAAC,CACxD,KAAK,CAAC,MAAM,WAAW,GAAG,KAAK,IAAI,MAAM,EAAE,CAAC,CAC5C,KAAK,EAAE,EAAE;AACd;AAEA,SAAgB,uBACd,aACkC;CAClC,IAAI,CAAC,YAAY,QACf,OAAO,CAAC;CAGV,MAAM,QAAQ,YAAY,KAAK,MAAM,EAAE,IAAI;CAE3C,MAAM,WAAW;CAejB,OAAO,EACL,6BAdc;EACd,aAAa,EAAE,OAAO,SAAS,CAAC;EAChC,gBAAgB,UAAU,EACxB,mBAAmB,CACjB,CAAC,GACD,EACE,SAAS,UAAU,MAAM,KAAK,MAAM,UAAU,CAAC,CAAC,CAAC,CAAC,KAAK,KAAK,EAAE,2BAChE,CACF,EACF,CAAC;EACQ;CACX,CAAC,CAAC,KAAK,IAG8B,EACrC;AACF;AAEA,SAAgB,oBAAoB,aAAwC;CAC1E,OAAO,YACJ,QAAQ,MAAM,EAAE,OAAO,CAAC,CACxB,KAAK,EAAE,MAAM,cAAc;EAC1B,OAAO,MAAgB;kDACqB,KAAK;YAC3C,UAAU,0BAA0B,WAAW,GAAG,EAAE;;;CAG5D,CAAC,CAAC,CACD,KAAK,IAAI;AACd"}
|