|
|
@@ -58,11 +58,11 @@ async function writePackage(
|
|
|
function typertSource(pkgName: string, entryName: string): string {
|
|
|
return [
|
|
|
'import { z } from \'zod\'',
|
|
|
- `export const ${entryName} = z.object({ id: z.string() })`,
|
|
|
+ `export const ${entryName} = () => z.object({ id: z.string() })`,
|
|
|
'export const TYPERT = {',
|
|
|
` package: '${pkgName}',`,
|
|
|
' face: \'host\',',
|
|
|
- ` schemas: [{ name: '${entryName}', schema: ${entryName} }],`,
|
|
|
+ ` schemas: [{ name: '${entryName}', create: ${entryName} }],`,
|
|
|
' model: { services: [], events: [], objects: [] },',
|
|
|
' invocations: [],',
|
|
|
'}',
|
|
|
@@ -73,7 +73,7 @@ function typertSource(pkgName: string, entryName: string): string {
|
|
|
function invocationTypertSource(pkgName: string): string {
|
|
|
return [
|
|
|
'import { z } from \'zod\'',
|
|
|
- 'const Text = z.string()',
|
|
|
+ 'const Text = () => z.string()',
|
|
|
'export const TYPERT = {',
|
|
|
` package: '${pkgName}',`,
|
|
|
' face: \'host\',',
|
|
|
@@ -85,10 +85,10 @@ function invocationTypertSource(pkgName: string): string {
|
|
|
' invocation: { kind: \'direct\' },',
|
|
|
' parameters: [{',
|
|
|
' name: \'request\', wire: \'request\', source: \'json\',',
|
|
|
- ` codec: { mode: 'strict', typeSymbol: '${pkgName}/types#Request', schema: Text },`,
|
|
|
+ ` codec: { mode: 'strict', typeSymbol: '${pkgName}/types#Request', create: Text },`,
|
|
|
' }],',
|
|
|
" cancellation: { parameter: 'signal' },",
|
|
|
- ` result: { mode: 'strict', typeSymbol: '${pkgName}/types#Result', schema: Text },`,
|
|
|
+ ` result: { mode: 'strict', typeSymbol: '${pkgName}/types#Result', create: Text },`,
|
|
|
' sourceLocation: { file: \'src/index.ts\', line: 8, column: 3 },',
|
|
|
' }],',
|
|
|
'}',
|
|
|
@@ -168,7 +168,7 @@ describe('typert loader', () => {
|
|
|
})
|
|
|
expect(descriptor?.parameters[0]?.codec.mode).toBe('strict')
|
|
|
if (descriptor?.parameters[0]?.codec.mode === 'strict') {
|
|
|
- expect(descriptor.parameters[0].codec.schema.parse('request')).toBe('request')
|
|
|
+ expect(descriptor.parameters[0].codec.create().parse('request')).toBe('request')
|
|
|
}
|
|
|
|
|
|
await fiber.dispose()
|
|
|
@@ -289,11 +289,11 @@ describe('typert loader', () => {
|
|
|
'import { z } from \'zod\'',
|
|
|
'globalThis.__dshTypertLoaderGate.started()',
|
|
|
'await globalThis.__dshTypertLoaderGate.wait',
|
|
|
- 'export const Pending = z.object({ id: z.string() })',
|
|
|
+ 'export const Pending = () => z.object({ id: z.string() })',
|
|
|
'export const TYPERT = {',
|
|
|
' package: \'@fixture/pending\',',
|
|
|
' face: \'host\',',
|
|
|
- ' schemas: [{ name: \'Pending\', schema: Pending }],',
|
|
|
+ ' schemas: [{ name: \'Pending\', create: Pending }],',
|
|
|
' model: { services: [], events: [], objects: [] },',
|
|
|
' invocations: [],',
|
|
|
'}',
|
|
|
@@ -329,7 +329,7 @@ describe('typert loader', () => {
|
|
|
root = await mkdtemp(join(tmpdir(), 'dsh-typert-loader-'))
|
|
|
await linkZod(root)
|
|
|
await writePackage(root, '@fixture/broken', {
|
|
|
- typertSource: 'export const TYPERT = { package: \'@fixture/broken\', face: \'host\', schemas: [{ name: \'\', schema: {} }], model: { services: [], events: [], objects: [] }, invocations: [] }\n',
|
|
|
+ typertSource: 'export const TYPERT = { package: \'@fixture/broken\', face: \'host\', schemas: [{ name: \'\', create: {} }], model: { services: [], events: [], objects: [] }, invocations: [] }\n',
|
|
|
})
|
|
|
const ctx = await boot()
|
|
|
await ctx.loader.create({ name: '@fixture/broken' })
|
|
|
@@ -443,7 +443,7 @@ describe('validateTypertManifest', () => {
|
|
|
expect(validateTypertManifest('pkg', {
|
|
|
package: 'pkg',
|
|
|
face: 'host',
|
|
|
- schemas: [{ name: 'A', schema: zodish }],
|
|
|
+ schemas: [{ name: 'A', create: () => zodish }],
|
|
|
model: { services: [], events: [], objects: [] },
|
|
|
invocations: [],
|
|
|
}).schemas).toHaveLength(1)
|
|
|
@@ -453,10 +453,10 @@ describe('validateTypertManifest', () => {
|
|
|
expect(() => validateTypertManifest('pkg', { package: 'pkg', face: 'client' })).toThrow('TYPERT.face is not "host"')
|
|
|
expect(() => validateTypertManifest('pkg', { package: 'pkg', face: 'host', schemas: 'x' })).toThrow('schemas must be an array')
|
|
|
expect(() => validateTypertManifest('pkg', { package: 'pkg', face: 'host', schemas: [null] })).toThrow('non-object schema')
|
|
|
- expect(() => validateTypertManifest('pkg', { package: 'pkg', face: 'host', schemas: [{ name: '', schema: zodish }] }))
|
|
|
+ expect(() => validateTypertManifest('pkg', { package: 'pkg', face: 'host', schemas: [{ name: '', create: () => zodish }] }))
|
|
|
.toThrow('missing or empty name')
|
|
|
- expect(() => validateTypertManifest('pkg', { package: 'pkg', face: 'host', schemas: [{ name: 'A', schema: {} }] }))
|
|
|
- .toThrow('not a zod v4 schema instance')
|
|
|
+ expect(() => validateTypertManifest('pkg', { package: 'pkg', face: 'host', schemas: [{ name: 'A', create: {} }] }))
|
|
|
+ .toThrow('has no create() factory')
|
|
|
expect(() => validateTypertManifest('pkg', {
|
|
|
package: 'pkg',
|
|
|
face: 'host',
|
|
|
@@ -572,8 +572,8 @@ describe('validateTypertManifest', () => {
|
|
|
})).toThrow('cancellation parameter must be "signal"')
|
|
|
expect(() => validateTypertManifest('pkg', {
|
|
|
...base,
|
|
|
- invocations: [{ ...descriptor, result: { mode: 'strict', typeSymbol: 'pkg#Result', schema: zodish } }],
|
|
|
- })).toThrow('result codec is not backed by a zod v4 schema')
|
|
|
+ invocations: [{ ...descriptor, result: { mode: 'strict', typeSymbol: 'pkg#Result', create: zodish } }],
|
|
|
+ })).toThrow('result codec has no create() factory')
|
|
|
expect(() => validateTypertManifest('pkg', {
|
|
|
...base,
|
|
|
invocations: [{
|
|
|
@@ -667,7 +667,7 @@ describe('validateTypertManifest', () => {
|
|
|
})
|
|
|
|
|
|
function strictCodec(typeSymbol: string) {
|
|
|
- return { mode: 'strict', typeSymbol, schema: z.string() }
|
|
|
+ return { mode: 'strict', typeSymbol, create: () => z.string() }
|
|
|
}
|
|
|
|
|
|
function strictInvocation() {
|
|
|
@@ -694,7 +694,7 @@ function completeManifest(zodish: object) {
|
|
|
return {
|
|
|
package: 'pkg',
|
|
|
face: 'host',
|
|
|
- schemas: [{ name: 'Schema', schema: zodish }],
|
|
|
+ schemas: [{ name: 'Schema', create: () => zodish }],
|
|
|
invocations: [],
|
|
|
model: {
|
|
|
services: [{
|