Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions core/daml-codegen-helpers/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"name": "@canton-network/core-daml-codegen-helpers",
Comment thread
PHOL-DA marked this conversation as resolved.
"version": "1.0.0",
"type": "module",
"description": "Helpers for combining Daml codegen TypeScript output with the Splice Wallet SDK.",
"license": "Apache-2.0",
"author": "Phillip Olesen <phillip.olesen@digitalasset.com>",
"packageManager": "yarn@4.9.4",
"main": "dist/index.cjs",
"module": "dist/index.js",
"types": "dist/index.d.ts",
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.js",
"require": "./dist/index.cjs",
"default": "./dist/index.js"
}
},
"scripts": {
"build": "tsup && tsc -p tsconfig.types.json",
"dev": "tsup --watch --onSuccess \"tsc -p tsconfig.types.json\"",
"clean": "tsc -b --clean; rm -rf dist",
"flatpack": "yarn pack --out \"$FLATPACK_OUTDIR\"",
"test": "vitest run --project node --project browser --passWithNoTests",
"test:coverage": "vitest run --project node --project browser --coverage --passWithNoTests"
},
"devDependencies": {
"@types/node": "^25.0.10",
"@vitest/browser-playwright": "^4.1.2",
"@vitest/coverage-v8": "^4.1.2",
"tsup": "^8.5.1",
"typescript": "^5.9.3",
"vitest": "^4.1.2"
},
"files": [
"dist/**"
],
"publishConfig": {
"access": "public"
},
"repository": {
"type": "git",
"url": "git+https://github.com/hyperledger-labs/splice-wallet-kernel.git",
"directory": "core/daml-codegen-helpers"
}
}
10 changes: 10 additions & 0 deletions core/daml-codegen-helpers/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright (c) 2025-2026 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

export {
type AcsContractLike,
type TypedAcsContract,
toTemplateContract,
toTemplateContracts,
expectTemplateContract,
} from './typed-contract.js'
62 changes: 62 additions & 0 deletions core/daml-codegen-helpers/src/typed-contract.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Copyright (c) 2025-2026 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

export type AcsContractLike = {
templateId: string
createArgument: unknown
}

export type TypedAcsContract<
TPayload,
TContract extends AcsContractLike = AcsContractLike,
> = Omit<TContract, 'createArgument'> & {
createArgument: TPayload
}

export function toTemplateContract<TPayload, TContract extends AcsContractLike>(
contract: TContract,
expectedTemplateId: string
): TypedAcsContract<TPayload, TContract> | undefined {
if (contract.templateId !== expectedTemplateId) {
return undefined
}

return contract as TypedAcsContract<TPayload, TContract>
}

export function toTemplateContracts<
TPayload,
TContract extends AcsContractLike,
>(
contracts: TContract[],
expectedTemplateId: string
): TypedAcsContract<TPayload, TContract>[] {
return contracts
.map((contract) =>
toTemplateContract<TPayload, TContract>(
contract,
expectedTemplateId
)
)
.filter(
(contract): contract is TypedAcsContract<TPayload, TContract> =>
contract !== undefined
)
}

export function expectTemplateContract<
TPayload,
TContract extends AcsContractLike,
>(
contract: TContract,
expectedTemplateId: string,
label: string
): TypedAcsContract<TPayload, TContract> {
if (contract.templateId !== expectedTemplateId) {
throw new Error(
`${label} expected template ${expectedTemplateId}, got ${contract.templateId}`
)
}

return contract as TypedAcsContract<TPayload, TContract>
}
8 changes: 8 additions & 0 deletions core/daml-codegen-helpers/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "../../tsconfig.web.json",
"compilerOptions": {
"rootDir": "./src",
"outDir": "./dist"
},
"include": ["src"]
}
15 changes: 15 additions & 0 deletions core/daml-codegen-helpers/tsconfig.types.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"extends": "../../tsconfig.web.json",
"compilerOptions": {
"emitDeclarationOnly": true,
"declaration": true,
"declarationMap": true,
"rootDir": "./src",
"outDir": "./dist",
"moduleResolution": "bundler",
"noEmit": false,
"composite": false
},
"include": ["src/**/*.ts", "src/**/*.d.ts"],
"exclude": ["**/*.test.*", "**/*.spec.*", "**/__tests__/**"]
}
10 changes: 10 additions & 0 deletions core/daml-codegen-helpers/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright (c) 2025-2026 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

import { defineConfig } from 'tsup'
import { base } from '../../tsup.base'

export default defineConfig({
...base,
entry: ['src/index.ts'],
})
48 changes: 48 additions & 0 deletions core/daml-codegen-helpers/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright (c) 2025-2026 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

import { defineConfig, defineProject } from 'vitest/config'
import { playwright } from '@vitest/browser-playwright'

export default defineConfig({
test: {
coverage: {
include: ['src/**/*.ts'],
provider: 'v8',
reporter: ['text', 'html', 'lcov'],
thresholds: {
lines: 0,
functions: 0,
branches: 0,
statements: 0,
},
},
environment: 'node',
include: ['src/**/*.test.ts'],
projects: [
defineProject({
test: {
name: 'node',
environment: 'node',
include: ['src/**/*.test.ts'],
},
}),
defineProject({
test: {
name: 'browser',
include: ['src/**/*.test.ts'],
browser: {
enabled: true,
provider: playwright({
trace: 'off',
screenshot: 'off',
video: 'off',
}),
instances: [{ browser: 'chromium' }],
headless: true,
},
},
}),
],
},
})
13 changes: 13 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1340,6 +1340,19 @@ __metadata:
languageName: unknown
linkType: soft

"@canton-network/core-daml-codegen-helpers@workspace:core/daml-codegen-helpers":
version: 0.0.0-use.local
resolution: "@canton-network/core-daml-codegen-helpers@workspace:core/daml-codegen-helpers"
dependencies:
"@types/node": "npm:^25.0.10"
"@vitest/browser-playwright": "npm:^4.1.2"
"@vitest/coverage-v8": "npm:^4.1.2"
tsup: "npm:^8.5.1"
typescript: "npm:^5.9.3"
vitest: "npm:^4.1.2"
languageName: unknown
linkType: soft

"@canton-network/core-ledger-client-types@workspace:^, @canton-network/core-ledger-client-types@workspace:core/ledger-client-types":
version: 0.0.0-use.local
resolution: "@canton-network/core-ledger-client-types@workspace:core/ledger-client-types"
Expand Down
Loading