@solidxai/core 0.1.21-beta.0 → 0.1.21
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/CHANGELOG.md +74 -0
- package/agenthub-ui-json-seed-audit.md +151 -0
- package/dist/commands/run-tests.command.d.ts +2 -0
- package/dist/commands/run-tests.command.d.ts.map +1 -1
- package/dist/commands/run-tests.command.js +16 -0
- package/dist/commands/run-tests.command.js.map +1 -1
- package/dist/constants/error-messages.js +1 -1
- package/dist/constants/error-messages.js.map +1 -1
- package/dist/controllers/agent-config-version.controller.d.ts +93 -0
- package/dist/controllers/agent-config-version.controller.d.ts.map +1 -0
- package/dist/controllers/agent-config-version.controller.js +211 -0
- package/dist/controllers/agent-config-version.controller.js.map +1 -0
- package/dist/controllers/agent-registry.controller.d.ts +2 -0
- package/dist/controllers/agent-registry.controller.d.ts.map +1 -1
- package/dist/controllers/agent-registry.controller.js +14 -0
- package/dist/controllers/agent-registry.controller.js.map +1 -1
- package/dist/controllers/agent-session.controller.d.ts +18 -0
- package/dist/controllers/agent-session.controller.d.ts.map +1 -1
- package/dist/controllers/agent-session.controller.js +18 -0
- package/dist/controllers/agent-session.controller.js.map +1 -1
- package/dist/controllers/agent-user-memory.controller.d.ts +16 -0
- package/dist/controllers/agent-user-memory.controller.d.ts.map +1 -0
- package/dist/controllers/agent-user-memory.controller.js +135 -0
- package/dist/controllers/agent-user-memory.controller.js.map +1 -0
- package/dist/dtos/activate-agent-registry.dto.d.ts +5 -0
- package/dist/dtos/activate-agent-registry.dto.d.ts.map +1 -0
- package/dist/dtos/activate-agent-registry.dto.js +34 -0
- package/dist/dtos/activate-agent-registry.dto.js.map +1 -0
- package/dist/dtos/create-agent-config-version.dto.d.ts +8 -0
- package/dist/dtos/create-agent-config-version.dto.d.ts.map +1 -0
- package/dist/dtos/create-agent-config-version.dto.js +50 -0
- package/dist/dtos/create-agent-config-version.dto.js.map +1 -0
- package/dist/dtos/create-agent-user-memory.dto.d.ts +8 -0
- package/dist/dtos/create-agent-user-memory.dto.d.ts.map +1 -0
- package/dist/dtos/create-agent-user-memory.dto.js +52 -0
- package/dist/dtos/create-agent-user-memory.dto.js.map +1 -0
- package/dist/dtos/create-secret.dto.d.ts +2 -0
- package/dist/dtos/create-secret.dto.d.ts.map +1 -1
- package/dist/dtos/create-secret.dto.js +13 -1
- package/dist/dtos/create-secret.dto.js.map +1 -1
- package/dist/dtos/test-run-request.dto.d.ts +1 -0
- package/dist/dtos/test-run-request.dto.d.ts.map +1 -1
- package/dist/dtos/test-run-request.dto.js +6 -1
- package/dist/dtos/test-run-request.dto.js.map +1 -1
- package/dist/dtos/update-agent-config-version.dto.d.ts +9 -0
- package/dist/dtos/update-agent-config-version.dto.d.ts.map +1 -0
- package/dist/dtos/update-agent-config-version.dto.js +58 -0
- package/dist/dtos/update-agent-config-version.dto.js.map +1 -0
- package/dist/dtos/update-agent-user-memory.dto.d.ts +9 -0
- package/dist/dtos/update-agent-user-memory.dto.d.ts.map +1 -0
- package/dist/dtos/update-agent-user-memory.dto.js +58 -0
- package/dist/dtos/update-agent-user-memory.dto.js.map +1 -0
- package/dist/dtos/update-secret.dto.d.ts +2 -0
- package/dist/dtos/update-secret.dto.d.ts.map +1 -1
- package/dist/dtos/update-secret.dto.js +13 -1
- package/dist/dtos/update-secret.dto.js.map +1 -1
- package/dist/entities/agent-config-version.entity.d.ts +9 -0
- package/dist/entities/agent-config-version.entity.d.ts.map +1 -0
- package/dist/entities/agent-config-version.entity.js +44 -0
- package/dist/entities/agent-config-version.entity.js.map +1 -0
- package/dist/entities/agent-hub-tag.entity.js +1 -1
- package/dist/entities/agent-hub-tag.entity.js.map +1 -1
- package/dist/entities/agent-registry.entity.d.ts +2 -0
- package/dist/entities/agent-registry.entity.d.ts.map +1 -1
- package/dist/entities/agent-registry.entity.js +7 -2
- package/dist/entities/agent-registry.entity.js.map +1 -1
- package/dist/entities/agent-session.entity.d.ts.map +1 -1
- package/dist/entities/agent-session.entity.js.map +1 -1
- package/dist/entities/agent-skill-registry.entity.js +1 -1
- package/dist/entities/agent-skill-registry.entity.js.map +1 -1
- package/dist/entities/agent-tool-registry.entity.js +1 -1
- package/dist/entities/agent-tool-registry.entity.js.map +1 -1
- package/dist/entities/agent-user-memory.entity.d.ts +12 -0
- package/dist/entities/agent-user-memory.entity.d.ts.map +1 -0
- package/dist/entities/agent-user-memory.entity.js +51 -0
- package/dist/entities/agent-user-memory.entity.js.map +1 -0
- package/dist/entities/secret.entity.d.ts +2 -0
- package/dist/entities/secret.entity.d.ts.map +1 -1
- package/dist/entities/secret.entity.js +7 -1
- package/dist/entities/secret.entity.js.map +1 -1
- package/dist/helpers/module-metadata-helper.service.js +1 -1
- package/dist/helpers/module-metadata-helper.service.js.map +1 -1
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -1
- package/dist/jobs/database/test-run-queue-subscriber-database.service.d.ts.map +1 -1
- package/dist/jobs/database/test-run-queue-subscriber-database.service.js +1 -0
- package/dist/jobs/database/test-run-queue-subscriber-database.service.js.map +1 -1
- package/dist/repository/agent-config-version.repository.d.ts +12 -0
- package/dist/repository/agent-config-version.repository.d.ts.map +1 -0
- package/dist/repository/agent-config-version.repository.js +39 -0
- package/dist/repository/agent-config-version.repository.js.map +1 -0
- package/dist/repository/agent-user-memory.repository.d.ts +12 -0
- package/dist/repository/agent-user-memory.repository.d.ts.map +1 -0
- package/dist/repository/agent-user-memory.repository.js +39 -0
- package/dist/repository/agent-user-memory.repository.js.map +1 -0
- package/dist/resources/agent-embed/solid-agent-embed.js +7 -1
- package/dist/seeders/module-metadata-agenthub.spec.js +52 -3
- package/dist/seeders/module-metadata-agenthub.spec.js.map +1 -1
- package/dist/seeders/module-metadata-seeder.service.d.ts +1 -1
- package/dist/seeders/module-metadata-seeder.service.d.ts.map +1 -1
- package/dist/seeders/module-metadata-seeder.service.js +87 -45
- package/dist/seeders/module-metadata-seeder.service.js.map +1 -1
- package/dist/seeders/seed-data/solid-core-metadata.json +833 -37
- package/dist/services/agent-config-version-record.service.d.ts +81 -0
- package/dist/services/agent-config-version-record.service.d.ts.map +1 -0
- package/dist/services/agent-config-version-record.service.js +308 -0
- package/dist/services/agent-config-version-record.service.js.map +1 -0
- package/dist/services/agent-config-version.service.d.ts +1 -1
- package/dist/services/agent-config-version.service.d.ts.map +1 -1
- package/dist/services/agent-config-version.service.js +14 -15
- package/dist/services/agent-config-version.service.js.map +1 -1
- package/dist/services/agent-registry.service.d.ts +2 -0
- package/dist/services/agent-registry.service.d.ts.map +1 -1
- package/dist/services/agent-registry.service.js +27 -1
- package/dist/services/agent-registry.service.js.map +1 -1
- package/dist/services/agent-session.service.d.ts +21 -1
- package/dist/services/agent-session.service.d.ts.map +1 -1
- package/dist/services/agent-session.service.js +78 -2
- package/dist/services/agent-session.service.js.map +1 -1
- package/dist/services/agent-user-memory.service.d.ts +12 -0
- package/dist/services/agent-user-memory.service.d.ts.map +1 -0
- package/dist/services/agent-user-memory.service.js +38 -0
- package/dist/services/agent-user-memory.service.js.map +1 -0
- package/dist/services/secret.service.js +3 -3
- package/dist/services/secret.service.js.map +1 -1
- package/dist/services/settings/default-settings-provider.service.d.ts +2 -2
- package/dist/services/settings/default-settings-provider.service.js +1 -1
- package/dist/services/settings/default-settings-provider.service.js.map +1 -1
- package/dist/services/view-metadata.service.d.ts.map +1 -1
- package/dist/services/view-metadata.service.js +14 -5
- package/dist/services/view-metadata.service.js.map +1 -1
- package/dist/solid-core.module.d.ts.map +1 -1
- package/dist/solid-core.module.js +25 -3
- package/dist/solid-core.module.js.map +1 -1
- package/dist/subscribers/agent-hub-tag.subscriber.d.ts +9 -5
- package/dist/subscribers/agent-hub-tag.subscriber.d.ts.map +1 -1
- package/dist/subscribers/agent-hub-tag.subscriber.js +100 -88
- package/dist/subscribers/agent-hub-tag.subscriber.js.map +1 -1
- package/dist/subscribers/agent-registry-subscribers.spec.js +158 -6
- package/dist/subscribers/agent-registry-subscribers.spec.js.map +1 -1
- package/dist/subscribers/agent-registry.subscriber.d.ts +16 -6
- package/dist/subscribers/agent-registry.subscriber.d.ts.map +1 -1
- package/dist/subscribers/agent-registry.subscriber.js +191 -60
- package/dist/subscribers/agent-registry.subscriber.js.map +1 -1
- package/dist/subscribers/agent-role.subscriber.d.ts +19 -0
- package/dist/subscribers/agent-role.subscriber.d.ts.map +1 -0
- package/dist/subscribers/agent-role.subscriber.js +112 -0
- package/dist/subscribers/agent-role.subscriber.js.map +1 -0
- package/dist/subscribers/agent-secret.subscriber.d.ts +19 -0
- package/dist/subscribers/agent-secret.subscriber.d.ts.map +1 -0
- package/dist/subscribers/agent-secret.subscriber.js +112 -0
- package/dist/subscribers/agent-secret.subscriber.js.map +1 -0
- package/dist/subscribers/agent-skill-registry.subscriber.d.ts +12 -4
- package/dist/subscribers/agent-skill-registry.subscriber.d.ts.map +1 -1
- package/dist/subscribers/agent-skill-registry.subscriber.js +137 -79
- package/dist/subscribers/agent-skill-registry.subscriber.js.map +1 -1
- package/dist/subscribers/agent-skill.subscriber.d.ts +8 -2
- package/dist/subscribers/agent-skill.subscriber.d.ts.map +1 -1
- package/dist/subscribers/agent-skill.subscriber.js +59 -8
- package/dist/subscribers/agent-skill.subscriber.js.map +1 -1
- package/dist/subscribers/agent-tool-registry.subscriber.d.ts +12 -4
- package/dist/subscribers/agent-tool-registry.subscriber.d.ts.map +1 -1
- package/dist/subscribers/agent-tool-registry.subscriber.js +138 -80
- package/dist/subscribers/agent-tool-registry.subscriber.js.map +1 -1
- package/dist/subscribers/agent-tool.subscriber.d.ts +8 -2
- package/dist/subscribers/agent-tool.subscriber.d.ts.map +1 -1
- package/dist/subscribers/agent-tool.subscriber.js +59 -8
- package/dist/subscribers/agent-tool.subscriber.js.map +1 -1
- package/dist/subscribers/agenthub-metadata-sync.util.d.ts +0 -9
- package/dist/subscribers/agenthub-metadata-sync.util.d.ts.map +1 -1
- package/dist/subscribers/agenthub-metadata-sync.util.js +21 -14
- package/dist/subscribers/agenthub-metadata-sync.util.js.map +1 -1
- package/dist/subscribers/secret.subscriber.d.ts +26 -0
- package/dist/subscribers/secret.subscriber.d.ts.map +1 -0
- package/dist/subscribers/secret.subscriber.js +236 -0
- package/dist/subscribers/secret.subscriber.js.map +1 -0
- package/dist/testing/contracts/runtime-context.types.d.ts +2 -0
- package/dist/testing/contracts/runtime-context.types.d.ts.map +1 -1
- package/dist/testing/contracts/runtime-context.types.js.map +1 -1
- package/dist/testing/core/call-args.d.ts +18 -0
- package/dist/testing/core/call-args.d.ts.map +1 -0
- package/dist/testing/core/call-args.js +133 -0
- package/dist/testing/core/call-args.js.map +1 -0
- package/dist/testing/core/dates.d.ts +27 -0
- package/dist/testing/core/dates.d.ts.map +1 -0
- package/dist/testing/core/dates.js +151 -0
- package/dist/testing/core/dates.js.map +1 -0
- package/dist/testing/core/dates.spec.d.ts +2 -0
- package/dist/testing/core/dates.spec.d.ts.map +1 -0
- package/dist/testing/core/dates.spec.js +246 -0
- package/dist/testing/core/dates.spec.js.map +1 -0
- package/dist/testing/core/interpolation.d.ts +4 -1
- package/dist/testing/core/interpolation.d.ts.map +1 -1
- package/dist/testing/core/interpolation.js +56 -27
- package/dist/testing/core/interpolation.js.map +1 -1
- package/dist/testing/core/random-data.d.ts +12 -0
- package/dist/testing/core/random-data.d.ts.map +1 -0
- package/dist/testing/core/random-data.js +270 -0
- package/dist/testing/core/random-data.js.map +1 -0
- package/dist/testing/core/random-data.spec.d.ts +2 -0
- package/dist/testing/core/random-data.spec.d.ts.map +1 -0
- package/dist/testing/core/random-data.spec.js +198 -0
- package/dist/testing/core/random-data.spec.js.map +1 -0
- package/dist/testing/core/random-names.d.ts +4 -0
- package/dist/testing/core/random-names.d.ts.map +1 -0
- package/dist/testing/core/random-names.js +50 -0
- package/dist/testing/core/random-names.js.map +1 -0
- package/dist/testing/core/step-registry.d.ts +6 -1
- package/dist/testing/core/step-registry.d.ts.map +1 -1
- package/dist/testing/core/step-registry.js +8 -1
- package/dist/testing/core/step-registry.js.map +1 -1
- package/dist/testing/core/testing-engine.d.ts +1 -0
- package/dist/testing/core/testing-engine.d.ts.map +1 -1
- package/dist/testing/core/testing-engine.js +15 -1
- package/dist/testing/core/testing-engine.js.map +1 -1
- package/dist/testing/core/token-scan.d.ts +8 -0
- package/dist/testing/core/token-scan.d.ts.map +1 -0
- package/dist/testing/core/token-scan.js +70 -0
- package/dist/testing/core/token-scan.js.map +1 -0
- package/dist/testing/runner/run-from-metadata.d.ts +1 -0
- package/dist/testing/runner/run-from-metadata.d.ts.map +1 -1
- package/dist/testing/runner/run-from-metadata.js +10 -3
- package/dist/testing/runner/run-from-metadata.js.map +1 -1
- package/dist/testing/runner/run-from-metadata.spec.d.ts +2 -0
- package/dist/testing/runner/run-from-metadata.spec.d.ts.map +1 -0
- package/dist/testing/runner/run-from-metadata.spec.js +62 -0
- package/dist/testing/runner/run-from-metadata.spec.js.map +1 -0
- package/dist/testing/steps/util/index.d.ts.map +1 -1
- package/dist/testing/steps/util/index.js +6 -0
- package/dist/testing/steps/util/index.js.map +1 -1
- package/dist/testing/steps/util/now.step.d.ts +3 -0
- package/dist/testing/steps/util/now.step.d.ts.map +1 -0
- package/dist/testing/steps/util/now.step.js +15 -0
- package/dist/testing/steps/util/now.step.js.map +1 -0
- package/dist/testing/steps/util/random.step.d.ts +3 -0
- package/dist/testing/steps/util/random.step.d.ts.map +1 -0
- package/dist/testing/steps/util/random.step.js +18 -0
- package/dist/testing/steps/util/random.step.js.map +1 -0
- package/dist/testing/steps/util/script.step.d.ts +3 -0
- package/dist/testing/steps/util/script.step.d.ts.map +1 -0
- package/dist/testing/steps/util/script.step.js +221 -0
- package/dist/testing/steps/util/script.step.js.map +1 -0
- package/dist/testing/steps/util/script.step.spec.d.ts +2 -0
- package/dist/testing/steps/util/script.step.spec.d.ts.map +1 -0
- package/dist/testing/steps/util/script.step.spec.js +205 -0
- package/dist/testing/steps/util/script.step.spec.js.map +1 -0
- package/package.json +1 -1
- package/resources/agent-embed/solid-agent-embed.js +7 -1
- package/src/commands/run-tests.command.ts +12 -0
- package/src/constants/error-messages.ts +1 -1
- package/src/controllers/agent-config-version.controller.ts +114 -0
- package/src/controllers/agent-registry.controller.ts +7 -0
- package/src/controllers/agent-session.controller.ts +16 -1
- package/src/controllers/agent-user-memory.controller.ts +32 -0
- package/src/dtos/activate-agent-registry.dto.ts +14 -0
- package/src/dtos/create-agent-config-version.dto.ts +27 -0
- package/src/dtos/create-agent-user-memory.dto.ts +10 -0
- package/src/dtos/create-secret.dto.ts +11 -1
- package/src/dtos/test-run-request.dto.ts +4 -0
- package/src/dtos/update-agent-config-version.dto.ts +34 -0
- package/src/dtos/update-agent-user-memory.dto.ts +11 -0
- package/src/dtos/update-secret.dto.ts +10 -0
- package/src/entities/agent-config-version.entity.ts +20 -0
- package/src/entities/agent-hub-tag.entity.ts +1 -1
- package/src/entities/agent-registry.entity.ts +5 -1
- package/src/entities/agent-session.entity.ts +1 -0
- package/src/entities/agent-skill-registry.entity.ts +1 -1
- package/src/entities/agent-tool-registry.entity.ts +1 -1
- package/src/entities/agent-user-memory.entity.ts +26 -0
- package/src/entities/secret.entity.ts +6 -1
- package/src/helpers/module-metadata-helper.service.ts +1 -1
- package/src/index.ts +13 -0
- package/src/jobs/database/test-run-queue-subscriber-database.service.ts +1 -0
- package/src/repository/agent-config-version.repository.ts +19 -0
- package/src/repository/agent-user-memory.repository.ts +18 -0
- package/src/seeders/module-metadata-agenthub.spec.ts +58 -3
- package/src/seeders/module-metadata-seeder.service.ts +85 -44
- package/src/seeders/seed-data/solid-core-metadata.json +833 -37
- package/src/services/agent-config-version-record.service.ts +317 -0
- package/src/services/agent-config-version.service.ts +24 -10
- package/src/services/agent-registry.service.ts +32 -3
- package/src/services/agent-session.service.ts +75 -2
- package/src/services/agent-user-memory.service.ts +18 -0
- package/src/services/secret.service.ts +4 -4
- package/src/services/settings/default-settings-provider.service.ts +1 -1
- package/src/services/view-metadata.service.ts +17 -5
- package/src/solid-core.module.ts +25 -3
- package/src/subscribers/agent-hub-tag.subscriber.ts +154 -93
- package/src/subscribers/agent-registry-subscribers.spec.ts +163 -6
- package/src/subscribers/agent-registry.subscriber.ts +202 -58
- package/src/subscribers/agent-role.subscriber.ts +105 -0
- package/src/subscribers/agent-secret.subscriber.ts +105 -0
- package/src/subscribers/agent-skill-registry.subscriber.ts +144 -75
- package/src/subscribers/agent-skill.subscriber.ts +68 -9
- package/src/subscribers/agent-tool-registry.subscriber.ts +145 -76
- package/src/subscribers/agent-tool.subscriber.ts +68 -9
- package/src/subscribers/agenthub-metadata-sync.util.ts +19 -13
- package/src/subscribers/secret.subscriber.ts +192 -0
- package/src/testing/README.md +199 -0
- package/src/testing/contracts/runtime-context.types.ts +3 -0
- package/src/testing/core/call-args.ts +154 -0
- package/src/testing/core/dates.spec.ts +311 -0
- package/src/testing/core/dates.ts +198 -0
- package/src/testing/core/interpolation.ts +67 -28
- package/src/testing/core/random-data.spec.ts +253 -0
- package/src/testing/core/random-data.ts +326 -0
- package/src/testing/core/random-names.ts +54 -0
- package/src/testing/core/step-registry.ts +18 -1
- package/src/testing/core/testing-engine.ts +16 -1
- package/src/testing/core/token-scan.ts +72 -0
- package/src/testing/runner/run-from-metadata.spec.ts +82 -0
- package/src/testing/runner/run-from-metadata.ts +15 -3
- package/src/testing/steps/util/index.ts +6 -0
- package/src/testing/steps/util/now.step.ts +19 -0
- package/src/testing/steps/util/random.step.ts +23 -0
- package/src/testing/steps/util/script.step.spec.ts +269 -0
- package/src/testing/steps/util/script.step.ts +242 -0
package/src/testing/README.md
CHANGED
|
@@ -146,9 +146,14 @@ Available tokens:
|
|
|
146
146
|
- `${env:NAME}` (environment variables)
|
|
147
147
|
- `${params.foo}` (scenario params)
|
|
148
148
|
- `${res:saveAs.path}` (saved step results)
|
|
149
|
+
- `${random:<generator>}` or `${random:<generator>(name=value, ...)}` (random test data; see below)
|
|
150
|
+
- `${now:<kind>}` or `${now:<kind>(offset=+7d, format=DD/MM/YYYY)}` (the current date or time; see below)
|
|
149
151
|
- `${data:modelUserKey["recUserKeyValue"].field}` (test data from `testing.data`)
|
|
150
152
|
- `${data:modelUserKey["recUserKeyValue"]._rec}` (raw record object when used alone)
|
|
151
153
|
|
|
154
|
+
`util.script` is the exception: it resolves its own `input`, where a value that is exactly one token keeps its
|
|
155
|
+
type (a list stays a list), and its `script` is never interpolated. See *Op: `util.script`*.
|
|
156
|
+
|
|
152
157
|
Test data lookup details:
|
|
153
158
|
- Data is indexed as `data:<modelUserKey>["<recUserKeyValue>"]`.
|
|
154
159
|
- You can access fields with `.fieldName`.
|
|
@@ -181,6 +186,136 @@ Examples:
|
|
|
181
186
|
}
|
|
182
187
|
```
|
|
183
188
|
|
|
189
|
+
### Reading saved results
|
|
190
|
+
`${res:<name>.<path>}` reads what an earlier step saved with `saveAs`. An `api.request` result has `status`,
|
|
191
|
+
`headers`, `bodyText` and `bodyJson`. The examples read a `books` result whose body is:
|
|
192
|
+
|
|
193
|
+
```json
|
|
194
|
+
{ "records": [ { "id": 7, "title": "Dune" }, { "id": 8, "title": "Emma", "note": "" } ] }
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
Paths:
|
|
198
|
+
- `${res:books.status}` gives `200`.
|
|
199
|
+
- `${res:books.bodyJson.records.0.id}` gives `7`. A number in the path is a position in a list, counted from 0.
|
|
200
|
+
- `${res:books.bodyJson.records[1].title}` gives `Emma`. Brackets and dots mean the same.
|
|
201
|
+
- `${res:books.bodyJson.records.length}` gives `2`, the number of records.
|
|
202
|
+
- `${res:books.bodyJson.records.0}` gives the whole first record, as JSON text.
|
|
203
|
+
- `${res:created.headers.location}` reads a response header. Header names are lower case.
|
|
204
|
+
|
|
205
|
+
A token becomes text, even when it is the whole value (except a `._rec` record, a secret that is not text, and
|
|
206
|
+
`util.script`'s `input`). So in `assert.equals` write the expected value as text: `"expected": "7"`, not `7`.
|
|
207
|
+
|
|
208
|
+
Transforms go after the path, each after a `|`:
|
|
209
|
+
- `| match:PATTERN` runs a regular expression over the value and gives the part in brackets, or the whole match
|
|
210
|
+
when the pattern has no brackets.
|
|
211
|
+
- `| default:VALUE` replaces a value that is null or empty.
|
|
212
|
+
|
|
213
|
+
```json
|
|
214
|
+
{ "then": { "op": "assert.equals", "with": { "actual": "${res:created.headers.location | match:/api/book/(\\d+)}", "expected": "42" } } },
|
|
215
|
+
{ "and": { "op": "api.request", "with": { "method": "GET", "url": "${env:API_BASE_URL}/api/order/${res:receipt.bodyText | match:ref=([A-Z0-9-]+)}" } } },
|
|
216
|
+
{ "and": { "op": "ui.fill", "with": { "selector": "#note", "value": "${res:books.bodyJson.records.1.note | default:none}" } } }
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
The first gives `42` from a `Location: /api/book/42` header. The second takes `BK-2026-0042` from a plain-text
|
|
220
|
+
body such as `Created book id=42 ref=BK-2026-0042`. The third types `none`, because that record's note is empty.
|
|
221
|
+
|
|
222
|
+
Each of these fails the step:
|
|
223
|
+
- A path that does not exist (`Missing resource for token`). `default:` does not help here: it replaces only a
|
|
224
|
+
null or empty value.
|
|
225
|
+
- A pattern that matches nothing.
|
|
226
|
+
- A pattern that contains `}` or `|`: the `}` ends the token, and `|` starts another transform. Write `\d\d`
|
|
227
|
+
rather than `\d{2}`. For alternatives such as `(id|ref)`, use `util.script`.
|
|
228
|
+
|
|
229
|
+
In a JSON file, double every backslash: `\\d` in the file reaches the pattern as `\d`. On a list or object,
|
|
230
|
+
`match:` runs over its JSON text. For the last item of a list, an item found by a field value, or anything
|
|
231
|
+
computed, use `util.script`.
|
|
232
|
+
|
|
233
|
+
### Random test data
|
|
234
|
+
Every generator, argument and value is listed on the docs page *Random Test Data* (`developer-docs/testing/random-test-data`); the table below is the short form.
|
|
235
|
+
`${random:...}` generates realistic values that are never repeated within one run, so a run can
|
|
236
|
+
create several records whose fields must be unique (emails, phone numbers, PANs, invoice numbers).
|
|
237
|
+
Each run starts afresh. Every generator takes `unique=false` to allow repeats.
|
|
238
|
+
|
|
239
|
+
| Generator | Arguments (default first) | Example |
|
|
240
|
+
|---|---|---|
|
|
241
|
+
| `firstName` | `locale`: `any`, `in`, `gb`, `us` | `Priya` |
|
|
242
|
+
| `lastName` | `locale`: `any`, `in`, `gb`, `us` | `Sharma` |
|
|
243
|
+
| `emailAddress` | `domain`: `example.com`; `format`: `first.last`, `firstlast`, `first_last`, `flast`, `random`; `digits` (after the name): `4`, 0–8; `length` (for `random`): `10`, 4–64 | `priya.sharma4821@example.com` |
|
|
244
|
+
| `mobileNo` | `country`: `in`, `gb`, `us`; `format`: `digits`, `national`, `e164`, `international`; `fictional`: `false` (UK and US only) | India `9876543210`, `+91 98765 43210`; UK `07912 345678`, `+447912345678`; US `(415) 234-5678`, `+1 415-234-5678` |
|
|
245
|
+
| `panNo` | `holderType`: `P`, `C`, `H`, `F`, `A`, `T`, `B`, `L`, `J`, `G` | `ABCPK1234Z` |
|
|
246
|
+
| `date` | `from`: `-1y` and `to`: `+1y` (`today`, `now`, `2026-10-17`, or shifts such as `-18y`, `+30d`, `+1d+2h`); `time`: `none`, `random`, or a window `09:00-18:00`; `format`: a dayjs pattern, `iso` or `epoch` (default `YYYY-MM-DD`); `tz`: `local`, `utc` or `Asia/Kolkata`; `unique`: **`false`** | `1987-04-12`, `03/11/2026` |
|
|
247
|
+
| `invoiceId` | `prefix`: `INV` (empty for none); `separator`: `-`, `/`, `_`, `none`; `length` (digits): `8`, 4–20; `date`: `none`, `yyyy`, `yyyymm`, `yyyymmdd`, `yyyymmddhhmm`, `yyyymmddhhmmss` | `INV-00482913`, `INV-20261017143205-00482913` |
|
|
248
|
+
|
|
249
|
+
- **Arguments** are `name=value` pairs: `${random:emailAddress(domain=acme.test, digits=0)}`. A simple
|
|
250
|
+
value (letters, digits and `. - / _ + : @`) is written bare. Anything else, such as a space, comma or
|
|
251
|
+
bracket, goes in quotes: `${now:date(format='D MMM, YYYY')}`. Prefer single quotes, since double quotes
|
|
252
|
+
must be escaped inside JSON; a backslash writes the quote character itself (`'it\'s'`).
|
|
253
|
+
- **Each token gives a new value.** To type a value in one step and assert it in another, generate
|
|
254
|
+
it once with `util.random` and read it back with `${res:...}`:
|
|
255
|
+
|
|
256
|
+
```json
|
|
257
|
+
{ "given": { "op": "util.random", "with": { "generator": "emailAddress", "args": { "domain": "acme.test" } }, "saveAs": "newEmail" } },
|
|
258
|
+
{ "when": { "op": "ui.fill", "with": { "selector": "#email", "value": "${res:newEmail}" } } },
|
|
259
|
+
{ "then": { "op": "ui.expectText", "with": { "selector": ".profile-email", "equals": "${res:newEmail}" } } }
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
- **Phone numbers are real-looking, so they may belong to someone.** Run against a test SMS
|
|
263
|
+
provider, or pass `fictional=true` with `country=gb` (Ofcom's drama range, 07700 900000–900999) or
|
|
264
|
+
`country=us` (555-0100 to 555-0199 in each area code). India has no such range, so `country=in`
|
|
265
|
+
with `fictional=true` is an error. A phone number counts as
|
|
266
|
+
used whatever its format, so the same number cannot come back as `e164` after `digits`.
|
|
267
|
+
- **Names come from fixed lists** (50 first and 50 last names per locale; 150 first and 123 last names for `any`). A run that asks for more
|
|
268
|
+
distinct names than the list holds fails with a message saying so; pass `unique=false` then.
|
|
269
|
+
- **Emails** use `example.com` by default, which never receives mail. The digits after the name
|
|
270
|
+
keep addresses distinct across runs as well, where an application's unique-email rule would
|
|
271
|
+
otherwise reject one seen in an earlier run.
|
|
272
|
+
- **PANs** have the right shape (3 letters, holder type, a letter, 4 digits, a letter). The last
|
|
273
|
+
letter is a check letter whose rule is not published, so it is random: fine for format checks,
|
|
274
|
+
not for a service that verifies the PAN.
|
|
275
|
+
|
|
276
|
+
### Current date and time
|
|
277
|
+
`${now:<kind>(offset=…, format=…, tz=…)}` gives the current moment, shifted by `offset`. It is not random:
|
|
278
|
+
the same instant gives the same value.
|
|
279
|
+
|
|
280
|
+
| Kind | Default format | Example |
|
|
281
|
+
|---|---|---|
|
|
282
|
+
| `date` | `YYYY-MM-DD` | `2026-10-17` |
|
|
283
|
+
| `time` | `HH:mm:ss` | `14:46:15` |
|
|
284
|
+
| `datetime` | `YYYY-MM-DD HH:mm:ss` | `2026-10-17 14:46:15` |
|
|
285
|
+
|
|
286
|
+
ISO 8601 and epoch milliseconds are formats, not kinds: `${now:datetime(format=iso)}` gives `2026-10-17T14:46:15+05:30` (`…Z` with `tz=utc`), and `${now:datetime(format=epoch)}` gives `1792228575000`.
|
|
287
|
+
|
|
288
|
+
- `offset` is `0` or terms such as `+7d`, `-1m`, `+1d+2h`: `y` years, `m` months, `w` weeks, `d` days,
|
|
289
|
+
`h` hours, `min` minutes, `s` seconds. A month shift stops at the end of a shorter month (31 Jan + 1m is 28 Feb).
|
|
290
|
+
- `format` is a [dayjs](https://day.js.org/docs/en/display/format) pattern: `YYYY` year, `MM` month,
|
|
291
|
+
`DD` day, `HH` hour, `mm` minutes, `MMM` month name. Text in `[brackets]` is literal. Java and C# patterns
|
|
292
|
+
(`dd/mm/yyyy`) are refused with the token to use instead.
|
|
293
|
+
- `tz` is `local` (the machine running the test), `utc`, or a zone such as `Asia/Kolkata`. A date near
|
|
294
|
+
midnight can differ between zones, so set `tz` when the app compares dates in one.
|
|
295
|
+
- Two `${now:...}` tokens can differ by a second. To type a timestamp and then assert it, take it once with
|
|
296
|
+
`util.now` and `saveAs`.
|
|
297
|
+
- `random:date` takes the same `format`, `tz` and shifts. It allows repeats by default (a year has
|
|
298
|
+
only 365 days); pass `unique=true` when a date must be distinct.
|
|
299
|
+
|
|
300
|
+
Date recipes:
|
|
301
|
+
|
|
302
|
+
| Need | Token |
|
|
303
|
+
|---|---|
|
|
304
|
+
| Date of birth, aged 18 to 60 | `${random:date(from=-60y, to=-18y)}` |
|
|
305
|
+
| The same, written 12/04/1987 | `${random:date(from=-60y, to=-18y, format=DD/MM/YYYY)}` |
|
|
306
|
+
| A date in the past year | `${random:date(from=-1y, to=today)}` |
|
|
307
|
+
| A due date in the next 30 days | `${random:date(from=today, to=+30d)}` |
|
|
308
|
+
| A date in a fixed period | `${random:date(from=2026-04-01, to=2027-03-31)}` |
|
|
309
|
+
| A slot in business hours, next two weeks | `${random:date(from=today, to=+14d, time=09:00-18:00)}` |
|
|
310
|
+
| A time in the next two hours | `${random:date(from=now, to=now+2h, time=random)}` |
|
|
311
|
+
| Today | `${now:date}` |
|
|
312
|
+
| A week from today | `${now:date(offset=+7d)}` |
|
|
313
|
+
| Yesterday (an expired date) | `${now:date(offset=-1d)}` |
|
|
314
|
+
| Exactly 18 years ago today (an age-limit boundary) | `${now:date(offset=-18y)}` |
|
|
315
|
+
| The current moment as an ISO timestamp, in UTC | `${now:datetime(tz=utc, format=iso)}` |
|
|
316
|
+
|
|
317
|
+
In `from`, `to` and `offset`, `now` and shifts in `h`, `min` or `s` mean an exact moment. Anything else (`today`, a fixed date, shifts in `y`, `m`, `w` or `d`) means the whole day, so `to=today` includes all of today. A shift with no base counts from the start of today, so a time ahead of the current moment is written with the base: `to=now+2h`, not `to=+2h`.
|
|
318
|
+
|
|
184
319
|
## Ops Reference
|
|
185
320
|
|
|
186
321
|
### **Op: `api.request`**
|
|
@@ -435,6 +570,69 @@ Options in `with`:
|
|
|
435
570
|
- `resource` (required)
|
|
436
571
|
- `message` (optional)
|
|
437
572
|
|
|
573
|
+
### **Op: `util.random`**
|
|
574
|
+
Description: Returns one random value (see *Random test data*), to keep with `saveAs`.
|
|
575
|
+
|
|
576
|
+
Options in `with`:
|
|
577
|
+
- `generator` (required): `firstName`, `lastName`, `emailAddress`, `mobileNo`, `panNo`, `date` or `invoiceId`
|
|
578
|
+
- `args` (optional): the generator's arguments as an object, e.g. `{ "format": "e164" }`
|
|
579
|
+
|
|
580
|
+
### **Op: `util.now`**
|
|
581
|
+
Description: Returns the current date or time (see *Current date and time*), to keep with `saveAs`.
|
|
582
|
+
|
|
583
|
+
Options in `with`:
|
|
584
|
+
- `kind` (optional): `date` (default), `time` or `datetime`. For ISO 8601 or epoch milliseconds, pass
|
|
585
|
+
`"format": "iso"` or `"epoch"` in `args`
|
|
586
|
+
- `args` (optional): `offset`, `format` and `tz` as an object, e.g. `{ "offset": "+7d" }`
|
|
587
|
+
|
|
588
|
+
### **Op: `util.script`**
|
|
589
|
+
Description: Runs a short TypeScript function over `input` and returns its result, to keep with `saveAs`.
|
|
590
|
+
Use it for what a token cannot do: find an item by a condition, combine two responses, reshape a value
|
|
591
|
+
for the next request. A fixed path (`${res:r.bodyJson.records.0.id}`) or a regex (`| match:`) needs no script;
|
|
592
|
+
see *Reading saved results*.
|
|
593
|
+
|
|
594
|
+
Options in `with`:
|
|
595
|
+
- `script` (required): a function body, as text or a list of lines, that ends with `return`
|
|
596
|
+
- `input` (optional): an object of values the script reads as `input.<name>`
|
|
597
|
+
- `timeoutMs` (optional, on the step): stops a script that runs too long; defaults to `5000`, at most `30000`
|
|
598
|
+
|
|
599
|
+
Tokens go in `input`, code goes in `script`:
|
|
600
|
+
```json
|
|
601
|
+
{ "when": { "op": "api.request", "with": { "method": "GET", "url": "${env:API_BASE_URL}/api/book" }, "saveAs": "books" } },
|
|
602
|
+
{ "and": { "op": "util.script", "with": {
|
|
603
|
+
"input": { "records": "${res:books.bodyJson.records}", "title": "${params.title}" },
|
|
604
|
+
"script": [
|
|
605
|
+
"const book = input.records.find((b: any) => b.title === input.title);",
|
|
606
|
+
"if (!book) throw new Error(`No book titled ${input.title}`);",
|
|
607
|
+
"return book.id;"
|
|
608
|
+
] }, "saveAs": "bookId" } },
|
|
609
|
+
{ "then": { "op": "api.request", "with": { "method": "DELETE", "url": "${env:API_BASE_URL}/api/book/${res:bookId}" } } }
|
|
610
|
+
```
|
|
611
|
+
|
|
612
|
+
Notes:
|
|
613
|
+
- The script sees only `input` and `console`. Anything it needs from the run, such as saved results, params,
|
|
614
|
+
test data, secrets, or random and current values, goes in `input` as a token, so each step shows what it depends on.
|
|
615
|
+
- A value in `input` that is exactly one token keeps its type: `"${res:books.bodyJson.records}"` arrives as a
|
|
616
|
+
list and `"${res:r.status}"` as a number. A token inside text (`"id-${res:r.status}"`) is text, as in any op.
|
|
617
|
+
- Don't write tokens inside `script`; the step refuses them. Inside code, `${...}` belongs to JavaScript: in a
|
|
618
|
+
template literal such as `` `Book ${input.id}` `` it inserts a variable's value. So the runner leaves the
|
|
619
|
+
script exactly as written, and values reach it only through `input`.
|
|
620
|
+
- The script runs synchronously: no `await`, `require`, timers or network. It gets a copy of `input`, so it
|
|
621
|
+
cannot change a saved result. While it runs, nothing else in the runner's process does (in test-hub, the
|
|
622
|
+
whole API), which is why the timeout is capped at 30 seconds. Keep scripts small: there is no memory limit.
|
|
623
|
+
- It must return data (text, numbers, true/false, lists or objects). The result is saved as JSON, so a date
|
|
624
|
+
comes back as ISO text. With `saveAs`, a script that returns nothing fails. Without `saveAs`, a throw still
|
|
625
|
+
fails the step, so a script can act as a custom check.
|
|
626
|
+
- `console.log`, `info`, `warn`, `error` and `debug` are collected and attached to the step's report as
|
|
627
|
+
*util.script console*, also when the script fails.
|
|
628
|
+
- TypeScript is compiled with the project's `typescript` package. Where that is not installed, write plain JavaScript.
|
|
629
|
+
- The script runs in a Node `vm` context that is given only text: `input` arrives as JSON, `console` is defined
|
|
630
|
+
inside it, and the result leaves as JSON. That keeps the runner's own objects, and with them `process` and
|
|
631
|
+
`require`, out of reach. Node does not promise that `vm` is a security boundary, though, so a script still
|
|
632
|
+
runs with the trust of whoever can change the scenario file, and in test-hub that file is the application's
|
|
633
|
+
tracked branch.
|
|
634
|
+
- For I/O, async work or logic shared between scenarios, write a `test.spec`.
|
|
635
|
+
|
|
438
636
|
### **Op: `test.spec`**
|
|
439
637
|
Description: Runs a custom test spec registered via testing.specs.
|
|
440
638
|
|
|
@@ -522,6 +720,7 @@ Common `test run` flags (all pass through solidctl unchanged):
|
|
|
522
720
|
- `--ui-navigation-timeout-ms <number>` — default wait for `ui.goto`
|
|
523
721
|
- `--timeout-ms <number>` / `--retries <number>` — scenario-level guard and retry count
|
|
524
722
|
- `--scenario-ids <ids>` / `--include-tags <tags>` / `--skip-scenario-ids <ids>`
|
|
723
|
+
- `--fail-fast [true|false]` — stop at the first failed scenario (the default). `--fail-fast false` runs every scenario, then still reports the run as failed and exits with code 1 if any failed
|
|
525
724
|
- `--no-progress` — disable the interactive test progress footer
|
|
526
725
|
|
|
527
726
|
## Add A New Step (SOP)
|
|
@@ -2,6 +2,7 @@ import type { ApiAdapter } from "../adapters/api/api-adapter";
|
|
|
2
2
|
import type { PlaywrightAdapter } from "../adapters/ui/playwright-adapter";
|
|
3
3
|
import type { Reporter } from "../reporter/reporter.types";
|
|
4
4
|
import type { SpecRegistry } from "../core/spec-registry";
|
|
5
|
+
import type { RandomDataRegistry } from "../core/random-data";
|
|
5
6
|
import type { ScenarioType } from "./testing-metadata.types";
|
|
6
7
|
|
|
7
8
|
export type StepPhase = "given" | "when" | "then" | "and" | "step";
|
|
@@ -36,6 +37,8 @@ export interface TestContext {
|
|
|
36
37
|
* Scoped per scenario — a scenario never sees another scenario's secrets.
|
|
37
38
|
*/
|
|
38
39
|
secrets?: Record<string, any>;
|
|
40
|
+
/** Hands out `${random:...}` and `util.random` values; one per run, so values never repeat in it. */
|
|
41
|
+
randomData?: RandomDataRegistry;
|
|
39
42
|
options?: {
|
|
40
43
|
printApiLogs?: boolean;
|
|
41
44
|
};
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
// Arguments of a call-style token, shared by `${random:<generator>(...)}` and `${now:<kind>(...)}`:
|
|
2
|
+
// declaring them, parsing them out of the token, and checking what was given.
|
|
3
|
+
//
|
|
4
|
+
// A value is written bare when it is simple (letters, digits and . - / _ + : @), and quoted when it
|
|
5
|
+
// holds anything else: `format='D MMM, YYYY'`. Quote with ' or " (single quotes are easier inside
|
|
6
|
+
// JSON); a backslash writes the quote character itself.
|
|
7
|
+
|
|
8
|
+
export type ArgValue = string | number | boolean;
|
|
9
|
+
export type Args = Record<string, ArgValue>;
|
|
10
|
+
|
|
11
|
+
export interface ArgSpec {
|
|
12
|
+
type: "string" | "number" | "boolean";
|
|
13
|
+
default: ArgValue;
|
|
14
|
+
/** Allowed values of a string argument, compared case-insensitively. */
|
|
15
|
+
values?: readonly string[];
|
|
16
|
+
/** Shape of a free-text string argument, with the wording used when it does not match. */
|
|
17
|
+
pattern?: RegExp;
|
|
18
|
+
patternHint?: string;
|
|
19
|
+
min?: number;
|
|
20
|
+
max?: number;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const BARE_VALUE = /^[A-Za-z0-9._\-/+:@]*$/;
|
|
24
|
+
|
|
25
|
+
export function coerceArg(label: string, key: string, raw: unknown, spec: ArgSpec): ArgValue {
|
|
26
|
+
const where = `${label} "${key}"`;
|
|
27
|
+
if (spec.type === "boolean") {
|
|
28
|
+
if (raw === true || raw === "true") return true;
|
|
29
|
+
if (raw === false || raw === "false") return false;
|
|
30
|
+
throw new Error(`${where} must be true or false (got "${String(raw)}")`);
|
|
31
|
+
}
|
|
32
|
+
if (spec.type === "number") {
|
|
33
|
+
const n = typeof raw === "number" ? raw : Number(String(raw).trim());
|
|
34
|
+
if (String(raw).trim() === "" || !Number.isInteger(n) || n < (spec.min ?? -Infinity) || n > (spec.max ?? Infinity)) {
|
|
35
|
+
throw new Error(`${where} must be a whole number from ${spec.min} to ${spec.max} (got "${String(raw)}")`);
|
|
36
|
+
}
|
|
37
|
+
return n;
|
|
38
|
+
}
|
|
39
|
+
const text = String(raw);
|
|
40
|
+
if (spec.values) {
|
|
41
|
+
const match = spec.values.find((v) => v.toLowerCase() === text.toLowerCase());
|
|
42
|
+
if (match === undefined) {
|
|
43
|
+
throw new Error(`${where} must be one of: ${spec.values.join(", ")} (got "${text}")`);
|
|
44
|
+
}
|
|
45
|
+
return match;
|
|
46
|
+
}
|
|
47
|
+
if (spec.pattern && !spec.pattern.test(text)) {
|
|
48
|
+
throw new Error(`${where} must be ${spec.patternHint} (got "${text}")`);
|
|
49
|
+
}
|
|
50
|
+
return text;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** Checks `raw` against `specs`, filling in defaults. `label` prefixes every message, e.g. `random:panNo`. */
|
|
54
|
+
export function resolveArgs(label: string, specs: Record<string, ArgSpec>, raw: Record<string, unknown>): Args {
|
|
55
|
+
for (const key of Object.keys(raw)) {
|
|
56
|
+
if (!specs[key]) {
|
|
57
|
+
throw new Error(`${label} does not take "${key}". It takes: ${Object.keys(specs).join(", ")}`);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
const args: Args = {};
|
|
61
|
+
for (const [key, spec] of Object.entries(specs)) {
|
|
62
|
+
args[key] = raw[key] === undefined ? spec.default : coerceArg(label, key, raw[key], spec);
|
|
63
|
+
}
|
|
64
|
+
return args;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// Splits the text between the brackets on commas that are not inside quotes.
|
|
68
|
+
function splitArgs(inner: string, whole: string): string[] {
|
|
69
|
+
const parts: string[] = [];
|
|
70
|
+
let quote: string | null = null;
|
|
71
|
+
let last = 0;
|
|
72
|
+
for (let i = 0; i < inner.length; i += 1) {
|
|
73
|
+
const c = inner[i];
|
|
74
|
+
if (quote) {
|
|
75
|
+
if (c === "\\") i += 1;
|
|
76
|
+
else if (c === quote) quote = null;
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
if (c === "'" || c === '"') quote = c;
|
|
80
|
+
else if (c === ",") {
|
|
81
|
+
parts.push(inner.slice(last, i));
|
|
82
|
+
last = i + 1;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
if (quote) throw new Error(`Unclosed quote in "${whole}"`);
|
|
86
|
+
parts.push(inner.slice(last));
|
|
87
|
+
return parts;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Reads a quoted value; null when anything follows the closing quote.
|
|
91
|
+
function unquote(raw: string, whole: string): string | null {
|
|
92
|
+
const quote = raw[0];
|
|
93
|
+
let out = "";
|
|
94
|
+
for (let i = 1; i < raw.length; i += 1) {
|
|
95
|
+
const c = raw[i];
|
|
96
|
+
if (c === "\\" && i + 1 < raw.length) {
|
|
97
|
+
out += raw[i + 1];
|
|
98
|
+
i += 1;
|
|
99
|
+
} else if (c === quote) {
|
|
100
|
+
return i === raw.length - 1 ? out : null;
|
|
101
|
+
} else {
|
|
102
|
+
out += c;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
throw new Error(`Unclosed quote in "${whole}"`);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Parses what follows `<prefix>:` in a token: `emailAddress` or
|
|
110
|
+
* `emailAddress(domain=acme.test, digits=0)`. `noun` names the first part in messages
|
|
111
|
+
* ("generator", "kind").
|
|
112
|
+
*/
|
|
113
|
+
export function parseCallToken(
|
|
114
|
+
prefix: string,
|
|
115
|
+
noun: string,
|
|
116
|
+
spec: string,
|
|
117
|
+
): { name: string; args: Record<string, string> } {
|
|
118
|
+
const whole = `${prefix}:${spec}`;
|
|
119
|
+
const invalidToken = () =>
|
|
120
|
+
new Error(`Invalid ${prefix} token "${whole}". Write ${prefix}:<${noun}> or ${prefix}:<${noun}>(name=value, ...)`);
|
|
121
|
+
const m = spec.trim().match(/^([A-Za-z][A-Za-z0-9]*)\s*([\s\S]*)$/);
|
|
122
|
+
if (!m) throw invalidToken();
|
|
123
|
+
const name = m[1];
|
|
124
|
+
const rest = m[2].trim();
|
|
125
|
+
const args: Record<string, string> = {};
|
|
126
|
+
if (!rest) return { name, args };
|
|
127
|
+
if (!rest.startsWith("(") || !rest.endsWith(")")) throw invalidToken();
|
|
128
|
+
|
|
129
|
+
for (const part of splitArgs(rest.slice(1, -1), whole)) {
|
|
130
|
+
const piece = part.trim();
|
|
131
|
+
if (!piece) continue;
|
|
132
|
+
const eq = piece.indexOf("=");
|
|
133
|
+
const key = eq === -1 ? "" : piece.slice(0, eq).trim();
|
|
134
|
+
if (!key) {
|
|
135
|
+
throw new Error(`Invalid argument "${piece}" in "${whole}". Write name=value`);
|
|
136
|
+
}
|
|
137
|
+
if (key in args) {
|
|
138
|
+
throw new Error(`Argument "${key}" is given twice in "${whole}"`);
|
|
139
|
+
}
|
|
140
|
+
const raw = piece.slice(eq + 1).trim();
|
|
141
|
+
if (raw[0] === "'" || raw[0] === '"') {
|
|
142
|
+
const value = unquote(raw, whole);
|
|
143
|
+
if (value === null) {
|
|
144
|
+
throw new Error(`Invalid argument "${piece}" in "${whole}". Write name=value`);
|
|
145
|
+
}
|
|
146
|
+
args[key] = value;
|
|
147
|
+
} else if (BARE_VALUE.test(raw)) {
|
|
148
|
+
args[key] = raw;
|
|
149
|
+
} else {
|
|
150
|
+
throw new Error(`${prefix}:${name} "${key}" must be quoted: ${key}='${raw}'`);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
return { name, args };
|
|
154
|
+
}
|