@tailor-platform/sdk 1.14.2 → 1.15.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 +25 -0
- package/dist/{application-DhwHYQ3H.mjs → application-DPunZ4lc.mjs} +2 -2
- package/dist/{application-DhwHYQ3H.mjs.map → application-DPunZ4lc.mjs.map} +1 -1
- package/dist/application-JwJ_-_PQ.mjs +4 -0
- package/dist/cli/index.mjs +3 -3
- package/dist/cli/lib.d.mts +53 -6
- package/dist/cli/lib.mjs +2 -2
- package/dist/cli/lib.mjs.map +1 -1
- package/dist/configure/index.d.mts +4 -4
- package/dist/configure/index.mjs +0 -7
- package/dist/configure/index.mjs.map +1 -1
- package/dist/{index-q3n7wQOs.d.mts → index-Bs9AsQb2.d.mts} +27 -11
- package/dist/{index-YzESrtj0.d.mts → index-DomkP6gz.d.mts} +2 -2
- package/dist/plugin/index.d.mts +1 -1
- package/dist/plugin/index.mjs.map +1 -1
- package/dist/{types-DbvONSS-.d.mts → types-Db1oxr0U.d.mts} +26 -67
- package/dist/{update-Dm8ERWHJ.mjs → update-C_ZTRB63.mjs} +354 -361
- package/dist/update-C_ZTRB63.mjs.map +1 -0
- package/dist/utils/test/index.d.mts +3 -3
- package/docs/plugin/custom.md +62 -45
- package/package.json +1 -1
- package/dist/application-BznueWxG.mjs +0 -4
- package/dist/update-Dm8ERWHJ.mjs.map +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference path="./../../user-defined.d.ts" />
|
|
2
|
-
import { M as TailorDBType,
|
|
3
|
-
import "../../index-
|
|
4
|
-
import { G as WORKFLOW_TEST_ENV_KEY, n as output } from "../../index-
|
|
2
|
+
import { M as TailorDBType, st as TailorField } from "../../types-Db1oxr0U.mjs";
|
|
3
|
+
import "../../index-DomkP6gz.mjs";
|
|
4
|
+
import { G as WORKFLOW_TEST_ENV_KEY, n as output } from "../../index-Bs9AsQb2.mjs";
|
|
5
5
|
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
6
6
|
|
|
7
7
|
//#region src/utils/test/index.d.ts
|
package/docs/plugin/custom.md
CHANGED
|
@@ -23,7 +23,7 @@ This is required so that generators can use plugin-generated TailorDB types via
|
|
|
23
23
|
## Plugin Interface
|
|
24
24
|
|
|
25
25
|
```typescript
|
|
26
|
-
interface Plugin<PluginConfig = unknown> {
|
|
26
|
+
interface Plugin<TypeConfig = unknown, PluginConfig = unknown> {
|
|
27
27
|
/** Unique identifier for the plugin (e.g., "@my-company/soft-delete") */
|
|
28
28
|
readonly id: string;
|
|
29
29
|
|
|
@@ -33,40 +33,34 @@ interface Plugin<PluginConfig = unknown> {
|
|
|
33
33
|
/** Import path for generated code to reference */
|
|
34
34
|
readonly importPath: string;
|
|
35
35
|
|
|
36
|
-
/** Schema for per-type configuration via .plugin() (required when using processType) */
|
|
37
|
-
readonly configSchema?: TailorAnyField;
|
|
38
|
-
|
|
39
|
-
/** Schema for plugin-level configuration via definePlugins() (optional) */
|
|
40
|
-
readonly pluginConfigSchema?: TailorAnyField;
|
|
41
|
-
|
|
42
36
|
/** Controls whether per-type config is required when attaching via .plugin() */
|
|
43
37
|
readonly typeConfigRequired?: boolean | ((pluginConfig?: PluginConfig) => boolean);
|
|
44
38
|
|
|
45
39
|
/** Plugin-level config passed via definePlugins() */
|
|
46
40
|
readonly pluginConfig?: PluginConfig;
|
|
47
41
|
|
|
48
|
-
/** Optional template for generating PluginConfigs typing */
|
|
49
|
-
readonly configTypeTemplate?: string;
|
|
50
|
-
|
|
51
42
|
/** Process a type with this plugin attached */
|
|
52
|
-
processType?(
|
|
43
|
+
processType?(
|
|
44
|
+
context: PluginProcessContext<TypeConfig, PluginConfig>,
|
|
45
|
+
): TypePluginOutput | Promise<TypePluginOutput>;
|
|
53
46
|
|
|
54
47
|
/** Process a namespace (plugins without a source type) */
|
|
55
48
|
processNamespace?(
|
|
56
|
-
context: PluginNamespaceProcessContext
|
|
57
|
-
):
|
|
49
|
+
context: PluginNamespaceProcessContext<PluginConfig>,
|
|
50
|
+
): PluginOutput | Promise<PluginOutput>;
|
|
58
51
|
}
|
|
59
52
|
```
|
|
60
53
|
|
|
61
54
|
Notes:
|
|
62
55
|
|
|
63
56
|
- `importPath` should be resolvable from the directory containing `tailor.config.ts`. Code generators use it to import plugin APIs such as `getGeneratedType` and executor modules.
|
|
64
|
-
- If you want to attach a plugin via `.plugin()`,
|
|
65
|
-
- Namespace-only plugins
|
|
57
|
+
- If you want to attach a plugin via `.plugin()`, implement the `processType` method.
|
|
58
|
+
- Namespace-only plugins implement `processNamespace` instead.
|
|
66
59
|
- `pluginConfig` stores the plugin-level config so it can be read later during processing. Set it on the plugin object (e.g., via a factory function) before passing to `definePlugins()`.
|
|
67
60
|
- `resolve` should return a dynamic import; relative specifiers are resolved from the plugin module.
|
|
68
61
|
- Per-type config is optional by default. Use `typeConfigRequired: true` to make it mandatory.
|
|
69
62
|
- To toggle optional/required based on plugin config, provide a function for `typeConfigRequired`.
|
|
63
|
+
- Use TypeScript type parameters (`TypeConfig`, `PluginConfig`) to get type-safe config in your `processType` and `processNamespace` methods.
|
|
70
64
|
|
|
71
65
|
## PluginProcessContext
|
|
72
66
|
|
|
@@ -102,9 +96,11 @@ interface PluginNamespaceProcessContext<PluginConfig = unknown> {
|
|
|
102
96
|
}
|
|
103
97
|
```
|
|
104
98
|
|
|
105
|
-
##
|
|
99
|
+
## Output Types
|
|
106
100
|
|
|
107
|
-
|
|
101
|
+
### PluginOutput (base)
|
|
102
|
+
|
|
103
|
+
Base output used by both `processType` and `processNamespace`:
|
|
108
104
|
|
|
109
105
|
```typescript
|
|
110
106
|
interface PluginOutput {
|
|
@@ -116,20 +112,24 @@ interface PluginOutput {
|
|
|
116
112
|
|
|
117
113
|
/** Additional executors to generate */
|
|
118
114
|
executors?: PluginGeneratedExecutor[];
|
|
115
|
+
}
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### TypePluginOutput
|
|
119
119
|
|
|
120
|
+
Return value from `processType`. Extends `PluginOutput` with the ability to add fields to the source type:
|
|
121
|
+
|
|
122
|
+
```typescript
|
|
123
|
+
interface TypePluginOutput extends PluginOutput {
|
|
120
124
|
/** Extensions to apply to the source type */
|
|
121
125
|
extends?: {
|
|
122
126
|
/** Fields to add to the source type */
|
|
123
|
-
fields?: Record<string,
|
|
127
|
+
fields?: Record<string, TailorAnyDBField>;
|
|
124
128
|
};
|
|
125
129
|
}
|
|
126
130
|
```
|
|
127
131
|
|
|
128
|
-
`processNamespace` returns `
|
|
129
|
-
|
|
130
|
-
```typescript
|
|
131
|
-
type NamespacePluginOutput = Omit<PluginOutput, "extends">;
|
|
132
|
-
```
|
|
132
|
+
`processNamespace` returns `PluginOutput` directly (namespace plugins cannot extend a source type).
|
|
133
133
|
|
|
134
134
|
## getGeneratedType Helper
|
|
135
135
|
|
|
@@ -196,8 +196,8 @@ A complete example of a plugin that adds soft delete functionality:
|
|
|
196
196
|
|
|
197
197
|
```typescript
|
|
198
198
|
// plugins/soft-delete/plugin.ts
|
|
199
|
-
import { db
|
|
200
|
-
import type { Plugin, PluginProcessContext,
|
|
199
|
+
import { db } from "@tailor-platform/sdk";
|
|
200
|
+
import type { Plugin, PluginProcessContext, TypePluginOutput } from "@tailor-platform/sdk";
|
|
201
201
|
|
|
202
202
|
interface SoftDeleteConfig {
|
|
203
203
|
archiveReason?: boolean;
|
|
@@ -210,22 +210,9 @@ interface SoftDeletePluginConfig {
|
|
|
210
210
|
requireTypeConfig?: boolean;
|
|
211
211
|
}
|
|
212
212
|
|
|
213
|
-
const configSchema = t.object({
|
|
214
|
-
archiveReason: t.bool({ optional: true }),
|
|
215
|
-
retentionDays: t.int({ optional: true }),
|
|
216
|
-
// Use { required: true } to mark fields as required in plugin configs.
|
|
217
|
-
// By default, plugin config fields are optional.
|
|
218
|
-
// token: t.string({ required: true }),
|
|
219
|
-
});
|
|
220
|
-
|
|
221
|
-
const pluginConfigSchema = t.object({
|
|
222
|
-
archiveTablePrefix: t.string({ optional: true }),
|
|
223
|
-
defaultRetentionDays: t.int({ optional: true }),
|
|
224
|
-
});
|
|
225
|
-
|
|
226
213
|
function processSoftDelete(
|
|
227
214
|
context: PluginProcessContext<SoftDeleteConfig, SoftDeletePluginConfig>,
|
|
228
|
-
):
|
|
215
|
+
): TypePluginOutput {
|
|
229
216
|
const { type, typeConfig, pluginConfig, namespace } = context;
|
|
230
217
|
const prefix = pluginConfig?.archiveTablePrefix ?? "Deleted_";
|
|
231
218
|
|
|
@@ -266,13 +253,13 @@ function processSoftDelete(
|
|
|
266
253
|
}
|
|
267
254
|
|
|
268
255
|
// Factory function for plugins with plugin-level config
|
|
269
|
-
function createSoftDeletePlugin(
|
|
256
|
+
function createSoftDeletePlugin(
|
|
257
|
+
pluginConfig?: SoftDeletePluginConfig,
|
|
258
|
+
): Plugin<SoftDeleteConfig, SoftDeletePluginConfig> {
|
|
270
259
|
return {
|
|
271
260
|
id: "@example/soft-delete",
|
|
272
261
|
description: "Adds soft delete with archive functionality",
|
|
273
262
|
importPath: "./plugins/soft-delete",
|
|
274
|
-
configSchema,
|
|
275
|
-
pluginConfigSchema,
|
|
276
263
|
pluginConfig,
|
|
277
264
|
typeConfigRequired: (config) => config?.requireTypeConfig === true,
|
|
278
265
|
processType: processSoftDelete,
|
|
@@ -287,8 +274,9 @@ export default createSoftDeletePlugin();
|
|
|
287
274
|
|
|
288
275
|
```typescript
|
|
289
276
|
// plugins/soft-delete/executors/on-delete.ts
|
|
290
|
-
import { createExecutor, recordDeletedTrigger
|
|
277
|
+
import { createExecutor, recordDeletedTrigger } from "@tailor-platform/sdk";
|
|
291
278
|
import type { TailorAnyDBType } from "@tailor-platform/sdk";
|
|
279
|
+
import { withPluginContext } from "@tailor-platform/sdk/plugin";
|
|
292
280
|
import { getDB } from "generated/tailordb";
|
|
293
281
|
|
|
294
282
|
interface SoftDeleteContext {
|
|
@@ -365,10 +353,39 @@ export const plugins = definePlugins(
|
|
|
365
353
|
|
|
366
354
|
## Adding Type Safety
|
|
367
355
|
|
|
368
|
-
|
|
356
|
+
Plugin type safety is provided at two levels:
|
|
357
|
+
|
|
358
|
+
### Plugin-level type safety (TypeConfig / PluginConfig)
|
|
359
|
+
|
|
360
|
+
Use TypeScript type parameters on `Plugin<TypeConfig, PluginConfig>` to get type-safe config
|
|
361
|
+
in `processType` and `processNamespace` methods:
|
|
362
|
+
|
|
363
|
+
```typescript
|
|
364
|
+
interface MyTypeConfig {
|
|
365
|
+
archiveReason?: boolean;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
interface MyPluginConfig {
|
|
369
|
+
prefix?: string;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
const plugin: Plugin<MyTypeConfig, MyPluginConfig> = {
|
|
373
|
+
id: "@example/my-plugin",
|
|
374
|
+
// ...
|
|
375
|
+
processType(context) {
|
|
376
|
+
// context.typeConfig is MyTypeConfig
|
|
377
|
+
// context.pluginConfig is MyPluginConfig
|
|
378
|
+
},
|
|
379
|
+
};
|
|
380
|
+
```
|
|
381
|
+
|
|
382
|
+
### Per-type `.plugin()` type safety (declaration merging)
|
|
383
|
+
|
|
384
|
+
To enable type checking when users attach plugins via `.plugin()`, provide a declaration merge
|
|
385
|
+
for the `PluginConfigs` interface. Plugin authors should ship this in their package's type definitions:
|
|
369
386
|
|
|
370
387
|
```typescript
|
|
371
|
-
//
|
|
388
|
+
// your-plugin/types.d.ts (shipped with your plugin package)
|
|
372
389
|
declare module "@tailor-platform/sdk" {
|
|
373
390
|
interface PluginConfigs<Fields extends string> {
|
|
374
391
|
"@example/soft-delete": {
|
package/package.json
CHANGED