@prisma-next/sql-contract-ts 0.12.0-dev.30 → 0.12.0-dev.31
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 +8 -0
- package/dist/config-types.d.mts +7 -3
- package/dist/config-types.d.mts.map +1 -1
- package/dist/config-types.mjs +11 -8
- package/dist/config-types.mjs.map +1 -1
- package/package.json +10 -10
- package/src/config-types.ts +24 -6
package/README.md
CHANGED
|
@@ -260,6 +260,14 @@ export default defineConfig({
|
|
|
260
260
|
});
|
|
261
261
|
```
|
|
262
262
|
|
|
263
|
+
Optional third argument (options bag) for `typescriptContract` / `typescriptContractFromPath`, and `defaultControlPolicy` on `emptyContract`:
|
|
264
|
+
|
|
265
|
+
```typescript
|
|
266
|
+
typescriptContract(contract, 'src/prisma/contract.json', { defaultControlPolicy: 'external' });
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
The specifier value applies only when the loaded contract omits `defaultControlPolicy` (a value authored on the contract module wins).
|
|
270
|
+
|
|
263
271
|
## Dependencies
|
|
264
272
|
|
|
265
273
|
- **`@prisma-next/config`** - `ContractConfig` types used by `typescriptContract(...)`
|
package/dist/config-types.d.mts
CHANGED
|
@@ -1,14 +1,18 @@
|
|
|
1
|
-
import { Contract } from "@prisma-next/contract/types";
|
|
1
|
+
import { Contract, ControlPolicy } from "@prisma-next/contract/types";
|
|
2
2
|
import { ContractConfig, ContractConfig as ContractConfig$1 } from "@prisma-next/config/config-types";
|
|
3
3
|
import { TargetPackRef } from "@prisma-next/framework-components/components";
|
|
4
4
|
|
|
5
5
|
//#region src/config-types.d.ts
|
|
6
|
+
interface TypeScriptContractSpecifierOptions {
|
|
7
|
+
readonly defaultControlPolicy?: ControlPolicy;
|
|
8
|
+
}
|
|
6
9
|
declare function emptyContract(options: {
|
|
7
10
|
readonly output?: string;
|
|
8
11
|
readonly target: TargetPackRef<'sql', string>;
|
|
12
|
+
readonly defaultControlPolicy?: ControlPolicy;
|
|
9
13
|
}): ContractConfig$1;
|
|
10
|
-
declare function typescriptContract(contract: Contract, output?: string): ContractConfig$1;
|
|
11
|
-
declare function typescriptContractFromPath(contractPath: string, output?: string): ContractConfig$1;
|
|
14
|
+
declare function typescriptContract(contract: Contract, output?: string, options?: TypeScriptContractSpecifierOptions): ContractConfig$1;
|
|
15
|
+
declare function typescriptContractFromPath(contractPath: string, output?: string, options?: TypeScriptContractSpecifierOptions): ContractConfig$1;
|
|
12
16
|
//#endregion
|
|
13
17
|
export { type ContractConfig, emptyContract, typescriptContract, typescriptContractFromPath };
|
|
14
18
|
//# sourceMappingURL=config-types.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config-types.d.mts","names":[],"sources":["../src/config-types.ts"],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"config-types.d.mts","names":[],"sources":["../src/config-types.ts"],"mappings":";;;;;UAsBiB,kCAAA;EAAA,SACN,oBAAA,GAAuB,aAAa;AAAA;AAAA,iBAG/B,aAAA,CAAc,OAAA;EAAA,SACnB,MAAA;EAAA,SACA,MAAA,EAAQ,aAAA;EAAA,SACR,oBAAA,GAAuB,aAAA;AAAA,IAC9B,gBAAA;AAAA,iBAYY,kBAAA,CACd,QAAA,EAAU,QAAA,EACV,MAAA,WACA,OAAA,GAAU,kCAAA,GACT,gBAAA;AAAA,iBAYa,0BAAA,CACd,YAAA,UACA,MAAA,WACA,OAAA,GAAU,kCAAA,GACT,gBAAc"}
|
package/dist/config-types.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { t as buildSqlContractFromDefinition } from "./build-contract-BDUH6Cu0.mjs";
|
|
2
2
|
import { ifDefined } from "@prisma-next/utils/defined";
|
|
3
3
|
import { pathToFileURL } from "node:url";
|
|
4
|
+
import { applySpecifierDefaultControlPolicy } from "@prisma-next/contract/apply-specifier-default-control-policy";
|
|
4
5
|
import { ok } from "@prisma-next/utils/result";
|
|
5
6
|
import { extname } from "pathe";
|
|
6
7
|
//#region src/config-types.ts
|
|
@@ -17,20 +18,22 @@ function defaultOutputFromContractPath(contractPath) {
|
|
|
17
18
|
}
|
|
18
19
|
function emptyContract(options) {
|
|
19
20
|
return {
|
|
20
|
-
source: { load: async () =>
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
source: { load: async () => {
|
|
22
|
+
return ok(applySpecifierDefaultControlPolicy(buildSqlContractFromDefinition({
|
|
23
|
+
target: options.target,
|
|
24
|
+
models: []
|
|
25
|
+
}), options.defaultControlPolicy));
|
|
26
|
+
} },
|
|
24
27
|
...ifDefined("output", options.output)
|
|
25
28
|
};
|
|
26
29
|
}
|
|
27
|
-
function typescriptContract(contract, output) {
|
|
30
|
+
function typescriptContract(contract, output, options) {
|
|
28
31
|
return {
|
|
29
|
-
source: { load: async () => ok(contract) },
|
|
32
|
+
source: { load: async () => ok(applySpecifierDefaultControlPolicy(contract, options?.defaultControlPolicy)) },
|
|
30
33
|
...ifDefined("output", output)
|
|
31
34
|
};
|
|
32
35
|
}
|
|
33
|
-
function typescriptContractFromPath(contractPath, output) {
|
|
36
|
+
function typescriptContractFromPath(contractPath, output, options) {
|
|
34
37
|
return {
|
|
35
38
|
source: {
|
|
36
39
|
inputs: [contractPath],
|
|
@@ -40,7 +43,7 @@ function typescriptContractFromPath(contractPath, output) {
|
|
|
40
43
|
const mod = await import(pathToFileURL(absolutePath).href);
|
|
41
44
|
const contract = mod.default ?? mod.contract;
|
|
42
45
|
if (contract === void 0) throw new Error(`typescriptContractFromPath: module at "${absolutePath}" has no "default" or "contract" export.`);
|
|
43
|
-
return ok(contract);
|
|
46
|
+
return ok(applySpecifierDefaultControlPolicy(contract, options?.defaultControlPolicy));
|
|
44
47
|
}
|
|
45
48
|
},
|
|
46
49
|
output: output ?? defaultOutputFromContractPath(contractPath)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config-types.mjs","names":[],"sources":["../src/config-types.ts"],"sourcesContent":["import { pathToFileURL } from 'node:url';\nimport type { ContractConfig } from '@prisma-next/config/config-types';\nimport type { Contract } from '@prisma-next/contract/types';\nimport type { TargetPackRef } from '@prisma-next/framework-components/components';\nimport { ifDefined } from '@prisma-next/utils/defined';\nimport { ok } from '@prisma-next/utils/result';\nimport { extname } from 'pathe';\nimport { buildSqlContractFromDefinition } from './build-contract';\n\n/**\n * Derives the emit output path from the TS contract input so artefacts land\n * colocated with the source (e.g. `prisma/contract.ts` →\n * `prisma/contract.json`). Mirrors the same default-derivation logic in\n * `@prisma-next/sql-contract-psl/provider`.\n */\nfunction defaultOutputFromContractPath(contractPath: string): string {\n const ext = extname(contractPath);\n if (ext.length === 0) return `${contractPath}.json`;\n return `${contractPath.slice(0, -ext.length)}.json`;\n}\n\nexport function emptyContract(options: {\n readonly output?: string;\n readonly target: TargetPackRef<'sql', string>;\n}): ContractConfig {\n return {\n source: {\n load: async () =>
|
|
1
|
+
{"version":3,"file":"config-types.mjs","names":[],"sources":["../src/config-types.ts"],"sourcesContent":["import { pathToFileURL } from 'node:url';\nimport type { ContractConfig } from '@prisma-next/config/config-types';\nimport { applySpecifierDefaultControlPolicy } from '@prisma-next/contract/apply-specifier-default-control-policy';\nimport type { Contract, ControlPolicy } from '@prisma-next/contract/types';\nimport type { TargetPackRef } from '@prisma-next/framework-components/components';\nimport { ifDefined } from '@prisma-next/utils/defined';\nimport { ok } from '@prisma-next/utils/result';\nimport { extname } from 'pathe';\nimport { buildSqlContractFromDefinition } from './build-contract';\n\n/**\n * Derives the emit output path from the TS contract input so artefacts land\n * colocated with the source (e.g. `prisma/contract.ts` →\n * `prisma/contract.json`). Mirrors the same default-derivation logic in\n * `@prisma-next/sql-contract-psl/provider`.\n */\nfunction defaultOutputFromContractPath(contractPath: string): string {\n const ext = extname(contractPath);\n if (ext.length === 0) return `${contractPath}.json`;\n return `${contractPath.slice(0, -ext.length)}.json`;\n}\n\nexport interface TypeScriptContractSpecifierOptions {\n readonly defaultControlPolicy?: ControlPolicy;\n}\n\nexport function emptyContract(options: {\n readonly output?: string;\n readonly target: TargetPackRef<'sql', string>;\n readonly defaultControlPolicy?: ControlPolicy;\n}): ContractConfig {\n return {\n source: {\n load: async () => {\n const built = buildSqlContractFromDefinition({ target: options.target, models: [] });\n return ok(applySpecifierDefaultControlPolicy(built, options.defaultControlPolicy));\n },\n },\n ...ifDefined('output', options.output),\n };\n}\n\nexport function typescriptContract(\n contract: Contract,\n output?: string,\n options?: TypeScriptContractSpecifierOptions,\n): ContractConfig {\n return {\n source: {\n load: async () =>\n ok(applySpecifierDefaultControlPolicy(contract, options?.defaultControlPolicy)),\n },\n // The in-memory variant has no input path to anchor on; fall through to\n // the global default in `normalizeContractConfig` when caller doesn't pin it.\n ...ifDefined('output', output),\n };\n}\n\nexport function typescriptContractFromPath(\n contractPath: string,\n output?: string,\n options?: TypeScriptContractSpecifierOptions,\n): ContractConfig {\n return {\n source: {\n inputs: [contractPath],\n load: async (context) => {\n const [absolutePath] = context.resolvedInputs;\n if (absolutePath === undefined) {\n throw new Error(\n 'typescriptContractFromPath: context.resolvedInputs is empty. The CLI config loader should populate it positional-matched with source.inputs.',\n );\n }\n const mod = await import(pathToFileURL(absolutePath).href);\n const contract: Contract | undefined = mod.default ?? mod.contract;\n if (contract === undefined) {\n throw new Error(\n `typescriptContractFromPath: module at \"${absolutePath}\" has no \"default\" or \"contract\" export.`,\n );\n }\n return ok(applySpecifierDefaultControlPolicy(contract, options?.defaultControlPolicy));\n },\n },\n output: output ?? defaultOutputFromContractPath(contractPath),\n };\n}\n"],"mappings":";;;;;;;;;;;;;AAgBA,SAAS,8BAA8B,cAA8B;CACnE,MAAM,MAAM,QAAQ,YAAY;CAChC,IAAI,IAAI,WAAW,GAAG,OAAO,GAAG,aAAa;CAC7C,OAAO,GAAG,aAAa,MAAM,GAAG,CAAC,IAAI,MAAM,EAAE;AAC/C;AAMA,SAAgB,cAAc,SAIX;CACjB,OAAO;EACL,QAAQ,EACN,MAAM,YAAY;GAEhB,OAAO,GAAG,mCADI,+BAA+B;IAAE,QAAQ,QAAQ;IAAQ,QAAQ,CAAC;GAAE,CACjC,GAAG,QAAQ,oBAAoB,CAAC;EACnF,EACF;EACA,GAAG,UAAU,UAAU,QAAQ,MAAM;CACvC;AACF;AAEA,SAAgB,mBACd,UACA,QACA,SACgB;CAChB,OAAO;EACL,QAAQ,EACN,MAAM,YACJ,GAAG,mCAAmC,UAAU,SAAS,oBAAoB,CAAC,EAClF;EAGA,GAAG,UAAU,UAAU,MAAM;CAC/B;AACF;AAEA,SAAgB,2BACd,cACA,QACA,SACgB;CAChB,OAAO;EACL,QAAQ;GACN,QAAQ,CAAC,YAAY;GACrB,MAAM,OAAO,YAAY;IACvB,MAAM,CAAC,gBAAgB,QAAQ;IAC/B,IAAI,iBAAiB,KAAA,GACnB,MAAM,IAAI,MACR,8IACF;IAEF,MAAM,MAAM,MAAM,OAAO,cAAc,YAAY,EAAE;IACrD,MAAM,WAAiC,IAAI,WAAW,IAAI;IAC1D,IAAI,aAAa,KAAA,GACf,MAAM,IAAI,MACR,0CAA0C,aAAa,yCACzD;IAEF,OAAO,GAAG,mCAAmC,UAAU,SAAS,oBAAoB,CAAC;GACvF;EACF;EACA,QAAQ,UAAU,8BAA8B,YAAY;CAC9D;AACF"}
|
package/package.json
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma-next/sql-contract-ts",
|
|
3
|
-
"version": "0.12.0-dev.
|
|
3
|
+
"version": "0.12.0-dev.31",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"description": "SQL-specific TypeScript contract authoring surface for Prisma Next",
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@prisma-next/config": "0.12.0-dev.
|
|
10
|
-
"@prisma-next/contract": "0.12.0-dev.
|
|
11
|
-
"@prisma-next/contract-authoring": "0.12.0-dev.
|
|
12
|
-
"@prisma-next/framework-components": "0.12.0-dev.
|
|
13
|
-
"@prisma-next/sql-contract": "0.12.0-dev.
|
|
14
|
-
"@prisma-next/utils": "0.12.0-dev.
|
|
9
|
+
"@prisma-next/config": "0.12.0-dev.31",
|
|
10
|
+
"@prisma-next/contract": "0.12.0-dev.31",
|
|
11
|
+
"@prisma-next/contract-authoring": "0.12.0-dev.31",
|
|
12
|
+
"@prisma-next/framework-components": "0.12.0-dev.31",
|
|
13
|
+
"@prisma-next/sql-contract": "0.12.0-dev.31",
|
|
14
|
+
"@prisma-next/utils": "0.12.0-dev.31",
|
|
15
15
|
"arktype": "^2.2.0",
|
|
16
16
|
"pathe": "^2.0.3",
|
|
17
17
|
"ts-toolbelt": "^9.6.0"
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
20
|
-
"@prisma-next/test-utils": "0.12.0-dev.
|
|
21
|
-
"@prisma-next/tsconfig": "0.12.0-dev.
|
|
20
|
+
"@prisma-next/test-utils": "0.12.0-dev.31",
|
|
21
|
+
"@prisma-next/tsconfig": "0.12.0-dev.31",
|
|
22
22
|
"@types/pg": "8.20.0",
|
|
23
23
|
"pg": "8.20.0",
|
|
24
|
-
"@prisma-next/tsdown": "0.12.0-dev.
|
|
24
|
+
"@prisma-next/tsdown": "0.12.0-dev.31",
|
|
25
25
|
"tsdown": "0.22.0",
|
|
26
26
|
"typescript": "5.9.3",
|
|
27
27
|
"vitest": "4.1.6"
|
package/src/config-types.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { pathToFileURL } from 'node:url';
|
|
2
2
|
import type { ContractConfig } from '@prisma-next/config/config-types';
|
|
3
|
-
import
|
|
3
|
+
import { applySpecifierDefaultControlPolicy } from '@prisma-next/contract/apply-specifier-default-control-policy';
|
|
4
|
+
import type { Contract, ControlPolicy } from '@prisma-next/contract/types';
|
|
4
5
|
import type { TargetPackRef } from '@prisma-next/framework-components/components';
|
|
5
6
|
import { ifDefined } from '@prisma-next/utils/defined';
|
|
6
7
|
import { ok } from '@prisma-next/utils/result';
|
|
@@ -19,22 +20,35 @@ function defaultOutputFromContractPath(contractPath: string): string {
|
|
|
19
20
|
return `${contractPath.slice(0, -ext.length)}.json`;
|
|
20
21
|
}
|
|
21
22
|
|
|
23
|
+
export interface TypeScriptContractSpecifierOptions {
|
|
24
|
+
readonly defaultControlPolicy?: ControlPolicy;
|
|
25
|
+
}
|
|
26
|
+
|
|
22
27
|
export function emptyContract(options: {
|
|
23
28
|
readonly output?: string;
|
|
24
29
|
readonly target: TargetPackRef<'sql', string>;
|
|
30
|
+
readonly defaultControlPolicy?: ControlPolicy;
|
|
25
31
|
}): ContractConfig {
|
|
26
32
|
return {
|
|
27
33
|
source: {
|
|
28
|
-
load: async () =>
|
|
34
|
+
load: async () => {
|
|
35
|
+
const built = buildSqlContractFromDefinition({ target: options.target, models: [] });
|
|
36
|
+
return ok(applySpecifierDefaultControlPolicy(built, options.defaultControlPolicy));
|
|
37
|
+
},
|
|
29
38
|
},
|
|
30
39
|
...ifDefined('output', options.output),
|
|
31
40
|
};
|
|
32
41
|
}
|
|
33
42
|
|
|
34
|
-
export function typescriptContract(
|
|
43
|
+
export function typescriptContract(
|
|
44
|
+
contract: Contract,
|
|
45
|
+
output?: string,
|
|
46
|
+
options?: TypeScriptContractSpecifierOptions,
|
|
47
|
+
): ContractConfig {
|
|
35
48
|
return {
|
|
36
49
|
source: {
|
|
37
|
-
load: async () =>
|
|
50
|
+
load: async () =>
|
|
51
|
+
ok(applySpecifierDefaultControlPolicy(contract, options?.defaultControlPolicy)),
|
|
38
52
|
},
|
|
39
53
|
// The in-memory variant has no input path to anchor on; fall through to
|
|
40
54
|
// the global default in `normalizeContractConfig` when caller doesn't pin it.
|
|
@@ -42,7 +56,11 @@ export function typescriptContract(contract: Contract, output?: string): Contrac
|
|
|
42
56
|
};
|
|
43
57
|
}
|
|
44
58
|
|
|
45
|
-
export function typescriptContractFromPath(
|
|
59
|
+
export function typescriptContractFromPath(
|
|
60
|
+
contractPath: string,
|
|
61
|
+
output?: string,
|
|
62
|
+
options?: TypeScriptContractSpecifierOptions,
|
|
63
|
+
): ContractConfig {
|
|
46
64
|
return {
|
|
47
65
|
source: {
|
|
48
66
|
inputs: [contractPath],
|
|
@@ -60,7 +78,7 @@ export function typescriptContractFromPath(contractPath: string, output?: string
|
|
|
60
78
|
`typescriptContractFromPath: module at "${absolutePath}" has no "default" or "contract" export.`,
|
|
61
79
|
);
|
|
62
80
|
}
|
|
63
|
-
return ok(contract);
|
|
81
|
+
return ok(applySpecifierDefaultControlPolicy(contract, options?.defaultControlPolicy));
|
|
64
82
|
},
|
|
65
83
|
},
|
|
66
84
|
output: output ?? defaultOutputFromContractPath(contractPath),
|