@stripe/extensibility-custom-objects-tools 0.40.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/LICENSE.md +19 -0
- package/README.md +32 -0
- package/dist/build/build.d.ts +46 -0
- package/dist/build/build.d.ts.map +1 -0
- package/dist/build/cli.cjs +992 -0
- package/dist/build/cli.d.ts +3 -0
- package/dist/build/cli.d.ts.map +1 -0
- package/dist/build/cli.js +991 -0
- package/dist/build/extract-schemas.cli.cjs +8747 -0
- package/dist/build/extract-schemas.cli.d.ts +9 -0
- package/dist/build/extract-schemas.cli.d.ts.map +1 -0
- package/dist/build/extract-schemas.cli.js +8738 -0
- package/dist/build/extract-schemas.d.ts +17 -0
- package/dist/build/extract-schemas.d.ts.map +1 -0
- package/dist/build/package-build.d.ts +115 -0
- package/dist/build/package-build.d.ts.map +1 -0
- package/dist/extensibility-custom-objects-tools-alpha.d.ts +153 -0
- package/dist/extensibility-custom-objects-tools-beta.d.ts +32 -0
- package/dist/extensibility-custom-objects-tools-internal-alpha.d.ts +77 -0
- package/dist/extensibility-custom-objects-tools-internal-beta.d.ts +77 -0
- package/dist/extensibility-custom-objects-tools-internal-internal.d.ts +475 -0
- package/dist/extensibility-custom-objects-tools-internal-public.d.ts +77 -0
- package/dist/extensibility-custom-objects-tools-internal.d.ts +153 -0
- package/dist/extensibility-custom-objects-tools-public.d.ts +32 -0
- package/dist/generators/index.d.ts +43 -0
- package/dist/generators/index.d.ts.map +1 -0
- package/dist/index.cjs +956 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +927 -0
- package/dist/internal.cjs +8820 -0
- package/dist/internal.d.ts +7 -0
- package/dist/internal.d.ts.map +1 -0
- package/dist/internal.js +8791 -0
- package/dist/transformer/classify-fields.d.ts +105 -0
- package/dist/transformer/classify-fields.d.ts.map +1 -0
- package/dist/transformer/generate-descriptors.d.ts +72 -0
- package/dist/transformer/generate-descriptors.d.ts.map +1 -0
- package/dist/transformer/metadata.d.ts +25 -0
- package/dist/transformer/metadata.d.ts.map +1 -0
- package/dist/transformer/transform.d.ts +35 -0
- package/dist/transformer/transform.d.ts.map +1 -0
- package/dist/transformer/types.d.ts +146 -0
- package/dist/transformer/types.d.ts.map +1 -0
- package/dist/transformer/visitors.d.ts +99 -0
- package/dist/transformer/visitors.d.ts.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -0
- package/generators/custom-object/files/___packagesSubfolder___/src/___apiName___.object.ts.mustache +95 -0
- package/generators/custom-object-test/files/___packagesSubfolder___/src/___apiName___.object.test.ts.mustache +35 -0
- package/generators/custom-objects-workspace/files/___packagesSubfolder___/package.json.mustache +20 -0
- package/generators/custom-objects-workspace/files/___packagesSubfolder___/tsconfig.json +9 -0
- package/package.json +77 -0
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Classifies JSON Schema properties into `FieldClassification` trees for
|
|
3
|
+
* wire↔native type conversion descriptor generation.
|
|
4
|
+
*
|
|
5
|
+
* Custom objects don't have proto-parsed `TransformedField` objects like
|
|
6
|
+
* extension interfaces. Instead, field classification is driven by the
|
|
7
|
+
* JSON Schema output of the FormSpec extraction pipeline.
|
|
8
|
+
*
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Field classification tree — a subset of the internal-codegen
|
|
13
|
+
* `FieldClassification` type (omits `union`), defined locally to avoid a
|
|
14
|
+
* cross-package import from the codegen library (which is a build-time-only tool).
|
|
15
|
+
* @internal
|
|
16
|
+
*/
|
|
17
|
+
export type FieldClassification = {
|
|
18
|
+
kind: 'primitive';
|
|
19
|
+
} | {
|
|
20
|
+
kind: 'decimal';
|
|
21
|
+
} | {
|
|
22
|
+
kind: 'datetime';
|
|
23
|
+
} | {
|
|
24
|
+
kind: 'enum';
|
|
25
|
+
typeName: string;
|
|
26
|
+
} | {
|
|
27
|
+
kind: 'interface';
|
|
28
|
+
typeName: string;
|
|
29
|
+
} | {
|
|
30
|
+
kind: 'array';
|
|
31
|
+
element: FieldClassification;
|
|
32
|
+
} | {
|
|
33
|
+
kind: 'map';
|
|
34
|
+
value: FieldClassification;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Minimal JSON Schema shape we inspect during classification.
|
|
38
|
+
* Only the fields relevant to classification are typed — the full
|
|
39
|
+
* `JsonSchema2020` type from `@formspec/build` is a superset.
|
|
40
|
+
* @internal
|
|
41
|
+
*/
|
|
42
|
+
export interface JsonSchemaNode {
|
|
43
|
+
readonly type?: string | undefined;
|
|
44
|
+
readonly format?: string | undefined;
|
|
45
|
+
readonly enum?: readonly unknown[] | undefined;
|
|
46
|
+
readonly properties?: Readonly<Record<string, JsonSchemaNode>> | undefined;
|
|
47
|
+
readonly required?: readonly string[] | undefined;
|
|
48
|
+
readonly items?: JsonSchemaNode | undefined;
|
|
49
|
+
readonly additionalProperties?: JsonSchemaNode | boolean | undefined;
|
|
50
|
+
readonly title?: string | undefined;
|
|
51
|
+
/** Allow extra JSON Schema properties without breaking assignability */
|
|
52
|
+
readonly [key: string]: unknown;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Classifies a single JSON Schema property node into a `FieldClassification`.
|
|
56
|
+
*
|
|
57
|
+
* Classification rules (applied in order):
|
|
58
|
+
* - `{ type: "string", format: "date-time" }` → `datetime`
|
|
59
|
+
* - `{ type: "string", format: "decimal" }` → `decimal`
|
|
60
|
+
* - `{ type: "string", enum: [...] }` → `enum`
|
|
61
|
+
* - `{ type: "array", items: {...} }` → `array` (recursive)
|
|
62
|
+
* - `{ type: "object", additionalProperties: {...} }` → `map` (recursive)
|
|
63
|
+
* - `{ type: "object", properties: {...} }` → `interface` (recursive)
|
|
64
|
+
* - primitives (string, number, boolean, integer) → `primitive`
|
|
65
|
+
*
|
|
66
|
+
* @param schema - A JSON Schema node to classify
|
|
67
|
+
* @param typeName - An optional type name for object/enum types (used in
|
|
68
|
+
* descriptor generation to reference the descriptor constant)
|
|
69
|
+
* @returns The field classification
|
|
70
|
+
* @internal
|
|
71
|
+
*/
|
|
72
|
+
export declare function classifyJsonSchemaProperty(schema: JsonSchemaNode, typeName?: string): FieldClassification;
|
|
73
|
+
/**
|
|
74
|
+
* Result of classifying a JSON Schema object's properties for descriptor generation.
|
|
75
|
+
* @internal
|
|
76
|
+
*/
|
|
77
|
+
export interface ClassifiedSchema {
|
|
78
|
+
/** Per-property classification keyed by property name */
|
|
79
|
+
fields: Record<string, FieldClassification>;
|
|
80
|
+
/** Per-property optionality (true = optional) */
|
|
81
|
+
optionality: Record<string, boolean>;
|
|
82
|
+
/** Nested object schemas that need their own descriptors */
|
|
83
|
+
nestedSchemas: NestedSchemaInfo[];
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Info about a nested object schema that requires its own descriptor.
|
|
87
|
+
* @internal
|
|
88
|
+
*/
|
|
89
|
+
export interface NestedSchemaInfo {
|
|
90
|
+
/** Descriptor constant name prefix */
|
|
91
|
+
typeName: string;
|
|
92
|
+
/** The JSON Schema node for the nested object */
|
|
93
|
+
schema: JsonSchemaNode;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Classifies all properties of a JSON Schema object and collects nested
|
|
97
|
+
* schemas that need their own descriptor constants.
|
|
98
|
+
*
|
|
99
|
+
* @param schema - A JSON Schema node with `type: "object"` and `properties`
|
|
100
|
+
* @param prefix - A name prefix for generating nested type names
|
|
101
|
+
* @returns Classification result with per-field classifications and nested schemas
|
|
102
|
+
* @internal
|
|
103
|
+
*/
|
|
104
|
+
export declare function classifyObjectSchema(schema: JsonSchemaNode, prefix: string): ClassifiedSchema;
|
|
105
|
+
//# sourceMappingURL=classify-fields.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"classify-fields.d.ts","sourceRoot":"","sources":["../../src/transformer/classify-fields.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH;;;;;GAKG;AAC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EACtB,QAAQ,CAAC,EAAE,MAAM,GAChB,mBAAmB,CA6CrB;AAED;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC/B,yDAAyD;IACzD,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAAC;IAC5C,iDAAiD;IACjD,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACrC,4DAA4D;IAC5D,aAAa,EAAE,gBAAgB,EAAE,CAAC;CACnC;AAED;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC/B,sCAAsC;IACtC,QAAQ,EAAE,MAAM,CAAC;IACjB,iDAAiD;IACjD,MAAM,EAAE,cAAc,CAAC;CACxB;AAED;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,cAAc,EACtB,MAAM,EAAE,MAAM,GACb,gBAAgB,CAmBlB"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generates `_ShapeDescriptor` TypeScript code strings from classified
|
|
3
|
+
* JSON Schema for custom object wire↔native conversion.
|
|
4
|
+
*
|
|
5
|
+
* Follows the same pattern as `internal/codegen/src/generate-converters.ts`
|
|
6
|
+
* but adapted for custom objects where:
|
|
7
|
+
* - Wire names equal SDK names (no snake_case→camelCase rename needed)
|
|
8
|
+
* - There are no enums, unions, or discriminated unions from proto definitions
|
|
9
|
+
* - Classification is driven by JSON Schema rather than proto parsed types
|
|
10
|
+
*
|
|
11
|
+
* @internal
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Input for generating all descriptors for a single custom object.
|
|
15
|
+
* @internal
|
|
16
|
+
*/
|
|
17
|
+
export interface DescriptorGenerationInput {
|
|
18
|
+
/** The class name (e.g. `Invoice`) */
|
|
19
|
+
className: string;
|
|
20
|
+
/**
|
|
21
|
+
* JSON Schema for the fields surface (point-read hydration).
|
|
22
|
+
* Typed as `unknown` — the transformer carries schemas through the transform
|
|
23
|
+
* plan without coupling to `@formspec/build`'s `JsonSchema2020` type (which
|
|
24
|
+
* lacks an index signature). Cast to `JsonSchemaNode | null` happens inside
|
|
25
|
+
* `generateDescriptors` at this boundary.
|
|
26
|
+
*/
|
|
27
|
+
fieldsSchema: unknown;
|
|
28
|
+
/** Maps schema property names → TS property names for the fields surface */
|
|
29
|
+
fieldsPropertyNameMap?: Record<string, string> | undefined;
|
|
30
|
+
/** Per-action schemas keyed by apiName */
|
|
31
|
+
actions: Record<string, {
|
|
32
|
+
apiName: string;
|
|
33
|
+
/** JSON Schema for the action's input type. Typed as `unknown` — see `fieldsSchema`. */
|
|
34
|
+
inputSchema: unknown;
|
|
35
|
+
/** JSON Schema for the action's output type. Typed as `unknown` — see `fieldsSchema`. */
|
|
36
|
+
outputSchema: unknown;
|
|
37
|
+
/** Maps schema property names → TS property names for the input surface */
|
|
38
|
+
inputPropertyNameMap?: Record<string, string> | undefined;
|
|
39
|
+
/** Maps schema property names → TS property names for the output surface */
|
|
40
|
+
outputPropertyNameMap?: Record<string, string> | undefined;
|
|
41
|
+
}>;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Result of generating descriptors for a single custom object.
|
|
45
|
+
* @internal
|
|
46
|
+
*/
|
|
47
|
+
export interface DescriptorGenerationResult {
|
|
48
|
+
/** All generated descriptor code lines */
|
|
49
|
+
code: string[];
|
|
50
|
+
/** Names of all descriptors generated (for reference in the wrapper class) */
|
|
51
|
+
descriptorNames: {
|
|
52
|
+
fields: string | null;
|
|
53
|
+
actions: Record<string, {
|
|
54
|
+
input: string | null;
|
|
55
|
+
output: string | null;
|
|
56
|
+
}>;
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Generates all `_ShapeDescriptor` constants for one custom object.
|
|
61
|
+
*
|
|
62
|
+
* Produces:
|
|
63
|
+
* - `{ClassName}_FieldsDescriptor` for point-read hydration (wire→native)
|
|
64
|
+
* - `{ClassName}_{apiName}_InputDescriptor` per action (wire→native)
|
|
65
|
+
* - `{ClassName}_{apiName}_OutputDescriptor` per action (native→wire)
|
|
66
|
+
*
|
|
67
|
+
* Also generates descriptors for any nested object types discovered
|
|
68
|
+
* during classification.
|
|
69
|
+
* @internal
|
|
70
|
+
*/
|
|
71
|
+
export declare function generateDescriptors(input: DescriptorGenerationInput): DescriptorGenerationResult;
|
|
72
|
+
//# sourceMappingURL=generate-descriptors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-descriptors.d.ts","sourceRoot":"","sources":["../../src/transformer/generate-descriptors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAyFH;;;GAGG;AACH,MAAM,WAAW,yBAAyB;IACxC,sCAAsC;IACtC,SAAS,EAAE,MAAM,CAAC;IAClB;;;;;;OAMG;IACH,YAAY,EAAE,OAAO,CAAC;IACtB,4EAA4E;IAC5E,qBAAqB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,CAAC;IAC3D,0CAA0C;IAC1C,OAAO,EAAE,MAAM,CACb,MAAM,EACN;QACE,OAAO,EAAE,MAAM,CAAC;QAChB,wFAAwF;QACxF,WAAW,EAAE,OAAO,CAAC;QACrB,yFAAyF;QACzF,YAAY,EAAE,OAAO,CAAC;QACtB,2EAA2E;QAC3E,oBAAoB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,CAAC;QAC1D,4EAA4E;QAC5E,qBAAqB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,CAAC;KAC5D,CACF,CAAC;CACH;AAED;;;GAGG;AACH,MAAM,WAAW,0BAA0B;IACzC,0CAA0C;IAC1C,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,8EAA8E;IAC9E,eAAe,EAAE;QACf,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;QACtB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE;YAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;YAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAA;SAAE,CAAC,CAAC;KAC1E,CAAC;CACH;AAwCD;;;;;;;;;;;GAWG;AACH,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,yBAAyB,GAC/B,0BAA0B,CAiE5B"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts a string to snake_case.
|
|
3
|
+
* @param str - The string to convert
|
|
4
|
+
* @returns The snake_case version of the string
|
|
5
|
+
* @alpha
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* toSnakeCase('camelCase') // 'camel_case'
|
|
9
|
+
* toSnakeCase('PascalCase') // 'pascal_case'
|
|
10
|
+
* toSnakeCase('XMLParser') // 'xml_parser'
|
|
11
|
+
*/
|
|
12
|
+
export declare function toSnakeCase(str: string): string;
|
|
13
|
+
/**
|
|
14
|
+
* Converts a snake_case string to PascalCase.
|
|
15
|
+
* @param str - The string to convert
|
|
16
|
+
* @returns The PascalCase version of the string
|
|
17
|
+
* @alpha
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* toPascalCase('my_type') // 'MyType'
|
|
21
|
+
* toPascalCase('type_a') // 'TypeA'
|
|
22
|
+
* toPascalCase('shipment') // 'Shipment'
|
|
23
|
+
*/
|
|
24
|
+
export declare function toPascalCase(str: string): string;
|
|
25
|
+
//# sourceMappingURL=metadata.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"metadata.d.ts","sourceRoot":"","sources":["../../src/transformer/metadata.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAM/C;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAKhD"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { ModuleTransformPlan, TransformResult } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Transforms TypeScript source code with custom object decorators.
|
|
4
|
+
* Injects runtime code and extracts platform metadata.
|
|
5
|
+
*
|
|
6
|
+
* @param sourceCode - The TypeScript source code to transform
|
|
7
|
+
* @param fileName - Optional file name for error reporting
|
|
8
|
+
* @returns Transform result with code, metadata, and errors
|
|
9
|
+
* @deprecated Use `buildCustomObjectPackage` + `transformWithPlan` instead. This
|
|
10
|
+
* function performs source-only discovery without build-time schema analysis, so it
|
|
11
|
+
* cannot generate wire conversion descriptors and falls back to the legacy passthrough
|
|
12
|
+
* wrapper (no Decimal/DateTime hydration).
|
|
13
|
+
* @alpha
|
|
14
|
+
*/
|
|
15
|
+
export declare function transform(sourceCode: string, fileName?: string): TransformResult;
|
|
16
|
+
/**
|
|
17
|
+
* Transforms TypeScript source code using a precomputed module transform plan.
|
|
18
|
+
*
|
|
19
|
+
* @param sourceCode - The TypeScript source code to transform
|
|
20
|
+
* @param plan - Precomputed transform plan
|
|
21
|
+
* @param fileName - Optional file name for error reporting
|
|
22
|
+
* @returns Transform result with code, metadata, and errors
|
|
23
|
+
* @internal
|
|
24
|
+
*/
|
|
25
|
+
export declare function transformWithPlan(sourceCode: string, plan: ModuleTransformPlan, fileName?: string): TransformResult;
|
|
26
|
+
/**
|
|
27
|
+
* Transforms a TypeScript file from disk.
|
|
28
|
+
*
|
|
29
|
+
* @param filePath - Path to the TypeScript file
|
|
30
|
+
* @returns Transform result with code, metadata, and errors
|
|
31
|
+
* @deprecated Delegates to the deprecated `transform()`. Use `buildCustomObjectPackage` instead.
|
|
32
|
+
* @alpha
|
|
33
|
+
*/
|
|
34
|
+
export declare function transformFile(filePath: string): Promise<TransformResult>;
|
|
35
|
+
//# sourceMappingURL=transform.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transform.d.ts","sourceRoot":"","sources":["../../src/transformer/transform.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,mBAAmB,EAGnB,eAAe,EAChB,MAAM,YAAY,CAAC;AAcpB;;;;;;;;;;;;GAYG;AACH,wBAAgB,SAAS,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,eAAe,CA4BhF;AAED;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAC/B,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE,mBAAmB,EACzB,QAAQ,CAAC,EAAE,MAAM,GAChB,eAAe,CAmBjB;AAsLD;;;;;;;GAOG;AACH,wBAAsB,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC,CAkB9E"}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Metadata for a single action (method).
|
|
3
|
+
* @alpha
|
|
4
|
+
*/
|
|
5
|
+
export interface ActionMetadata {
|
|
6
|
+
/** The method name */
|
|
7
|
+
methodName: string;
|
|
8
|
+
/** String representation of argument types */
|
|
9
|
+
argType: string;
|
|
10
|
+
/** String representation of return type */
|
|
11
|
+
returnType: string;
|
|
12
|
+
/** API name for the action (defaults to snake_case of method name) */
|
|
13
|
+
apiName: string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Actions metadata for a custom object.
|
|
17
|
+
* Only instance methods are supported — static methods cannot be actions.
|
|
18
|
+
* @alpha
|
|
19
|
+
*/
|
|
20
|
+
export interface ActionsMetadata {
|
|
21
|
+
/** Instance-level actions */
|
|
22
|
+
instance: Record<string, ActionMetadata>;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Platform metadata for a custom object class.
|
|
26
|
+
* @alpha
|
|
27
|
+
*/
|
|
28
|
+
export interface PlatformMetadata {
|
|
29
|
+
/** Module path that defined this custom object */
|
|
30
|
+
modulePath?: string;
|
|
31
|
+
/** Original TypeScript class name */
|
|
32
|
+
className?: string;
|
|
33
|
+
/** Canonical class api name */
|
|
34
|
+
classApiName?: string;
|
|
35
|
+
/** The api name of the custom object */
|
|
36
|
+
apiName: string;
|
|
37
|
+
/** All actions for this custom object */
|
|
38
|
+
actions: ActionsMetadata;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* JSON Schema for one action's input/output surfaces, used by the
|
|
42
|
+
* descriptor generator to produce `_ShapeDescriptor` constants.
|
|
43
|
+
*
|
|
44
|
+
* Schema values are typed as `unknown` to avoid structural incompatibility
|
|
45
|
+
* with the `JsonSchema2020` interface from `@formspec/build` (which lacks
|
|
46
|
+
* an index signature). The transformer casts to its internal `JsonSchemaNode`
|
|
47
|
+
* at the `generateDescriptors` boundary.
|
|
48
|
+
*
|
|
49
|
+
* @internal
|
|
50
|
+
*/
|
|
51
|
+
export interface ActionSchemaData {
|
|
52
|
+
/** API name of the action (snake_case) */
|
|
53
|
+
apiName: string;
|
|
54
|
+
/** JSON Schema for the action's input type (null if no input parameter) */
|
|
55
|
+
inputSchema: unknown;
|
|
56
|
+
/** JSON Schema for the action's output type */
|
|
57
|
+
outputSchema: unknown;
|
|
58
|
+
/**
|
|
59
|
+
* Maps schema property names (apiName / snake_case) to original TypeScript
|
|
60
|
+
* property names (camelCase) for the input surface. Used to emit `wire`
|
|
61
|
+
* clauses in descriptor field entries when the names differ.
|
|
62
|
+
*/
|
|
63
|
+
inputPropertyNameMap?: Record<string, string> | undefined;
|
|
64
|
+
/**
|
|
65
|
+
* Maps schema property names (apiName / snake_case) to original TypeScript
|
|
66
|
+
* property names (camelCase) for the output surface.
|
|
67
|
+
*/
|
|
68
|
+
outputPropertyNameMap?: Record<string, string> | undefined;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Schema data needed by the transformer to generate wire conversion descriptors.
|
|
72
|
+
* @internal
|
|
73
|
+
*/
|
|
74
|
+
export interface TransformSchemaData {
|
|
75
|
+
/**
|
|
76
|
+
* JSON Schema for the fields surface (point-read hydration).
|
|
77
|
+
*
|
|
78
|
+
* Typed as `unknown` to avoid structural incompatibility with the `JsonSchema2020`
|
|
79
|
+
* interface from `@formspec/build` (which lacks an index signature). The transformer
|
|
80
|
+
* casts to its internal `JsonSchemaNode` at the `generateDescriptors` boundary —
|
|
81
|
+
* the same pattern used for `ActionSchemaData.inputSchema` / `outputSchema`.
|
|
82
|
+
*/
|
|
83
|
+
fieldsSchema: unknown;
|
|
84
|
+
/**
|
|
85
|
+
* Maps schema property names (apiName / snake_case) to original TypeScript
|
|
86
|
+
* property names (camelCase) for the fields surface.
|
|
87
|
+
*/
|
|
88
|
+
fieldsPropertyNameMap?: Record<string, string> | undefined;
|
|
89
|
+
/** Per-action schema data keyed by apiName */
|
|
90
|
+
actions: Record<string, ActionSchemaData>;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Planned transformation for one custom object class within a module.
|
|
94
|
+
* @internal
|
|
95
|
+
*/
|
|
96
|
+
export interface PlannedCustomObjectTransform {
|
|
97
|
+
/** Original class name in the source file */
|
|
98
|
+
className: string;
|
|
99
|
+
/** Precomputed platform metadata for this class */
|
|
100
|
+
platformMetadata: PlatformMetadata;
|
|
101
|
+
/** Schema data for wire conversion descriptor generation */
|
|
102
|
+
schemaData?: TransformSchemaData;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Planned transformation for one source module.
|
|
106
|
+
* @internal
|
|
107
|
+
*/
|
|
108
|
+
export interface ModuleTransformPlan {
|
|
109
|
+
/** Custom object classes to transform within the module */
|
|
110
|
+
objects: PlannedCustomObjectTransform[];
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Result of transforming source code.
|
|
114
|
+
* @alpha
|
|
115
|
+
*/
|
|
116
|
+
export interface TransformResult {
|
|
117
|
+
/** Transformed source code */
|
|
118
|
+
code: string;
|
|
119
|
+
/** Platform metadata extracted from all custom objects */
|
|
120
|
+
metadata: PlatformMetadata[];
|
|
121
|
+
/** Any errors encountered during transformation */
|
|
122
|
+
errors: TransformError[];
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* An error that occurred during transformation.
|
|
126
|
+
* @alpha
|
|
127
|
+
*/
|
|
128
|
+
export interface TransformError {
|
|
129
|
+
/** Error message */
|
|
130
|
+
message: string;
|
|
131
|
+
/** File path (if available) */
|
|
132
|
+
file?: string;
|
|
133
|
+
/** Line number (if available) */
|
|
134
|
+
line?: number;
|
|
135
|
+
/** Column number (if available) */
|
|
136
|
+
column?: number;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Metadata extracted from a decorator.
|
|
140
|
+
* @internal
|
|
141
|
+
*/
|
|
142
|
+
export interface DecoratorMetadata {
|
|
143
|
+
/** Decorator name */
|
|
144
|
+
name: string;
|
|
145
|
+
}
|
|
146
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/transformer/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC7B,sBAAsB;IACtB,UAAU,EAAE,MAAM,CAAC;IACnB,8CAA8C;IAC9C,OAAO,EAAE,MAAM,CAAC;IAChB,2CAA2C;IAC3C,UAAU,EAAE,MAAM,CAAC;IACnB,sEAAsE;IACtE,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;;;GAIG;AACH,MAAM,WAAW,eAAe;IAC9B,6BAA6B;IAC7B,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;CAC1C;AAED;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC/B,kDAAkD;IAClD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,qCAAqC;IACrC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,+BAA+B;IAC/B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,wCAAwC;IACxC,OAAO,EAAE,MAAM,CAAC;IAChB,yCAAyC;IACzC,OAAO,EAAE,eAAe,CAAC;CAC1B;AAED;;;;;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,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,iCAAiC;IACjC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,mCAAmC;IACnC,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;;GAGG;AACH,MAAM,WAAW,iBAAiB;IAChC,qBAAqB;IACrB,IAAI,EAAE,MAAM,CAAC;CACd"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import type { ClassDeclaration, MethodDeclaration, SourceFile } from 'ts-morph';
|
|
2
|
+
import type { PlatformMetadata, TransformSchemaData } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Checks if a class has the `@CustomObject` decorator.
|
|
5
|
+
* @param classDecl - The class declaration
|
|
6
|
+
* @returns true if the class has `@CustomObject`
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
export declare function hasCustomObjectDecorator(classDecl: ClassDeclaration): boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Checks if a method has the `@Action` decorator.
|
|
12
|
+
* @param method - The method declaration
|
|
13
|
+
* @returns true if the method has `@Action`
|
|
14
|
+
* @internal
|
|
15
|
+
*/
|
|
16
|
+
export declare function hasActionDecorator(method: MethodDeclaration): boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Extracts all platform metadata from a custom object class.
|
|
19
|
+
* @param classDecl - The class declaration
|
|
20
|
+
* @returns Platform metadata
|
|
21
|
+
* @internal
|
|
22
|
+
*/
|
|
23
|
+
export declare function extractPlatformMetadata(classDecl: ClassDeclaration): PlatformMetadata;
|
|
24
|
+
/**
|
|
25
|
+
* Injects platform metadata as a static property into a class.
|
|
26
|
+
* @param classDecl - The class declaration
|
|
27
|
+
* @param metadata - The platform metadata to inject
|
|
28
|
+
* @internal
|
|
29
|
+
*/
|
|
30
|
+
export declare function injectPlatformMetadata(classDecl: ClassDeclaration, metadata: PlatformMetadata): void;
|
|
31
|
+
/**
|
|
32
|
+
* Injects proxy return statement into the constructor of a `@CustomObject` class.
|
|
33
|
+
* This causes `new MyClass()` to return a proxy that tracks mutations.
|
|
34
|
+
* @param classDecl - The class declaration
|
|
35
|
+
* @throws Error if the constructor already contains return statements
|
|
36
|
+
* @internal
|
|
37
|
+
*/
|
|
38
|
+
export declare function injectConstructorProxy(classDecl: ClassDeclaration): void;
|
|
39
|
+
/**
|
|
40
|
+
* Injects auto-save logic at the end of an `@Action` method.
|
|
41
|
+
* After the method body executes, if there are pending changes, queue a save.
|
|
42
|
+
* @param method - The method declaration
|
|
43
|
+
* @internal
|
|
44
|
+
*/
|
|
45
|
+
export declare function injectAutoSave(method: MethodDeclaration): void;
|
|
46
|
+
/**
|
|
47
|
+
* Injects runtime imports at the top of the source file.
|
|
48
|
+
* These imports provide the functions needed by the injected code.
|
|
49
|
+
*
|
|
50
|
+
* When `hasDescriptors` is true, also injects stdlib imports for wire
|
|
51
|
+
* conversion primitives from `@stripe/extensibility-sdk/stdlib`.
|
|
52
|
+
*
|
|
53
|
+
* @param sourceFile - The source file
|
|
54
|
+
* @param hasDescriptors - Whether wire conversion descriptors were generated
|
|
55
|
+
* @internal
|
|
56
|
+
*/
|
|
57
|
+
export declare function injectRuntimeImports(sourceFile: SourceFile, hasDescriptors?: boolean): void;
|
|
58
|
+
/**
|
|
59
|
+
* Removes all decorators from a class and its members.
|
|
60
|
+
* @param classDecl - The class declaration
|
|
61
|
+
* @internal
|
|
62
|
+
*/
|
|
63
|
+
export declare function removeDecorators(classDecl: ClassDeclaration): void;
|
|
64
|
+
/**
|
|
65
|
+
* Removes decorator imports from a source file.
|
|
66
|
+
* Removes decorator-specific named imports from the extensibility-custom-objects package.
|
|
67
|
+
* @param sourceFile - The source file node
|
|
68
|
+
* @internal
|
|
69
|
+
*/
|
|
70
|
+
export declare function removeDecoratorImports(sourceFile: SourceFile): void;
|
|
71
|
+
/**
|
|
72
|
+
* Generates the InstanceMethodTypeMap type declaration.
|
|
73
|
+
* @param metadata - The platform metadata containing action information
|
|
74
|
+
* @returns The type declaration as a string
|
|
75
|
+
* @internal
|
|
76
|
+
*/
|
|
77
|
+
export declare function generateInstanceMethodTypeMap(metadata: PlatformMetadata): string;
|
|
78
|
+
/**
|
|
79
|
+
* Generates the wrapper class with wire-converting executeMethod.
|
|
80
|
+
* Only instance methods are supported — static methods cannot be actions.
|
|
81
|
+
*
|
|
82
|
+
* When `schemaData` is provided, the wrapper includes:
|
|
83
|
+
* - `_ShapeDescriptor` constants for fields, inputs, and outputs
|
|
84
|
+
* - A private `hydrate()` method that converts wire-format fields to native types
|
|
85
|
+
* - An `executeMethod(request, config, context)` entry point that extracts
|
|
86
|
+
* `objectRecord`, `methodName`, `methodArgs` from the request, then handles
|
|
87
|
+
* both input and output wire conversion
|
|
88
|
+
*
|
|
89
|
+
* When `schemaData` is not provided (legacy path), generates the simpler
|
|
90
|
+
* passthrough wrapper for backward compatibility.
|
|
91
|
+
*
|
|
92
|
+
* @param metadata - The platform metadata
|
|
93
|
+
* @param className - The original TypeScript class name
|
|
94
|
+
* @param schemaData - Optional schema data for wire conversion descriptor generation
|
|
95
|
+
* @returns The wrapper class (and descriptors) as a string
|
|
96
|
+
* @internal
|
|
97
|
+
*/
|
|
98
|
+
export declare function generateWrapperClass(metadata: PlatformMetadata, className: string, schemaData?: TransformSchemaData): string;
|
|
99
|
+
//# sourceMappingURL=visitors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"visitors.d.ts","sourceRoot":"","sources":["../../src/transformer/visitors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAEhB,iBAAiB,EACjB,UAAU,EACX,MAAM,UAAU,CAAC;AAElB,OAAO,KAAK,EAIV,gBAAgB,EAChB,mBAAmB,EACpB,MAAM,YAAY,CAAC;AAwBpB;;;;;GAKG;AACH,wBAAgB,wBAAwB,CAAC,SAAS,EAAE,gBAAgB,GAAG,OAAO,CAK7E;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,iBAAiB,GAAG,OAAO,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