@tailor-platform/sdk 1.74.1 → 1.76.0
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 +22 -0
- package/dist/{application-BsH6tkZC.mjs → application-BUfYmf0O.mjs} +291 -15
- package/dist/application-BUfYmf0O.mjs.map +1 -0
- package/dist/application-DbvD5UUz.mjs +3 -0
- package/dist/brand-Eo4pLXPJ.mjs.map +1 -1
- package/dist/cli/commands/deploy/workflow-execution-policy.d.mts +1 -0
- package/dist/cli/index.mjs +218 -66
- package/dist/cli/index.mjs.map +1 -1
- package/dist/cli/lib.mjs +2 -2
- package/dist/cli/query/index.d.mts +4 -0
- package/dist/completion/zsh-worker.zsh +10 -10
- package/dist/configure/config/types.d.mts +3 -1
- package/dist/configure/index.d.mts +3 -1
- package/dist/configure/index.mjs +112 -4
- package/dist/configure/index.mjs.map +1 -1
- package/dist/configure/services/index.d.mts +3 -1
- package/dist/configure/services/tailordb/schema.d.mts +28 -15
- package/dist/configure/services/workflow/execution-policy.d.mts +71 -0
- package/dist/configure/services/workflow/execution-policy.types.d.mts +104 -0
- package/dist/configure/services/workflow/index.d.mts +3 -1
- package/dist/configure/services/workflow/job.d.mts +7 -3
- package/dist/{globals-B8XX5TRB.mjs → globals-CcU1ONiK.mjs} +2 -2
- package/dist/globals-CcU1ONiK.mjs.map +1 -0
- package/dist/{job-CtU73PGa.mjs → job-D-PbD1P3.mjs} +5 -3
- package/dist/job-D-PbD1P3.mjs.map +1 -0
- package/dist/{registry-BozuxbPp.mjs → registry-NfSW0BRo.mjs} +4 -3
- package/dist/registry-NfSW0BRo.mjs.map +1 -0
- package/dist/resource_pb-BRv7AMXK.mjs +49 -0
- package/dist/resource_pb-BRv7AMXK.mjs.map +1 -0
- package/dist/runtime/globals.d.mts +1 -1
- package/dist/runtime/index.d.mts +1 -1
- package/dist/runtime/workflow.d.mts +22 -3
- package/dist/{runtime-DV1EnfMs.mjs → runtime-_vUgjiqT.mjs} +253 -254
- package/dist/runtime-_vUgjiqT.mjs.map +1 -0
- package/dist/{schema-Dl_y0m9e.mjs → schema-DrVyN-LP.mjs} +60 -36
- package/dist/schema-DrVyN-LP.mjs.map +1 -0
- package/dist/{service_pb-DjwIn4jO.mjs → service_pb-B2FF59sP.mjs} +1 -1
- package/dist/{service_pb-CIrhGwHk.mjs → service_pb-B5w9rjPY.mjs} +17 -50
- package/dist/service_pb-B5w9rjPY.mjs.map +1 -0
- package/dist/tailor-proto/src/tailor/v1/service_pb.d.mts +1 -1
- package/dist/tailor-proto/src/tailor/v1/workflow_pb.d.mts +29 -9
- package/dist/tailor-proto/src/tailor/v1/workflow_resource_pb.d.mts +35 -1
- package/dist/utils/test/index.mjs +1 -1
- package/dist/utils/test/index.mjs.map +1 -1
- package/dist/vitest/environment.mjs +1 -1
- package/dist/vitest/index.mjs +15 -12
- package/dist/vitest/index.mjs.map +1 -1
- package/dist/vitest/mocks/workflow.d.mts +5 -3
- package/dist/vitest/setup.mjs +1 -1
- package/dist/workflow-DSwnYPPP.mjs.map +1 -1
- package/docs/cli/auth.md +3 -3
- package/docs/cli/setup.md +8 -8
- package/docs/configuration.md +24 -0
- package/docs/services/tailordb.md +20 -0
- package/docs/services/workflow.md +78 -0
- package/package.json +1 -1
- package/dist/application-BsH6tkZC.mjs.map +0 -1
- package/dist/application-CSUhZMb5.mjs +0 -3
- package/dist/globals-B8XX5TRB.mjs.map +0 -1
- package/dist/job-CtU73PGa.mjs.map +0 -1
- package/dist/registry-BozuxbPp.mjs.map +0 -1
- package/dist/runtime-DV1EnfMs.mjs.map +0 -1
- package/dist/schema-Dl_y0m9e.mjs.map +0 -1
- package/dist/service_pb-CIrhGwHk.mjs.map +0 -1
|
@@ -340,6 +340,8 @@ export const user = db
|
|
|
340
340
|
});
|
|
341
341
|
```
|
|
342
342
|
|
|
343
|
+
**Note:** `.hooks()` can only be called once on a type. Duplicate type-level calls fail at compile time and throw at runtime.
|
|
344
|
+
|
|
343
345
|
### Validation
|
|
344
346
|
|
|
345
347
|
Add validation rules to fields. Validators receive three arguments (executed after hooks):
|
|
@@ -403,6 +405,8 @@ export const user = db
|
|
|
403
405
|
});
|
|
404
406
|
```
|
|
405
407
|
|
|
408
|
+
**Note:** `.validate()` can only be called once on a type. Duplicate type-level calls fail at compile time and throw at runtime.
|
|
409
|
+
|
|
406
410
|
### Vector Search
|
|
407
411
|
|
|
408
412
|
```typescript
|
|
@@ -434,6 +438,22 @@ export const user = db.type("User", {
|
|
|
434
438
|
|
|
435
439
|
## Type Modifiers
|
|
436
440
|
|
|
441
|
+
Type builder methods that set one type-level configuration can be called only once on the same type. Duplicate calls fail at compile time and throw at runtime. This applies to `.description()`, `.hooks()`, `.validate()`, `.features()`, `.indexes()`, `.files()`, `.permission()`, and `.gqlPermission()`.
|
|
442
|
+
|
|
443
|
+
Conditional assignment is still supported when only one branch calls the method:
|
|
444
|
+
|
|
445
|
+
```typescript
|
|
446
|
+
let user = db.type("User", {
|
|
447
|
+
name: db.string(),
|
|
448
|
+
});
|
|
449
|
+
|
|
450
|
+
if (enableFiles) {
|
|
451
|
+
user = user.files({
|
|
452
|
+
avatar: "profile image",
|
|
453
|
+
});
|
|
454
|
+
}
|
|
455
|
+
```
|
|
456
|
+
|
|
437
457
|
### Composite Indexes
|
|
438
458
|
|
|
439
459
|
```typescript
|
|
@@ -351,6 +351,84 @@ export default createWorkflow({
|
|
|
351
351
|
});
|
|
352
352
|
```
|
|
353
353
|
|
|
354
|
+
## Execution Policies
|
|
355
|
+
|
|
356
|
+
Execution policies apply a per-key concurrency cap to workflow job function dispatches. Declare them at the workspace level and pass a matching key when triggering a job; the platform serializes dispatches that resolve to the same key and suspends any that would exceed the cap until slots free up.
|
|
357
|
+
|
|
358
|
+
### Declaring Policies
|
|
359
|
+
|
|
360
|
+
Use `defineWorkflowExecutionPolicies` with a builder callback. Property names supply the workspace-unique name and default key prefix verbatim, matching the mental model of `defineWaitPoints`. Override `name` or `key` in the body when the property identifier is not valid execution policy grammar or the key prefix needs to differ. Set `matchType: "prefix"` to register the prefix as a wildcard that matches every dispatch key starting with it (the default, `"exact"`, matches only a dispatch key equal to it).
|
|
361
|
+
|
|
362
|
+
```typescript
|
|
363
|
+
import { defineWorkflowExecutionPolicies } from "@tailor-platform/sdk";
|
|
364
|
+
|
|
365
|
+
export const executionPolicies = defineWorkflowExecutionPolicies((define) => ({
|
|
366
|
+
/** Shared cap across every "premium" worker dispatch. */
|
|
367
|
+
premium: define({ concurrencyPolicy: { maxConcurrentExecutions: 5 } }),
|
|
368
|
+
/** Per-tenant cap: one pool per resolved tenant key. */
|
|
369
|
+
tenantApi: define({
|
|
370
|
+
name: "tenant-api",
|
|
371
|
+
matchType: "prefix",
|
|
372
|
+
concurrencyPolicy: { maxConcurrentExecutions: 3 },
|
|
373
|
+
}),
|
|
374
|
+
}));
|
|
375
|
+
```
|
|
376
|
+
|
|
377
|
+
For a single policy, use `defineWorkflowExecutionPolicy(name, def?)`; the key prefix defaults to `name` when `key` is omitted.
|
|
378
|
+
|
|
379
|
+
`concurrencyPolicy` is optional; when omitted, the policy registers the key as valid without a user-defined limit (platform safety nets still apply).
|
|
380
|
+
|
|
381
|
+
Register the policies on your config so the SDK creates them on the workspace during deploy:
|
|
382
|
+
|
|
383
|
+
```typescript
|
|
384
|
+
// tailor.config.ts
|
|
385
|
+
import { defineConfig } from "@tailor-platform/sdk";
|
|
386
|
+
import { executionPolicies } from "./workflows/policies";
|
|
387
|
+
|
|
388
|
+
export default defineConfig({
|
|
389
|
+
workflow: {
|
|
390
|
+
files: ["workflows/**/*.ts"],
|
|
391
|
+
executionPolicies,
|
|
392
|
+
},
|
|
393
|
+
});
|
|
394
|
+
```
|
|
395
|
+
|
|
396
|
+
### Key Grammar
|
|
397
|
+
|
|
398
|
+
`key` accepts `[a-z0-9_:.-]` and must start with `[a-z0-9]`. An exact key must also end with `[a-z0-9]`; a wildcard prefix (`matchType: "prefix"`) may end with any of those characters, since the platform appends a trailing `*` after it. The platform-registered key — including that trailing `*` when wildcarded — is 2 to 64 characters long, so a wildcard prefix must be at most 63 characters. `foo:bar` is a valid exact key; `tenant-api` with `matchType: "prefix"` registers `tenant-api*` as a wildcard prefix.
|
|
399
|
+
|
|
400
|
+
An exact-key policy applies to dispatches whose runtime key equals the policy key. A wildcard policy applies to every dispatch whose runtime key begins with the prefix; each concrete resolved key gets its own independent pool of the declared size (a `cap = 3` wildcard yields three concurrent dispatches per resolved key, not three across every match). The longest matching prefix wins when a dispatch could match more than one wildcard.
|
|
401
|
+
|
|
402
|
+
### Referencing a Policy from a Workflow
|
|
403
|
+
|
|
404
|
+
Pass the runtime key through the `executionPolicyKey` option on `job.trigger()` or `tailor.workflow.triggerJobFunction()`. For exact-key policies, use `<policy>.key` directly — it's typed so only a value that came from a declared policy can be passed. For wildcard policies (`matchType: "prefix"`), there is no `<policy>.key` — call `<policy>.keyFor(suffix)` to build the concrete key. `keyFor` joins the prefix and suffix with `.` by default; override it with `separator` — the second argument to `defineWorkflowExecutionPolicies` (applies to every policy in the group), or a `def` field on a single `defineWorkflowExecutionPolicy`.
|
|
405
|
+
|
|
406
|
+
```typescript
|
|
407
|
+
import { createWorkflowJob } from "@tailor-platform/sdk";
|
|
408
|
+
import { executionPolicies } from "./policies";
|
|
409
|
+
import { sendNotification } from "./jobs/send-notification";
|
|
410
|
+
import { fetchTenant } from "./jobs/fetch-tenant";
|
|
411
|
+
|
|
412
|
+
export const mainJob = createWorkflowJob({
|
|
413
|
+
name: "main-job",
|
|
414
|
+
body: async (input: { tenantId: string }) => {
|
|
415
|
+
// Exact key policy: pass .key directly.
|
|
416
|
+
await sendNotification.trigger(
|
|
417
|
+
{ message: "Order processed" },
|
|
418
|
+
{ executionPolicyKey: executionPolicies.premium.key },
|
|
419
|
+
);
|
|
420
|
+
|
|
421
|
+
// Wildcard policy: build the concrete key with keyFor().
|
|
422
|
+
await fetchTenant.trigger(
|
|
423
|
+
{ tenantId: input.tenantId },
|
|
424
|
+
{ executionPolicyKey: executionPolicies.tenantApi.keyFor(input.tenantId) },
|
|
425
|
+
);
|
|
426
|
+
},
|
|
427
|
+
});
|
|
428
|
+
```
|
|
429
|
+
|
|
430
|
+
The same `executionPolicyKey` option is available on `tailor.workflow.triggerJobFunction(name, args, options)` for jobs invoked by name.
|
|
431
|
+
|
|
354
432
|
## Triggering a Workflow from a Resolver
|
|
355
433
|
|
|
356
434
|
You can start a workflow execution from a resolver using `workflow.trigger()`.
|