@tailor-platform/sdk 1.20.0 → 1.22.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 +56 -0
- package/dist/application-CTQe2HSB.mjs +5723 -0
- package/dist/application-CTQe2HSB.mjs.map +1 -0
- package/dist/application-DdSu3baZ.mjs +8 -0
- package/dist/{brand-BZJCv6UY.mjs → brand-DyPrAzpM.mjs} +1 -1
- package/dist/{brand-BZJCv6UY.mjs.map → brand-DyPrAzpM.mjs.map} +1 -1
- package/dist/cli/index.mjs +544 -57
- package/dist/cli/index.mjs.map +1 -1
- package/dist/cli/lib.d.mts +50 -8
- package/dist/cli/lib.mjs +15 -16
- package/dist/cli/lib.mjs.map +1 -1
- package/dist/configure/index.d.mts +4 -4
- package/dist/configure/index.mjs +20 -4
- package/dist/configure/index.mjs.map +1 -1
- package/dist/{enum-constants-CGVvu3dd.mjs → enum-constants-B5Nl-yzx.mjs} +1 -1
- package/dist/{enum-constants-CGVvu3dd.mjs.map → enum-constants-B5Nl-yzx.mjs.map} +1 -1
- package/dist/{file-utils-GX_tGWl4.mjs → file-utils-sEOwAdJ4.mjs} +1 -1
- package/dist/{file-utils-GX_tGWl4.mjs.map → file-utils-sEOwAdJ4.mjs.map} +1 -1
- package/dist/{index-i6QUsr5p.d.mts → index-BGPX26_D.d.mts} +2 -2
- package/dist/{index-DcY0e3S5.d.mts → index-BiutQT7m.d.mts} +9 -10
- package/dist/{index-CGjiOz_W.d.mts → index-ClS0NClx.d.mts} +2 -2
- package/dist/{index-B86CIKCW.d.mts → index-Cwi86SUR.d.mts} +2 -2
- package/dist/{index-CIXOwe6g.d.mts → index-DPN_P0w3.d.mts} +2 -2
- package/dist/{interceptor-D8MeZOxX.mjs → interceptor-DiARwPfw.mjs} +1 -1
- package/dist/{interceptor-D8MeZOxX.mjs.map → interceptor-DiARwPfw.mjs.map} +1 -1
- package/dist/{job-2Q82qQ6N.mjs → job-CRavYLLk.mjs} +4 -24
- package/dist/job-CRavYLLk.mjs.map +1 -0
- package/dist/kysely/index.d.mts +2 -2
- package/dist/kysely/index.mjs +2 -2
- package/dist/kysely/index.mjs.map +1 -1
- package/dist/{kysely-type-Cpq5TNGY.mjs → kysely-type-CSlcwNFH.mjs} +1 -1
- package/dist/{kysely-type-Cpq5TNGY.mjs.map → kysely-type-CSlcwNFH.mjs.map} +1 -1
- package/dist/package-json-BI0ng3_5.mjs +3 -0
- package/dist/{package-json-3H5gfhA4.mjs → package-json-iVBhE5Ef.mjs} +1 -1
- package/dist/{package-json-3H5gfhA4.mjs.map → package-json-iVBhE5Ef.mjs.map} +1 -1
- package/dist/plugin/builtin/enum-constants/index.d.mts +2 -2
- package/dist/plugin/builtin/enum-constants/index.mjs +1 -1
- package/dist/plugin/builtin/file-utils/index.d.mts +2 -2
- package/dist/plugin/builtin/file-utils/index.mjs +1 -1
- package/dist/plugin/builtin/kysely-type/index.d.mts +2 -2
- package/dist/plugin/builtin/kysely-type/index.mjs +1 -1
- package/dist/plugin/builtin/seed/index.d.mts +2 -2
- package/dist/plugin/builtin/seed/index.mjs +1 -1
- package/dist/plugin/index.d.mts +1 -1
- package/dist/plugin/index.mjs +3 -3
- package/dist/plugin/index.mjs.map +1 -1
- package/dist/{update-DkpWgrzL.mjs → query-Bz2oDGhw.mjs} +1033 -258
- package/dist/query-Bz2oDGhw.mjs.map +1 -0
- package/dist/{schema-D5Cpd8fQ.mjs → schema-Cjm-OvPF.mjs} +2 -2
- package/dist/{schema-D5Cpd8fQ.mjs.map → schema-Cjm-OvPF.mjs.map} +1 -1
- package/dist/{seed-CeUEANfQ.mjs → seed-CXvCW3Xc.mjs} +3 -3
- package/dist/{seed-CeUEANfQ.mjs.map → seed-CXvCW3Xc.mjs.map} +1 -1
- package/dist/telemetry-BAxP8-PR.mjs +3 -0
- package/dist/{telemetry-DuBhnd0X.mjs → telemetry-C46fds1l.mjs} +2 -2
- package/dist/{telemetry-DuBhnd0X.mjs.map → telemetry-C46fds1l.mjs.map} +1 -1
- package/dist/{types-ClK_HJ0G.mjs → types-CBTSg-LK.mjs} +1 -1
- package/dist/{types-ClK_HJ0G.mjs.map → types-CBTSg-LK.mjs.map} +1 -1
- package/dist/{types-C14GuyPI.d.mts → types-DVMQNdTs.d.mts} +6 -2
- package/dist/{types-CNw4p8V7.d.mts → types-bcuNRo1Y.d.mts} +12 -1
- package/dist/utils/test/index.d.mts +42 -4
- package/dist/utils/test/index.mjs +78 -3
- package/dist/utils/test/index.mjs.map +1 -1
- package/docs/cli/function.md +83 -3
- package/docs/services/resolver.md +61 -0
- package/docs/services/tailordb.md +55 -0
- package/package.json +7 -5
- package/dist/application-Bli2ieqY.mjs +0 -102205
- package/dist/application-Bli2ieqY.mjs.map +0 -1
- package/dist/application-CZdieD3K.mjs +0 -9
- package/dist/chunk-CqAI0b6X.mjs +0 -47
- package/dist/jiti-DfS9jItj.mjs +0 -4482
- package/dist/jiti-DfS9jItj.mjs.map +0 -1
- package/dist/job-2Q82qQ6N.mjs.map +0 -1
- package/dist/package-json-DTDAqRRJ.mjs +0 -3
- package/dist/src-Bb1UVstT.mjs +0 -1038
- package/dist/src-Bb1UVstT.mjs.map +0 -1
- package/dist/telemetry-Dhzj9Ncm.mjs +0 -3
- package/dist/update-DkpWgrzL.mjs.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../../src/utils/test/index.ts"],"sourcesContent":["import type { output, TailorUser } from \"@/configure\";\nimport type { TailorDBType } from \"@/configure/services/tailordb/schema\";\nimport type { TailorField } from \"@/configure/types/type\";\nimport type { StandardSchemaV1 } from \"@standard-schema/spec\";\n\nexport { WORKFLOW_TEST_ENV_KEY
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../../src/utils/test/mock.ts","../../../src/utils/test/index.ts"],"sourcesContent":["import * as path from \"node:path\";\nimport { pathToFileURL } from \"node:url\";\n\ntype MainFunction = (args: Record<string, unknown>) => unknown | Promise<unknown>;\ntype QueryResolver = (query: string, params: unknown[]) => unknown[];\ntype JobHandler = (jobName: string, args: unknown) => unknown;\n\ninterface TailordbGlobal {\n tailordb?: {\n Client: new (config: { namespace?: string }) => {\n connect(): Promise<void> | void;\n end(): Promise<void> | void;\n queryObject(\n query: string,\n params?: unknown[],\n ): Promise<{ rows: unknown[] }> | { rows: unknown[] };\n };\n };\n tailor?: {\n workflow: {\n triggerJobFunction: (jobName: string, args: unknown) => unknown;\n };\n };\n}\n\nconst GlobalThis = globalThis as TailordbGlobal;\n\n/**\n * Sets up a mock for `globalThis.tailordb.Client` used in bundled resolver/executor tests.\n * @param resolver - Optional function to resolve query results. Defaults to returning empty arrays.\n * @returns Object containing arrays of executed queries and created clients for assertions.\n */\nexport function setupTailordbMock(resolver: QueryResolver = () => []): {\n executedQueries: { query: string; params: unknown[] }[];\n createdClients: { namespace?: string; ended: boolean }[];\n} {\n const executedQueries: { query: string; params: unknown[] }[] = [];\n const createdClients: { namespace?: string; ended: boolean }[] = [];\n\n class MockTailordbClient {\n private record: { namespace?: string; ended: boolean };\n\n constructor({ namespace }: { namespace?: string }) {\n this.record = { namespace, ended: false };\n createdClients.push(this.record);\n }\n\n async connect(): Promise<void> {\n /* noop */\n }\n\n async end(): Promise<void> {\n this.record.ended = true;\n }\n\n async queryObject(query: string, params: unknown[] = []): Promise<{ rows: unknown[] }> {\n executedQueries.push({ query, params });\n return { rows: resolver(query, params) ?? [] };\n }\n }\n\n GlobalThis.tailordb = {\n Client: MockTailordbClient,\n } as typeof GlobalThis.tailordb;\n\n return { executedQueries, createdClients };\n}\n\n/**\n * Sets up a mock for `globalThis.tailor.workflow.triggerJobFunction` used in bundled workflow tests.\n * @param handler - Function that handles triggered job calls and returns results.\n * @returns Object containing an array of triggered jobs for assertions.\n */\nexport function setupWorkflowMock(handler: JobHandler): {\n triggeredJobs: { jobName: string; args: unknown }[];\n} {\n const triggeredJobs: { jobName: string; args: unknown }[] = [];\n\n GlobalThis.tailor = {\n ...GlobalThis.tailor,\n workflow: {\n triggerJobFunction: (jobName: string, args: unknown) => {\n triggeredJobs.push({ jobName, args });\n return handler(jobName, args);\n },\n },\n } as typeof GlobalThis.tailor;\n\n return { triggeredJobs };\n}\n\n/**\n * Creates a function that imports a bundled JS file and returns its `main` export.\n * Used to test bundled output from `apply --buildOnly`.\n * @param baseDir - Base directory where bundled files are located.\n * @returns An async function that takes a relative path and returns the `main` function.\n */\nexport function createImportMain(baseDir: string): (relativePath: string) => Promise<MainFunction> {\n return async (relativePath: string): Promise<MainFunction> => {\n const fileUrl = pathToFileURL(path.join(baseDir, relativePath));\n fileUrl.searchParams.set(\"v\", `${Date.now()}-${Math.random()}`);\n const module = await import(fileUrl.href);\n const main = module.main;\n if (typeof main !== \"function\") {\n throw new Error(`Expected \"main\" to be a function in ${relativePath}, got ${typeof main}`);\n }\n return main;\n };\n}\n","import type { output, TailorUser } from \"@/configure\";\nimport type { TailorDBType } from \"@/configure/services/tailordb/schema\";\nimport type { TailorField } from \"@/configure/types/type\";\nimport type { StandardSchemaV1 } from \"@standard-schema/spec\";\n\nexport { WORKFLOW_TEST_ENV_KEY } from \"@/configure/services/workflow/job\";\nexport { setupTailordbMock, setupWorkflowMock, createImportMain } from \"./mock\";\n\n/** Represents an unauthenticated user in the Tailor platform. */\nexport const unauthenticatedTailorUser = {\n id: \"00000000-0000-0000-0000-000000000000\",\n type: \"\",\n workspaceId: \"00000000-0000-0000-0000-000000000000\",\n attributes: null,\n attributeList: [],\n} as const satisfies TailorUser;\n\n/**\n * Creates a hook function that processes TailorDB type fields\n * - Uses existing id from data if provided, otherwise generates UUID for id fields\n * - Recursively processes nested types\n * - Executes hooks.create for fields with create hooks\n * @template T - The output type of the hook function\n * @param type - TailorDB type definition\n * @returns A function that transforms input data according to field hooks\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function createTailorDBHook<T extends TailorDBType<any, any>>(type: T) {\n return (data: unknown) => {\n return Object.entries(type.fields).reduce(\n (hooked, [key, value]) => {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const field = value as TailorField<any, any, any>;\n if (key === \"id\") {\n // Use existing id from data if provided, otherwise generate new UUID\n const existingId =\n data && typeof data === \"object\" ? (data as Record<string, unknown>)[key] : undefined;\n hooked[key] = existingId ?? crypto.randomUUID();\n } else if (field.type === \"nested\") {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n hooked[key] = createTailorDBHook({ fields: field.fields } as any)(\n (data as Record<string, unknown>)[key],\n );\n } else if (field.metadata.hooks?.create) {\n hooked[key] = field.metadata.hooks.create({\n value: (data as Record<string, unknown>)[key],\n data: data,\n user: unauthenticatedTailorUser,\n });\n if (hooked[key] instanceof Date) {\n hooked[key] = hooked[key].toISOString();\n }\n } else if (data && typeof data === \"object\") {\n hooked[key] = (data as Record<string, unknown>)[key];\n }\n return hooked;\n },\n {} as Record<string, unknown>,\n ) as Partial<output<T>>;\n };\n}\n\n/**\n * Creates the standard schema definition for lines-db\n * This returns the first argument for defineSchema with the ~standard section\n * @template T - The output type after validation\n * @param schemaType - TailorDB field schema for validation\n * @param hook - Hook function to transform data before validation\n * @returns Schema object with ~standard section for defineSchema\n */\nexport function createStandardSchema<T = Record<string, unknown>>(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n schemaType: TailorField<any, T>,\n hook: (data: unknown) => Partial<T>,\n) {\n return {\n \"~standard\": {\n version: 1,\n vendor: \"@tailor-platform/sdk\",\n validate: (value: unknown) => {\n const hooked = hook(value);\n const result = schemaType.parse({\n value: hooked,\n data: hooked,\n user: unauthenticatedTailorUser,\n });\n if (result.issues) {\n return result;\n }\n return { value: hooked as T };\n },\n },\n } as const satisfies StandardSchemaV1<T>;\n}\n"],"mappings":";;;;;;AAyBA,MAAM,aAAa;;;;;;AAOnB,SAAgB,kBAAkB,iBAAgC,EAAE,EAGlE;CACA,MAAM,kBAA0D,EAAE;CAClE,MAAM,iBAA2D,EAAE;CAEnE,MAAM,mBAAmB;EACvB,AAAQ;EAER,YAAY,EAAE,aAAqC;AACjD,QAAK,SAAS;IAAE;IAAW,OAAO;IAAO;AACzC,kBAAe,KAAK,KAAK,OAAO;;EAGlC,MAAM,UAAyB;EAI/B,MAAM,MAAqB;AACzB,QAAK,OAAO,QAAQ;;EAGtB,MAAM,YAAY,OAAe,SAAoB,EAAE,EAAgC;AACrF,mBAAgB,KAAK;IAAE;IAAO;IAAQ,CAAC;AACvC,UAAO,EAAE,MAAM,SAAS,OAAO,OAAO,IAAI,EAAE,EAAE;;;AAIlD,YAAW,WAAW,EACpB,QAAQ,oBACT;AAED,QAAO;EAAE;EAAiB;EAAgB;;;;;;;AAQ5C,SAAgB,kBAAkB,SAEhC;CACA,MAAM,gBAAsD,EAAE;AAE9D,YAAW,SAAS;EAClB,GAAG,WAAW;EACd,UAAU,EACR,qBAAqB,SAAiB,SAAkB;AACtD,iBAAc,KAAK;IAAE;IAAS;IAAM,CAAC;AACrC,UAAO,QAAQ,SAAS,KAAK;KAEhC;EACF;AAED,QAAO,EAAE,eAAe;;;;;;;;AAS1B,SAAgB,iBAAiB,SAAkE;AACjG,QAAO,OAAO,iBAAgD;EAC5D,MAAM,UAAU,cAAc,KAAK,KAAK,SAAS,aAAa,CAAC;AAC/D,UAAQ,aAAa,IAAI,KAAK,GAAG,KAAK,KAAK,CAAC,GAAG,KAAK,QAAQ,GAAG;EAE/D,MAAM,QADS,MAAM,OAAO,QAAQ,OAChB;AACpB,MAAI,OAAO,SAAS,WAClB,OAAM,IAAI,MAAM,uCAAuC,aAAa,QAAQ,OAAO,OAAO;AAE5F,SAAO;;;;;;;ACjGX,MAAa,4BAA4B;CACvC,IAAI;CACJ,MAAM;CACN,aAAa;CACb,YAAY;CACZ,eAAe,EAAE;CAClB;;;;;;;;;;AAYD,SAAgB,mBAAqD,MAAS;AAC5E,SAAQ,SAAkB;AACxB,SAAO,OAAO,QAAQ,KAAK,OAAO,CAAC,QAChC,QAAQ,CAAC,KAAK,WAAW;GAExB,MAAM,QAAQ;AACd,OAAI,QAAQ,KAIV,QAAO,QADL,QAAQ,OAAO,SAAS,WAAY,KAAiC,OAAO,WAClD,OAAO,YAAY;YACtC,MAAM,SAAS,SAExB,QAAO,OAAO,mBAAmB,EAAE,QAAQ,MAAM,QAAQ,CAAQ,CAC9D,KAAiC,KACnC;YACQ,MAAM,SAAS,OAAO,QAAQ;AACvC,WAAO,OAAO,MAAM,SAAS,MAAM,OAAO;KACxC,OAAQ,KAAiC;KACnC;KACN,MAAM;KACP,CAAC;AACF,QAAI,OAAO,gBAAgB,KACzB,QAAO,OAAO,OAAO,KAAK,aAAa;cAEhC,QAAQ,OAAO,SAAS,SACjC,QAAO,OAAQ,KAAiC;AAElD,UAAO;KAET,EAAE,CACH;;;;;;;;;;;AAYL,SAAgB,qBAEd,YACA,MACA;AACA,QAAO,EACL,aAAa;EACX,SAAS;EACT,QAAQ;EACR,WAAW,UAAmB;GAC5B,MAAM,SAAS,KAAK,MAAM;GAC1B,MAAM,SAAS,WAAW,MAAM;IAC9B,OAAO;IACP,MAAM;IACN,MAAM;IACP,CAAC;AACF,OAAI,OAAO,OACT,QAAO;AAET,UAAO,EAAE,OAAO,QAAa;;EAEhC,EACF"}
|
package/docs/cli/function.md
CHANGED
|
@@ -28,9 +28,10 @@ tailor-sdk function [command]
|
|
|
28
28
|
|
|
29
29
|
**Commands**
|
|
30
30
|
|
|
31
|
-
| Command
|
|
32
|
-
|
|
|
33
|
-
| [`function logs`](#function-logs)
|
|
31
|
+
| Command | Description |
|
|
32
|
+
| ----------------------------------------- | --------------------------------------------------------------- |
|
|
33
|
+
| [`function logs`](#function-logs) | List or get function execution logs. |
|
|
34
|
+
| [`function test-run`](#function-test-run) | Run a function on the Tailor Platform server without deploying. |
|
|
34
35
|
|
|
35
36
|
<!-- politty:command:function:subcommands:end -->
|
|
36
37
|
<!-- politty:command:function logs:heading:start -->
|
|
@@ -90,3 +91,82 @@ tailor-sdk function logs <execution-id>
|
|
|
90
91
|
tailor-sdk function logs --json
|
|
91
92
|
tailor-sdk function logs <execution-id> --json
|
|
92
93
|
```
|
|
94
|
+
|
|
95
|
+
<!-- politty:command:function test-run:heading:start -->
|
|
96
|
+
|
|
97
|
+
### function test-run
|
|
98
|
+
|
|
99
|
+
<!-- politty:command:function test-run:heading:end -->
|
|
100
|
+
<!-- politty:command:function test-run:description:start -->
|
|
101
|
+
|
|
102
|
+
Run a function on the Tailor Platform server without deploying.
|
|
103
|
+
|
|
104
|
+
<!-- politty:command:function test-run:description:end -->
|
|
105
|
+
<!-- politty:command:function test-run:usage:start -->
|
|
106
|
+
|
|
107
|
+
**Usage**
|
|
108
|
+
|
|
109
|
+
```
|
|
110
|
+
tailor-sdk function test-run [options] <file>
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
<!-- politty:command:function test-run:usage:end -->
|
|
114
|
+
<!-- politty:command:function test-run:arguments:start -->
|
|
115
|
+
|
|
116
|
+
**Arguments**
|
|
117
|
+
|
|
118
|
+
| Argument | Description | Required |
|
|
119
|
+
| -------- | ------------------------- | -------- |
|
|
120
|
+
| `file` | Path to the function file | Yes |
|
|
121
|
+
|
|
122
|
+
<!-- politty:command:function test-run:arguments:end -->
|
|
123
|
+
<!-- politty:command:function test-run:options:start -->
|
|
124
|
+
|
|
125
|
+
**Options**
|
|
126
|
+
|
|
127
|
+
| Option | Alias | Description | Required | Default |
|
|
128
|
+
| ------------------------------- | ----- | ------------------------------------------------------------------------ | -------- | -------------------- |
|
|
129
|
+
| `--json` | `-j` | Output as JSON | No | `false` |
|
|
130
|
+
| `--workspace-id <WORKSPACE_ID>` | `-w` | Workspace ID | No | - |
|
|
131
|
+
| `--profile <PROFILE>` | `-p` | Workspace profile | No | - |
|
|
132
|
+
| `--name <NAME>` | `-n` | Workflow job name to run (matches the `name` field of createWorkflowJob) | No | - |
|
|
133
|
+
| `--arg <ARG>` | `-a` | JSON argument to pass to the function | No | - |
|
|
134
|
+
| `--machine-user <MACHINE_USER>` | `-m` | Machine user name for authentication | No | - |
|
|
135
|
+
| `--config <CONFIG>` | `-c` | Path to SDK config file | No | `"tailor.config.ts"` |
|
|
136
|
+
|
|
137
|
+
<!-- politty:command:function test-run:options:end -->
|
|
138
|
+
<!-- politty:command:function test-run:examples:start -->
|
|
139
|
+
|
|
140
|
+
**Examples**
|
|
141
|
+
|
|
142
|
+
**Run a resolver with input arguments**
|
|
143
|
+
|
|
144
|
+
```bash
|
|
145
|
+
$ tailor-sdk function test-run resolvers/add.ts --arg '{"input":{"a":1,"b":2}}'
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
**Run a specific workflow job by name**
|
|
149
|
+
|
|
150
|
+
```bash
|
|
151
|
+
$ tailor-sdk function test-run workflows/sample.ts --name validate-order
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
**Run a pre-bundled .js file directly**
|
|
155
|
+
|
|
156
|
+
```bash
|
|
157
|
+
$ tailor-sdk function test-run .tailor-sdk/resolvers/add.js --arg '{"input":{"a":1,"b":2}}'
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
<!-- politty:command:function test-run:examples:end -->
|
|
161
|
+
<!-- politty:command:function test-run:notes:start -->
|
|
162
|
+
|
|
163
|
+
**Notes**
|
|
164
|
+
|
|
165
|
+
You can pass either a source file (`.ts`) or a pre-bundled file (`.js`).
|
|
166
|
+
When a `.js` file is provided, detection and bundling are skipped and the file is executed as-is.
|
|
167
|
+
|
|
168
|
+
> [!WARNING]
|
|
169
|
+
> Workflow job `.trigger()` calls do not work in test-run mode.
|
|
170
|
+
> Triggered jobs are not executed; only the target job's `body` function runs in isolation.
|
|
171
|
+
|
|
172
|
+
<!-- politty:command:function test-run:notes:end -->
|
|
@@ -214,3 +214,64 @@ createResolver({
|
|
|
214
214
|
// ...
|
|
215
215
|
});
|
|
216
216
|
```
|
|
217
|
+
|
|
218
|
+
## Event Publishing
|
|
219
|
+
|
|
220
|
+
Enable event publishing for a resolver to trigger executors on resolver execution:
|
|
221
|
+
|
|
222
|
+
```typescript
|
|
223
|
+
createResolver({
|
|
224
|
+
name: "processOrder",
|
|
225
|
+
operation: "mutation",
|
|
226
|
+
publishEvents: true,
|
|
227
|
+
// ...
|
|
228
|
+
});
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
**Behavior:**
|
|
232
|
+
|
|
233
|
+
- When `publishEvents: true`, resolver execution events are published
|
|
234
|
+
- When not specified, it is **automatically set to `true`** if an executor uses this resolver with `resolverExecutedTrigger`
|
|
235
|
+
- When explicitly set to `false` while an executor uses this resolver, an error is thrown during `tailor apply`
|
|
236
|
+
|
|
237
|
+
**Use cases:**
|
|
238
|
+
|
|
239
|
+
1. **Auto-detection (recommended)**: Don't set `publishEvents` - the SDK automatically enables it when needed by executors
|
|
240
|
+
|
|
241
|
+
```typescript
|
|
242
|
+
// publishEvents is automatically enabled because an executor uses this resolver
|
|
243
|
+
export default createResolver({
|
|
244
|
+
name: "processPayment",
|
|
245
|
+
operation: "mutation",
|
|
246
|
+
// publishEvents not set - auto-detected
|
|
247
|
+
// ...
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
// In executor file:
|
|
251
|
+
export default createExecutor({
|
|
252
|
+
trigger: resolverExecutedTrigger("processPayment"),
|
|
253
|
+
// ...
|
|
254
|
+
});
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
2. **Manual enable**: Enable event publishing for external consumers or debugging
|
|
258
|
+
|
|
259
|
+
```typescript
|
|
260
|
+
createResolver({
|
|
261
|
+
name: "auditAction",
|
|
262
|
+
operation: "mutation",
|
|
263
|
+
publishEvents: true, // Enable even without executor triggers
|
|
264
|
+
// ...
|
|
265
|
+
});
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
3. **Explicit disable**: Disable event publishing for a resolver that doesn't need it (error if executor uses it)
|
|
269
|
+
|
|
270
|
+
```typescript
|
|
271
|
+
createResolver({
|
|
272
|
+
name: "internalHelper",
|
|
273
|
+
operation: "query",
|
|
274
|
+
publishEvents: false, // Explicitly disable
|
|
275
|
+
// ...
|
|
276
|
+
});
|
|
277
|
+
```
|
|
@@ -394,6 +394,61 @@ db.type("User", {
|
|
|
394
394
|
});
|
|
395
395
|
```
|
|
396
396
|
|
|
397
|
+
#### Event Publishing
|
|
398
|
+
|
|
399
|
+
Enable event publishing for a type to trigger executors on record changes:
|
|
400
|
+
|
|
401
|
+
```typescript
|
|
402
|
+
db.type("User", {
|
|
403
|
+
name: db.string(),
|
|
404
|
+
}).features({
|
|
405
|
+
publishEvents: true,
|
|
406
|
+
});
|
|
407
|
+
```
|
|
408
|
+
|
|
409
|
+
**Behavior:**
|
|
410
|
+
|
|
411
|
+
- When `publishEvents: true`, record creation/update/deletion events are published
|
|
412
|
+
- When not specified, it is **automatically set to `true`** if an executor uses this type with `recordCreatedTrigger`, `recordUpdatedTrigger`, or `recordDeletedTrigger`
|
|
413
|
+
- When explicitly set to `false` while an executor uses this type, an error is thrown during `tailor apply`
|
|
414
|
+
|
|
415
|
+
**Use cases:**
|
|
416
|
+
|
|
417
|
+
1. **Auto-detection (recommended)**: Don't set `publishEvents` - the SDK automatically enables it when needed by executors
|
|
418
|
+
|
|
419
|
+
```typescript
|
|
420
|
+
// publishEvents is automatically enabled because an executor uses this type
|
|
421
|
+
export const order = db.type("Order", {
|
|
422
|
+
status: db.string(),
|
|
423
|
+
});
|
|
424
|
+
|
|
425
|
+
// In executor file:
|
|
426
|
+
export default createExecutor({
|
|
427
|
+
trigger: recordCreatedTrigger(order),
|
|
428
|
+
// ...
|
|
429
|
+
});
|
|
430
|
+
```
|
|
431
|
+
|
|
432
|
+
2. **Manual enable**: Enable event publishing for external consumers or debugging
|
|
433
|
+
|
|
434
|
+
```typescript
|
|
435
|
+
db.type("AuditLog", {
|
|
436
|
+
action: db.string(),
|
|
437
|
+
}).features({
|
|
438
|
+
publishEvents: true, // Enable even without executor triggers
|
|
439
|
+
});
|
|
440
|
+
```
|
|
441
|
+
|
|
442
|
+
3. **Explicit disable**: Disable event publishing for a type that doesn't need it (error if executor uses it)
|
|
443
|
+
|
|
444
|
+
```typescript
|
|
445
|
+
db.type("TempData", {
|
|
446
|
+
data: db.string(),
|
|
447
|
+
}).features({
|
|
448
|
+
publishEvents: false, // Explicitly disable
|
|
449
|
+
});
|
|
450
|
+
```
|
|
451
|
+
|
|
397
452
|
### Permissions
|
|
398
453
|
|
|
399
454
|
Configure Permission and GQLPermission. For details, see the [TailorDB Permission documentation](https://docs.tailor.tech/guides/tailordb/permission).
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tailor-platform/sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.22.0",
|
|
4
4
|
"description": "Tailor Platform SDK - The SDK to work with Tailor Platform",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
|
-
"url": "https://github.com/tailor-platform/sdk.git",
|
|
8
|
+
"url": "git+https://github.com/tailor-platform/sdk.git",
|
|
9
9
|
"directory": "packages/sdk"
|
|
10
10
|
},
|
|
11
11
|
"bin": {
|
|
@@ -92,6 +92,7 @@
|
|
|
92
92
|
"date-fns": "4.1.0",
|
|
93
93
|
"es-toolkit": "^1.44.0",
|
|
94
94
|
"find-up-simple": "1.0.1",
|
|
95
|
+
"globals": "17.0.0",
|
|
95
96
|
"inflection": "3.0.2",
|
|
96
97
|
"kysely": "0.28.10",
|
|
97
98
|
"madge": "8.0.0",
|
|
@@ -102,8 +103,9 @@
|
|
|
102
103
|
"oxc-parser": "0.108.0",
|
|
103
104
|
"p-limit": "7.2.0",
|
|
104
105
|
"pathe": "2.0.3",
|
|
106
|
+
"pgsql-ast-parser": "^12.0.2",
|
|
105
107
|
"pkg-types": "2.3.0",
|
|
106
|
-
"politty": "^0.4.
|
|
108
|
+
"politty": "^0.4.4",
|
|
107
109
|
"rolldown": "1.0.0-beta.60",
|
|
108
110
|
"serve": "14.2.5",
|
|
109
111
|
"std-env": "3.10.0",
|
|
@@ -128,7 +130,6 @@
|
|
|
128
130
|
"eslint": "9.39.2",
|
|
129
131
|
"eslint-plugin-jsdoc": "62.1.0",
|
|
130
132
|
"eslint-plugin-oxlint": "1.39.0",
|
|
131
|
-
"globals": "17.0.0",
|
|
132
133
|
"oxlint": "1.39.0",
|
|
133
134
|
"oxlint-tsgolint": "0.11.1",
|
|
134
135
|
"sonda": "0.10.1",
|
|
@@ -154,6 +155,7 @@
|
|
|
154
155
|
"prepublish": "pnpm run build",
|
|
155
156
|
"postinstall": "node postinstall.mjs",
|
|
156
157
|
"measure:bundle": "node ../../scripts/measure-bundle-size-sonda.js",
|
|
157
|
-
"knip": "knip"
|
|
158
|
+
"knip": "knip",
|
|
159
|
+
"publint": "publint --strict"
|
|
158
160
|
}
|
|
159
161
|
}
|