@postxl/generators 3.1.2 → 3.2.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/dist/backend-repositories/generators/model-repository.generator.js +19 -3
- package/dist/backend-repositories/generators/model-repository.generator.js.map +1 -1
- package/dist/backend-update/model-update-service.generator.js +74 -7
- package/dist/backend-update/model-update-service.generator.js.map +1 -1
- package/dist/frontend-core/frontend.generator.js +28 -1
- package/dist/frontend-core/frontend.generator.js.map +1 -1
- package/dist/frontend-core/template/.gitignore.template +4 -0
- package/dist/frontend-core/template/src/main.tsx +3 -1
- package/dist/frontend-core/template/vite.config.ts +9 -0
- package/dist/frontend-core/types.d.ts +7 -0
- package/dist/generators.js +2 -0
- package/dist/generators.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/dist/skailify/generators/capabilities-file.generator.d.ts +29 -0
- package/dist/skailify/generators/capabilities-file.generator.js +195 -0
- package/dist/skailify/generators/capabilities-file.generator.js.map +1 -0
- package/dist/skailify/generators/field-to-zod.helper.d.ts +16 -0
- package/dist/skailify/generators/field-to-zod.helper.js +74 -0
- package/dist/skailify/generators/field-to-zod.helper.js.map +1 -0
- package/dist/skailify/generators/model-scope.helper.d.ts +25 -0
- package/dist/skailify/generators/model-scope.helper.js +42 -0
- package/dist/skailify/generators/model-scope.helper.js.map +1 -0
- package/dist/skailify/generators/preview-json.generator.d.ts +1 -0
- package/dist/skailify/generators/preview-json.generator.js +15 -0
- package/dist/skailify/generators/preview-json.generator.js.map +1 -0
- package/dist/skailify/generators/skaile-app-file.generator.d.ts +3 -0
- package/dist/skailify/generators/skaile-app-file.generator.js +92 -0
- package/dist/skailify/generators/skaile-app-file.generator.js.map +1 -0
- package/dist/skailify/index.d.ts +2 -0
- package/dist/skailify/index.js +7 -0
- package/dist/skailify/index.js.map +1 -0
- package/dist/skailify/skailify.generator.d.ts +6 -0
- package/dist/skailify/skailify.generator.js +136 -0
- package/dist/skailify/skailify.generator.js.map +1 -0
- package/dist/skailify/template/src/skailify/shared/capability-def.ts +52 -0
- package/dist/skailify/template/src/skailify/shared/merge-partial-update.test.ts +30 -0
- package/dist/skailify/template/src/skailify/shared/merge-partial-update.ts +14 -0
- package/package.json +2 -2
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateSkaileAppFile = generateSkaileAppFile;
|
|
4
|
+
function capitalize(value) {
|
|
5
|
+
return value.length > 0 ? value[0].toUpperCase() + value.slice(1) : value;
|
|
6
|
+
}
|
|
7
|
+
function generateSkaileAppFile(models) {
|
|
8
|
+
const imports = models
|
|
9
|
+
.map((m) => `import { build${capitalize(m.camelCase)}Capabilities } from './skailify/${m.camelCase}.capabilities'`)
|
|
10
|
+
.join('\n');
|
|
11
|
+
const builderCalls = models.map((m) => ` ...build${capitalize(m.camelCase)}Capabilities(client),`).join('\n');
|
|
12
|
+
return `import {
|
|
13
|
+
consoleLogger,
|
|
14
|
+
createSkaileApp,
|
|
15
|
+
createWebSocketAppTransport,
|
|
16
|
+
defineAppCapability,
|
|
17
|
+
resolveAppConnectionParams,
|
|
18
|
+
type AppConnectionParams,
|
|
19
|
+
type AppSession,
|
|
20
|
+
type SkaileApp,
|
|
21
|
+
} from '@skaile/workspaces/app-sdk'
|
|
22
|
+
|
|
23
|
+
import { APP_CONFIG } from '@lib/config'
|
|
24
|
+
import { createTrpcClient } from '@lib/trpc'
|
|
25
|
+
|
|
26
|
+
${imports}
|
|
27
|
+
|
|
28
|
+
// Must match the \`id\` of the frontend app in skaile.preview.json.
|
|
29
|
+
const APP_ID = 'frontend'
|
|
30
|
+
|
|
31
|
+
export function startSkaileApp(): () => void {
|
|
32
|
+
let closed = false
|
|
33
|
+
let app: SkaileApp | null = null
|
|
34
|
+
|
|
35
|
+
async function run(): Promise<void> {
|
|
36
|
+
let primed: AppConnectionParams | null = await resolveAppConnectionParams({ appId: APP_ID })
|
|
37
|
+
if (closed) {
|
|
38
|
+
return
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const transport = createWebSocketAppTransport({
|
|
42
|
+
url: primed.url,
|
|
43
|
+
sessionToken: () => {
|
|
44
|
+
// First connect reuses the params already fetched; every reconnect
|
|
45
|
+
// re-resolves, since the gateway burns the token at app_hello.
|
|
46
|
+
if (primed) {
|
|
47
|
+
const token = primed.token
|
|
48
|
+
primed = null
|
|
49
|
+
return token
|
|
50
|
+
}
|
|
51
|
+
return resolveAppConnectionParams({ appId: APP_ID }).then((p) => p.token)
|
|
52
|
+
},
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
app = createSkaileApp({ appId: APP_ID, transport, logger: consoleLogger })
|
|
56
|
+
|
|
57
|
+
const client = createTrpcClient({ apiUrl: APP_CONFIG.apiURL })
|
|
58
|
+
const capabilityDefs = [
|
|
59
|
+
${builderCalls}
|
|
60
|
+
]
|
|
61
|
+
for (const def of capabilityDefs) {
|
|
62
|
+
app.registerCapability(defineAppCapability(def as never))
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
app.onSessionChange((_session: AppSession | null) => {
|
|
66
|
+
// No UI to reflect connection state in a generated app by default.
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
if (closed) {
|
|
70
|
+
void app.close()
|
|
71
|
+
return
|
|
72
|
+
}
|
|
73
|
+
await app.connect()
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
void run().catch((error) => {
|
|
77
|
+
// A standalone (non-embedded) app has no host to answer skaile_app_ready;
|
|
78
|
+
// the SDK already reports this as a connection error. Any other failure
|
|
79
|
+
// (a schema/SDK mismatch, a registration error) is logged so it's not silent.
|
|
80
|
+
consoleLogger.debug('skaile app-channel did not start', { error })
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
return () => {
|
|
84
|
+
closed = true
|
|
85
|
+
if (app) {
|
|
86
|
+
void app.close()
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
`;
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=skaile-app-file.generator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"skaile-app-file.generator.js","sourceRoot":"","sources":["../../../src/skailify/generators/skaile-app-file.generator.ts"],"names":[],"mappings":";;AAIA,sDAsFC;AA1FD,SAAS,UAAU,CAAC,KAAa;IAC/B,OAAO,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAE,CAAC,WAAW,EAAE,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAA;AAC5E,CAAC;AAED,SAAgB,qBAAqB,CAAC,MAA+B;IACnE,MAAM,OAAO,GAAG,MAAM;SACnB,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,iBAAiB,UAAU,CAAC,CAAC,CAAC,SAAS,CAAC,mCAAmC,CAAC,CAAC,SAAS,gBAAgB,CAAC;SAClH,IAAI,CAAC,IAAI,CAAC,CAAA;IAEb,MAAM,YAAY,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,eAAe,UAAU,CAAC,CAAC,CAAC,SAAS,CAAC,uBAAuB,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IAEhH,OAAO;;;;;;;;;;;;;;EAcP,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAiCP,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA+Bb,CAAA;AACD,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.skailifyGeneratorId = exports.configureSkailifyGenerator = void 0;
|
|
4
|
+
var skailify_generator_1 = require("./skailify.generator");
|
|
5
|
+
Object.defineProperty(exports, "configureSkailifyGenerator", { enumerable: true, get: function () { return skailify_generator_1.configureSkailifyGenerator; } });
|
|
6
|
+
Object.defineProperty(exports, "skailifyGeneratorId", { enumerable: true, get: function () { return skailify_generator_1.skailifyGeneratorId; } });
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/skailify/index.ts"],"names":[],"mappings":";;;AAAA,2DAAsF;AAA7E,gIAAA,0BAA0B,OAAA;AAAE,yHAAA,mBAAmB,OAAA"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import * as Generator from '@postxl/generator';
|
|
2
|
+
export type SkailifyOptions = {
|
|
3
|
+
enabled?: boolean;
|
|
4
|
+
};
|
|
5
|
+
export declare const skailifyGeneratorId: string & import("zod").$brand<"PXL.GeneratorInterfaceId">;
|
|
6
|
+
export declare const configureSkailifyGenerator: (options?: SkailifyOptions) => Generator.GeneratorInterface;
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.configureSkailifyGenerator = exports.skailifyGeneratorId = void 0;
|
|
37
|
+
const Path = __importStar(require("node:path"));
|
|
38
|
+
const Generator = __importStar(require("@postxl/generator"));
|
|
39
|
+
const capabilities_file_generator_1 = require("./generators/capabilities-file.generator");
|
|
40
|
+
const model_scope_helper_1 = require("./generators/model-scope.helper");
|
|
41
|
+
const preview_json_generator_1 = require("./generators/preview-json.generator");
|
|
42
|
+
const skaile_app_file_generator_1 = require("./generators/skaile-app-file.generator");
|
|
43
|
+
exports.skailifyGeneratorId = Generator.toGeneratorInterfaceId('skailify');
|
|
44
|
+
const configureSkailifyGenerator = (options = {}) => {
|
|
45
|
+
const enabled = options.enabled ?? true;
|
|
46
|
+
return {
|
|
47
|
+
id: exports.skailifyGeneratorId,
|
|
48
|
+
requires: [
|
|
49
|
+
// Explicitly listed (and ordered) ahead of `frontend-core` even though
|
|
50
|
+
// `frontend-core` itself doesn't declare `base` as a formal dependency:
|
|
51
|
+
// `frontend-core`'s register() reads `context.base.packageJson` on trust that
|
|
52
|
+
// `base` already ran. In the full production registry the insertion order in
|
|
53
|
+
// `generators.ts` happens to make that true, but `GeneratorManager.registerTestGenerator`
|
|
54
|
+
// builds the dependency graph from a single generator's own `requires` array, and
|
|
55
|
+
// topological sort otherwise pushes `frontend-core` (which has `requires: []`) to the
|
|
56
|
+
// front, before `base` is ever reached transitively via `types`. Listing `base` first
|
|
57
|
+
// here mirrors the same convention already used by `frontend-forms` and
|
|
58
|
+
// `frontend-trpc-client` for the same reason.
|
|
59
|
+
Generator.toGeneratorInterfaceId('base'),
|
|
60
|
+
Generator.toGeneratorInterfaceId('frontend-core'),
|
|
61
|
+
Generator.toGeneratorInterfaceId('types'),
|
|
62
|
+
Generator.toGeneratorInterfaceId('frontend-trpc-client'),
|
|
63
|
+
],
|
|
64
|
+
register: (context) => {
|
|
65
|
+
if (!enabled) {
|
|
66
|
+
return context;
|
|
67
|
+
}
|
|
68
|
+
context.frontend.packageJson.dependencies.push({ packageName: '@skaile/workspaces', version: '^1.11.0' });
|
|
69
|
+
context.frontend.mountEffects.push({ importFrom: './skaile-app', importName: 'startSkaileApp' });
|
|
70
|
+
return context;
|
|
71
|
+
},
|
|
72
|
+
generate: async (context) => {
|
|
73
|
+
if (!enabled) {
|
|
74
|
+
return context;
|
|
75
|
+
}
|
|
76
|
+
context.vfs.write('/skaile.preview.json', (0, preview_json_generator_1.generateSkailePreviewJson)());
|
|
77
|
+
const getRelatedModelIdDecoderName = (referencedModelName) => {
|
|
78
|
+
const relatedModel = context.models.get(referencedModelName);
|
|
79
|
+
if (!relatedModel) {
|
|
80
|
+
throw new Error(`skailify: unknown related model "${referencedModelName}"`);
|
|
81
|
+
}
|
|
82
|
+
return relatedModel.types.id.decoder.name;
|
|
83
|
+
};
|
|
84
|
+
const getEnumMemberValues = (enumName) => {
|
|
85
|
+
const enum_ = context.enums.get(enumName);
|
|
86
|
+
if (!enum_) {
|
|
87
|
+
throw new Error(`skailify: unknown enum "${enumName}"`);
|
|
88
|
+
}
|
|
89
|
+
return [...enum_.members.values()].map((member) => member.value);
|
|
90
|
+
};
|
|
91
|
+
const vfs = new Generator.VirtualFileSystem();
|
|
92
|
+
for (const model of context.targetModels.values()) {
|
|
93
|
+
if ((0, model_scope_helper_1.isStandardModel)(model)) {
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
const content = (0, capabilities_file_generator_1.generateModelCapabilitiesFile)({
|
|
97
|
+
// `model`/`context.schema.schemaAuth` come from `@postxl/schema`'s zod-inferred
|
|
98
|
+
// `AuthRuleSet` (whose optional fields are typed `T | undefined` under
|
|
99
|
+
// `exactOptionalPropertyTypes`), while `CapabilitiesFileModel`/`ModelRuleSet` (Task 6/3)
|
|
100
|
+
// declare the same shape without the explicit `| undefined`. The two are runtime-identical
|
|
101
|
+
// (a plain-object auth-rule shape); this cast only bridges the type-level mismatch.
|
|
102
|
+
model: model,
|
|
103
|
+
schemaAuthRules: context.schema.schemaAuth,
|
|
104
|
+
defaultDeny: context.schema.auth?.defaultDeny ?? true,
|
|
105
|
+
getRelatedModelIdDecoderName,
|
|
106
|
+
getEnumMemberValues,
|
|
107
|
+
});
|
|
108
|
+
if (content) {
|
|
109
|
+
vfs.write(`/src/skailify/${model._conjugated.camelCase}.capabilities.ts`, content);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
// Intentionally uses the same verb-pruning check as the per-model loop above,
|
|
113
|
+
// not just isStandardModel — a model with zero generated verbs has no
|
|
114
|
+
// .capabilities.ts file to import, so it must also be excluded here or the
|
|
115
|
+
// generated skaile-app.ts references a module that doesn't exist.
|
|
116
|
+
const inScopeModels = [...context.models.values()].filter((model) => {
|
|
117
|
+
if ((0, model_scope_helper_1.isStandardModel)(model)) {
|
|
118
|
+
return false;
|
|
119
|
+
}
|
|
120
|
+
const verbs = (0, model_scope_helper_1.getGeneratedCapabilityVerbs)({
|
|
121
|
+
// See the matching cast/comment above generateModelCapabilitiesFile's call.
|
|
122
|
+
model: model,
|
|
123
|
+
schemaAuthRules: context.schema.schemaAuth,
|
|
124
|
+
defaultDeny: context.schema.auth?.defaultDeny ?? true,
|
|
125
|
+
});
|
|
126
|
+
return verbs.size > 0;
|
|
127
|
+
});
|
|
128
|
+
vfs.write('/src/skaile-app.ts', (0, skaile_app_file_generator_1.generateSkaileAppFile)(inScopeModels.map((model) => ({ camelCase: model._conjugated.camelCase }))));
|
|
129
|
+
await vfs.loadFolder({ diskPath: Path.join(__dirname, './template/src'), targetPath: '/src', recursive: true });
|
|
130
|
+
context.vfs.insertFromVfs({ targetPath: '/frontend', vfs });
|
|
131
|
+
return context;
|
|
132
|
+
},
|
|
133
|
+
};
|
|
134
|
+
};
|
|
135
|
+
exports.configureSkailifyGenerator = configureSkailifyGenerator;
|
|
136
|
+
//# sourceMappingURL=skailify.generator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"skailify.generator.js","sourceRoot":"","sources":["../../src/skailify/skailify.generator.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gDAAiC;AAEjC,6DAA8C;AAM9C,0FAA+G;AAC/G,wEAKwC;AACxC,gFAA+E;AAC/E,sFAA8E;AAMjE,QAAA,mBAAmB,GAAG,SAAS,CAAC,sBAAsB,CAAC,UAAU,CAAC,CAAA;AAOxE,MAAM,0BAA0B,GAAG,CAAC,UAA2B,EAAE,EAAgC,EAAE;IACxG,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,IAAI,IAAI,CAAA;IAEvC,OAAO;QACL,EAAE,EAAE,2BAAmB;QACvB,QAAQ,EAAE;YACR,uEAAuE;YACvE,wEAAwE;YACxE,8EAA8E;YAC9E,6EAA6E;YAC7E,0FAA0F;YAC1F,kFAAkF;YAClF,sFAAsF;YACtF,sFAAsF;YACtF,wEAAwE;YACxE,8CAA8C;YAC9C,SAAS,CAAC,sBAAsB,CAAC,MAAM,CAAC;YACxC,SAAS,CAAC,sBAAsB,CAAC,eAAe,CAAC;YACjD,SAAS,CAAC,sBAAsB,CAAC,OAAO,CAAC;YACzC,SAAS,CAAC,sBAAsB,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,EAAE,KAAiC;oBACxC,eAAe,EAAE,OAAO,CAAC,MAAM,CAAC,UAAkD;oBAClF,WAAW,EAAE,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,WAAW,IAAI,IAAI;iBACtD,CAAC,CAAA;gBACF,OAAO,KAAK,CAAC,IAAI,GAAG,CAAC,CAAA;YACvB,CAAC,CAAC,CAAA;YACF,GAAG,CAAC,KAAK,CACP,oBAAoB,EACpB,IAAA,iDAAqB,EAAC,aAAa,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,EAAE,SAAS,EAAE,KAAK,CAAC,WAAW,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,CAClG,CAAA;YAED,MAAM,GAAG,CAAC,UAAU,CAAC,EAAE,QAAQ,EAAE,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,gBAAgB,CAAC,EAAE,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAA;YAE/G,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,EAAE,UAAU,EAAE,WAAW,EAAE,GAAG,EAAE,CAAC,CAAA;YAE3D,OAAO,OAAO,CAAA;QAChB,CAAC;KACF,CAAA;AACH,CAAC,CAAA;AA3GY,QAAA,0BAA0B,8BA2GtC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type * as z from 'zod'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A model-agnostic description of one Skailify capability. Deliberately has no
|
|
5
|
+
* dependency on `@skaile/workspaces/app-sdk` — `skaile-app.ts` is the only file
|
|
6
|
+
* that bridges this shape into the SDK's own `defineAppCapability`.
|
|
7
|
+
*/
|
|
8
|
+
export type SkailifyCapabilityDef = {
|
|
9
|
+
name: string
|
|
10
|
+
displayName: string
|
|
11
|
+
description: string
|
|
12
|
+
kind: 'query' | 'effect'
|
|
13
|
+
requiresApproval?: boolean
|
|
14
|
+
audience: readonly ('llm' | 'user')[]
|
|
15
|
+
input: z.ZodTypeAny
|
|
16
|
+
output?: z.ZodTypeAny
|
|
17
|
+
handler: (input: never, ctx: SkailifyHandlerContext) => Promise<unknown>
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export type SkailifyHandlerContext = {
|
|
21
|
+
sessionId: string
|
|
22
|
+
appId: string
|
|
23
|
+
log: {
|
|
24
|
+
info: (message: string, data?: Record<string, unknown>) => void
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Defines one capability with its `input` schema and `handler` correlated by a
|
|
30
|
+
* generic type parameter — mirrors `@skaile/workspaces/app-sdk`'s own
|
|
31
|
+
* `defineAppCapability`. Writing the object literal directly as a
|
|
32
|
+
* `SkailifyCapabilityDef` (whose `handler` is type-erased to `(input: never, ...)`
|
|
33
|
+
* for storage in a heterogeneous array) would force TypeScript to contextually
|
|
34
|
+
* type each handler's `input` parameter as `never`, breaking every property
|
|
35
|
+
* access inside it. Going through this generic function instead lets each call
|
|
36
|
+
* site's own `input` schema drive its own handler's parameter type, and the
|
|
37
|
+
* (always-safe, since `never` is a subtype of everything) erasure back down to
|
|
38
|
+
* `SkailifyCapabilityDef` happens once, here.
|
|
39
|
+
*/
|
|
40
|
+
export function defineCapability<T extends z.ZodTypeAny>(def: {
|
|
41
|
+
name: string
|
|
42
|
+
displayName: string
|
|
43
|
+
description: string
|
|
44
|
+
kind: 'query' | 'effect'
|
|
45
|
+
requiresApproval?: boolean
|
|
46
|
+
audience: readonly ('llm' | 'user')[]
|
|
47
|
+
input: T
|
|
48
|
+
output?: z.ZodTypeAny
|
|
49
|
+
handler: (input: z.infer<T>, ctx: SkailifyHandlerContext) => Promise<unknown>
|
|
50
|
+
}): SkailifyCapabilityDef {
|
|
51
|
+
return def
|
|
52
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { describe, expect, test } from 'vitest'
|
|
2
|
+
|
|
3
|
+
import { mergePartialUpdate } from './merge-partial-update'
|
|
4
|
+
|
|
5
|
+
describe('mergePartialUpdate', () => {
|
|
6
|
+
test('leaves fields not present in the patch unchanged', () => {
|
|
7
|
+
const current = { title: 'A', body: 'B', viewCount: 5 }
|
|
8
|
+
const patch = { title: 'A2' }
|
|
9
|
+
expect(mergePartialUpdate(current, patch)).toEqual({ title: 'A2', body: 'B', viewCount: 5 })
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
test('ignores a patch key whose value is explicitly undefined', () => {
|
|
13
|
+
const current = { title: 'A', body: 'B' }
|
|
14
|
+
const patch = { title: undefined, body: 'B2' }
|
|
15
|
+
expect(mergePartialUpdate(current, patch)).toEqual({ title: 'A', body: 'B2' })
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
test('applies an explicit null to clear a nullable field', () => {
|
|
19
|
+
const current = { author: 'x@example.com' as string | null }
|
|
20
|
+
const patch = { author: null }
|
|
21
|
+
expect(mergePartialUpdate(current, patch)).toEqual({ author: null })
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
test('returns a new object, not a mutated current', () => {
|
|
25
|
+
const current = { title: 'A' }
|
|
26
|
+
const merged = mergePartialUpdate(current, { title: 'B' })
|
|
27
|
+
expect(current).toEqual({ title: 'A' })
|
|
28
|
+
expect(merged).not.toBe(current)
|
|
29
|
+
})
|
|
30
|
+
})
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shallow-merge a partial patch over a current row, skipping any key whose
|
|
3
|
+
* patch value is `undefined` (an omitted/untouched field) while still
|
|
4
|
+
* applying an explicit `null` (clearing a nullable field).
|
|
5
|
+
*/
|
|
6
|
+
export function mergePartialUpdate<T extends Record<string, unknown>>(current: T, patch: Partial<T>): T {
|
|
7
|
+
const result = { ...current }
|
|
8
|
+
for (const key of Object.keys(patch) as (keyof T)[]) {
|
|
9
|
+
if (patch[key] !== undefined) {
|
|
10
|
+
result[key] = patch[key] as T[keyof T]
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
return result
|
|
14
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@postxl/generators",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.2.0",
|
|
4
4
|
"description": "Code generators for PXL - generates backend, frontend, Prisma schemas, and more",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -45,8 +45,8 @@
|
|
|
45
45
|
"@prisma/prisma-schema-wasm": "7.8.0-6.3c6e192761c0362d496ed980de936e2f3cebcd3a",
|
|
46
46
|
"exceljs": "^4.4.0",
|
|
47
47
|
"@postxl/schema": "^2.2.0",
|
|
48
|
-
"@postxl/ui-components": "^1.8.2",
|
|
49
48
|
"@postxl/generator": "^1.7.2",
|
|
49
|
+
"@postxl/ui-components": "^1.8.2",
|
|
50
50
|
"@postxl/utils": "^1.4.2"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {},
|