@stripe/extensibility-custom-objects 0.7.4
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 +63 -0
- package/dist/decorators/action.d.ts +29 -0
- package/dist/decorators/action.d.ts.map +1 -0
- package/dist/decorators/custom-fields.d.ts +16 -0
- package/dist/decorators/custom-fields.d.ts.map +1 -0
- package/dist/decorators/custom-object.d.ts +19 -0
- package/dist/decorators/custom-object.d.ts.map +1 -0
- package/dist/decorators/index.d.ts +14 -0
- package/dist/decorators/index.d.ts.map +1 -0
- package/dist/extensibility-custom-objects-alpha.d.ts +245 -0
- package/dist/extensibility-custom-objects-beta.d.ts +245 -0
- package/dist/extensibility-custom-objects-internal.d.ts +680 -0
- package/dist/extensibility-custom-objects-public.d.ts +245 -0
- package/dist/index.cjs +761 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +710 -0
- package/dist/runtime/base-object.d.ts +84 -0
- package/dist/runtime/base-object.d.ts.map +1 -0
- package/dist/runtime/deep-clone.d.ts +16 -0
- package/dist/runtime/deep-clone.d.ts.map +1 -0
- package/dist/runtime/events.d.ts +161 -0
- package/dist/runtime/events.d.ts.map +1 -0
- package/dist/runtime/flush-helpers.d.ts +9 -0
- package/dist/runtime/flush-helpers.d.ts.map +1 -0
- package/dist/runtime/invoke.d.ts +19 -0
- package/dist/runtime/invoke.d.ts.map +1 -0
- package/dist/runtime/persist.d.ts +44 -0
- package/dist/runtime/persist.d.ts.map +1 -0
- package/dist/runtime/proxy/constants.d.ts +5 -0
- package/dist/runtime/proxy/constants.d.ts.map +1 -0
- package/dist/runtime/proxy/fields-proxy.d.ts +19 -0
- package/dist/runtime/proxy/fields-proxy.d.ts.map +1 -0
- package/dist/runtime/proxy/index.d.ts +5 -0
- package/dist/runtime/proxy/index.d.ts.map +1 -0
- package/dist/runtime/proxy/instance-proxy.d.ts +81 -0
- package/dist/runtime/proxy/instance-proxy.d.ts.map +1 -0
- package/dist/runtime/proxy/types.d.ts +25 -0
- package/dist/runtime/proxy/types.d.ts.map +1 -0
- package/dist/runtime/registry.d.ts +40 -0
- package/dist/runtime/registry.d.ts.map +1 -0
- package/dist/runtime/symbol-helpers.d.ts +17 -0
- package/dist/runtime/symbol-helpers.d.ts.map +1 -0
- package/dist/runtime/types.d.ts +139 -0
- package/dist/runtime/types.d.ts.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -0
- package/package.json +48 -0
|
@@ -0,0 +1,680 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stripe Custom Objects SDK
|
|
3
|
+
*
|
|
4
|
+
* Provides decorators and runtime support for defining custom object types
|
|
5
|
+
* that integrate with the Stripe platform. Custom objects are defined using
|
|
6
|
+
* TypeScript classes with decorators, then transformed at build time using
|
|
7
|
+
* `@stripe/extensibility-custom-objects-tools`.
|
|
8
|
+
*
|
|
9
|
+
* @packageDocumentation
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Checks if a proxied object has pending changes.
|
|
14
|
+
*
|
|
15
|
+
* @internal
|
|
16
|
+
*/
|
|
17
|
+
export declare function __hasPendingChanges(obj: BaseObject): boolean;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Flushes pending field changes into the proxy's slated-updates accumulator.
|
|
21
|
+
*
|
|
22
|
+
* Called by the auto-save code injected at the end of each `@Action` method.
|
|
23
|
+
* BaseObject.save() performs an equivalent flush directly via the shared
|
|
24
|
+
* _flushPendingToSlated helper.
|
|
25
|
+
*
|
|
26
|
+
* @internal
|
|
27
|
+
*/
|
|
28
|
+
export declare function __queueSave(obj: BaseObject): void;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Marks an instance method as an action on a custom object.
|
|
32
|
+
*
|
|
33
|
+
* This decorator is **inert at runtime** — it does not modify the method in any way.
|
|
34
|
+
* It serves as a marker for the build-time transformer, which extracts action metadata
|
|
35
|
+
* and generates the necessary platform registration code.
|
|
36
|
+
*
|
|
37
|
+
* Can only be applied to instance methods, not static methods. Applying `@Action`
|
|
38
|
+
* to a static method is a TypeScript compile error.
|
|
39
|
+
*
|
|
40
|
+
* All naming metadata is expressed via TSDoc annotation tags in a JSDoc comment
|
|
41
|
+
* on the method: `@apiName`, `@displayName`, `@description`.
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* Use TSDoc tags in a JSDoc comment above the decorator,
|
|
45
|
+
* e.g. `@apiName mark_delivered` and `@displayName Mark Delivered`,
|
|
46
|
+
* then apply the bare decorator `@Action`.
|
|
47
|
+
*
|
|
48
|
+
* @public
|
|
49
|
+
*/
|
|
50
|
+
export declare function Action(_target: (...args: never) => unknown, _context: InstanceMethodDecoratorContext): void;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Metadata describing a single action method.
|
|
54
|
+
*
|
|
55
|
+
* @internal
|
|
56
|
+
*/
|
|
57
|
+
export declare interface _ActionMetadata {
|
|
58
|
+
/** Name of the method */
|
|
59
|
+
methodName: string;
|
|
60
|
+
/** API name for this action (derived from method name or overridden via the apiName TSDoc tag) */
|
|
61
|
+
apiName: string;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Assembles an update payload from pending proxy updates.
|
|
66
|
+
*
|
|
67
|
+
* Fields prefixed with `fields.` are grouped into a nested `fields` object.
|
|
68
|
+
* All other fields appear at the top level.
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```typescript
|
|
72
|
+
* assemblePayload([
|
|
73
|
+
* { field: 'status', value: 'active' },
|
|
74
|
+
* { field: 'fields.email', value: 'alice@example.com' },
|
|
75
|
+
* ]);
|
|
76
|
+
* // Returns: { status: 'active', fields: { email: 'alice@example.com' } }
|
|
77
|
+
* ```
|
|
78
|
+
*
|
|
79
|
+
* @internal
|
|
80
|
+
*/
|
|
81
|
+
export declare function _assemblePayload(pendingUpdates: {
|
|
82
|
+
field: string;
|
|
83
|
+
value: unknown;
|
|
84
|
+
}[]): Record<string, unknown>;
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Abstract base class for all custom objects.
|
|
88
|
+
*
|
|
89
|
+
* Provides built-in platform fields (id, object, created, updated, livemode)
|
|
90
|
+
* and a typed `fields` container for user-defined fields. The generic parameter
|
|
91
|
+
* `T` describes the shape of user fields accessible via `this.fields`.
|
|
92
|
+
*
|
|
93
|
+
* @remarks
|
|
94
|
+
* **Definite assignment assertions (`!`)**: All platform fields (`id`, `object`,
|
|
95
|
+
* `created`, `updated`, `livemode`, `fields`) use the TypeScript definite assignment
|
|
96
|
+
* assertion operator. This suppresses the "property has no initializer" error because
|
|
97
|
+
* these fields are intentionally left unset by the zero-argument constructor.
|
|
98
|
+
*
|
|
99
|
+
* The runtime (`executeInstanceMethod` in `invoke.ts`) is solely responsible for
|
|
100
|
+
* populating these fields via `Object.assign` and `hydrateInstance` **before** the
|
|
101
|
+
* dirty-tracking proxy is installed. Code that constructs a subclass directly
|
|
102
|
+
* (bypassing the runtime) will have `undefined` values for all platform fields at
|
|
103
|
+
* runtime, despite the types suggesting otherwise.
|
|
104
|
+
*
|
|
105
|
+
* @typeParam T - Shape of user-defined fields stored in `fields`
|
|
106
|
+
* @public
|
|
107
|
+
*/
|
|
108
|
+
export declare abstract class BaseObject<T extends Record<string, unknown> = Record<string, unknown>> {
|
|
109
|
+
/** Unique identifier assigned by the platform */
|
|
110
|
+
readonly id: string;
|
|
111
|
+
/** Object type identifier assigned by the platform */
|
|
112
|
+
readonly object: string;
|
|
113
|
+
/** Timestamp when the object was created */
|
|
114
|
+
readonly created: Date;
|
|
115
|
+
/** Timestamp when the object was last updated */
|
|
116
|
+
readonly updated: Date;
|
|
117
|
+
/** Whether the object exists in live mode (true) or test mode (false). @public */
|
|
118
|
+
readonly livemode: boolean;
|
|
119
|
+
/**
|
|
120
|
+
* User-defined fields container. Populated during hydration via Object.assign
|
|
121
|
+
* before the dirty-tracking proxy is installed.
|
|
122
|
+
* Access individual fields as `this.fields.fieldName`.
|
|
123
|
+
*
|
|
124
|
+
* @remarks
|
|
125
|
+
* The generic type `T` describes the shape of available fields after
|
|
126
|
+
* hydration, not at construction time. Fields may be undefined before
|
|
127
|
+
* the instance is hydrated with data from the platform.
|
|
128
|
+
*
|
|
129
|
+
* @public
|
|
130
|
+
*/
|
|
131
|
+
readonly fields: T;
|
|
132
|
+
/**
|
|
133
|
+
* Flushes pending field mutations into the slated-updates accumulator.
|
|
134
|
+
*
|
|
135
|
+
* When called from a transformed action (no save handler configured), this
|
|
136
|
+
* records which fields were mutated so that the Logic wrapper can include them
|
|
137
|
+
* in the response envelope's `updatedFields`. No network call is made.
|
|
138
|
+
*
|
|
139
|
+
* When a save handler is configured (runtime invoke path), the handler is
|
|
140
|
+
* called for actual persistence and its result is returned.
|
|
141
|
+
*
|
|
142
|
+
* @returns The save result including `updatedFieldCount` (unique fields flushed)
|
|
143
|
+
* @throws Error if the object is not proxied
|
|
144
|
+
* @public
|
|
145
|
+
*/
|
|
146
|
+
save(): Promise<SaveResult>;
|
|
147
|
+
/**
|
|
148
|
+
* Discard all pending changes and restore field values to their
|
|
149
|
+
* last-saved state. Has no effect if the object is not proxied.
|
|
150
|
+
*
|
|
151
|
+
* @public
|
|
152
|
+
*/
|
|
153
|
+
revert(): void;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Builds the ExecuteMethodResponse envelope for a completed action.
|
|
158
|
+
* Reads and clears the slated-updates accumulator, returning
|
|
159
|
+
* `{ methodReturnValue, updatedFields }`.
|
|
160
|
+
*
|
|
161
|
+
* @internal
|
|
162
|
+
*/
|
|
163
|
+
export declare function _buildMethodResponse(obj: BaseObject, methodReturnValue: unknown): {
|
|
164
|
+
methodReturnValue: unknown;
|
|
165
|
+
updatedFields: Record<string, unknown>;
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Clears all registered classes.
|
|
170
|
+
* Primarily for testing.
|
|
171
|
+
*
|
|
172
|
+
* @internal
|
|
173
|
+
*/
|
|
174
|
+
export declare function _clearRegistry(): void;
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Clears the slated-updates accumulator on an instance.
|
|
178
|
+
*
|
|
179
|
+
* Called twice during executeMethod: once before the action (to ensure
|
|
180
|
+
* no stale state from a previous invocation leaks in) and once inside
|
|
181
|
+
* buildEnvelope after the accumulated updates have been read.
|
|
182
|
+
*
|
|
183
|
+
* @internal
|
|
184
|
+
*/
|
|
185
|
+
export declare function _clearSlatedUpdates(obj: BaseObject): void;
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Commits the proxy state: clears pending updates and updates the saved snapshot.
|
|
189
|
+
*
|
|
190
|
+
* @internal
|
|
191
|
+
*/
|
|
192
|
+
export declare function _commitProxyState(state: _ProxyState): void;
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Creates a new runtime event emitter.
|
|
196
|
+
* Listeners are isolated: if one throws, others still receive the event.
|
|
197
|
+
*
|
|
198
|
+
* @internal
|
|
199
|
+
*/
|
|
200
|
+
export declare function _createEventEmitter(): _RuntimeEventEmitter;
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Creates a proxied custom object instance with change tracking.
|
|
204
|
+
*
|
|
205
|
+
* @internal
|
|
206
|
+
*/
|
|
207
|
+
export declare function _createInstanceProxy<T extends BaseObject>(instance: T, options?: _CreateProxyOptions): _ProxiedObject<T>;
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Options for creating a proxied custom object instance.
|
|
211
|
+
*
|
|
212
|
+
* @internal
|
|
213
|
+
*/
|
|
214
|
+
export declare interface _CreateProxyOptions {
|
|
215
|
+
/** Event emitter for telemetry */
|
|
216
|
+
eventEmitter?: _RuntimeEventEmitter;
|
|
217
|
+
/** Save handler for persistence */
|
|
218
|
+
saveHandler?: _SaveHandler;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Marks a class as a custom fields container for a custom object.
|
|
223
|
+
*
|
|
224
|
+
* This decorator is **inert at runtime** — it does not modify the class in any way.
|
|
225
|
+
* It serves as a marker for the build-time transformer, which discovers the fields
|
|
226
|
+
* class by this decorator and extracts field metadata from its members.
|
|
227
|
+
*
|
|
228
|
+
* The fields class must contain only field declarations (no methods). Use
|
|
229
|
+
* TSDoc tags from `@stripe/extensibility-jsonschema` on each field to control
|
|
230
|
+
* display and validation. Exactly one field should be tagged `primaryField`
|
|
231
|
+
* and at most one `secondaryField`.
|
|
232
|
+
*
|
|
233
|
+
* @public
|
|
234
|
+
*/
|
|
235
|
+
export declare function CustomFields(_target: new (...args: unknown[]) => unknown, _context: ClassDecoratorContext): void;
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Marks a class as a custom object type.
|
|
239
|
+
*
|
|
240
|
+
* This decorator is **inert at runtime** — it does not modify the class in any way.
|
|
241
|
+
* It serves as a marker for the build-time transformer, which extracts metadata
|
|
242
|
+
* and generates the necessary platform registration code.
|
|
243
|
+
*
|
|
244
|
+
* All naming metadata is expressed via TSDoc annotation tags in a JSDoc comment
|
|
245
|
+
* on the class: `@apiName`, `@displayName`, `@description`.
|
|
246
|
+
*
|
|
247
|
+
* @example
|
|
248
|
+
* Use TSDoc tags in a JSDoc comment above the decorator,
|
|
249
|
+
* e.g. `@apiName installment_plan` and `@displayName Installment plan`,
|
|
250
|
+
* then apply the bare decorator `@CustomObject`.
|
|
251
|
+
*
|
|
252
|
+
* @public
|
|
253
|
+
*/
|
|
254
|
+
export declare function CustomObject(_target: new (...args: unknown[]) => unknown, _context: ClassDecoratorContext): void;
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* Constructor type for custom object classes.
|
|
258
|
+
*
|
|
259
|
+
* @internal
|
|
260
|
+
*/
|
|
261
|
+
export declare interface _CustomObjectConstructor<T extends BaseObject = BaseObject> {
|
|
262
|
+
/** Constructs a new instance of the custom object class. */
|
|
263
|
+
new (): T;
|
|
264
|
+
/** Platform metadata attached by the `CustomObject` decorator at build time */
|
|
265
|
+
__platformMeta__?: _PlatformMetadata;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Executes a custom object method (instance or class/static).
|
|
270
|
+
* Dispatches to the appropriate handler based on whether instanceId is present.
|
|
271
|
+
*
|
|
272
|
+
* @internal
|
|
273
|
+
*/
|
|
274
|
+
export declare function _executeMethod(request: _ExecuteMethodRequest, options?: _ExecuteMethodOptions): Promise<unknown>;
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* Options for executing a custom object method.
|
|
278
|
+
*
|
|
279
|
+
* @internal
|
|
280
|
+
*/
|
|
281
|
+
export declare interface _ExecuteMethodOptions {
|
|
282
|
+
/** Event emitter for telemetry */
|
|
283
|
+
eventEmitter?: _RuntimeEventEmitter;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* Request structure for invoking custom object methods.
|
|
288
|
+
*
|
|
289
|
+
* @internal
|
|
290
|
+
*/
|
|
291
|
+
export declare interface _ExecuteMethodRequest {
|
|
292
|
+
/** API name of the custom object class */
|
|
293
|
+
apiName: string;
|
|
294
|
+
/** Name of the method to invoke */
|
|
295
|
+
methodName: string;
|
|
296
|
+
/** Instance ID for instance methods */
|
|
297
|
+
instanceId?: string;
|
|
298
|
+
/** Instance field data for hydration (instance methods only) */
|
|
299
|
+
instanceData?: Record<string, unknown>;
|
|
300
|
+
/** Arguments to pass to the method */
|
|
301
|
+
args?: unknown[];
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
* Extracts the proxy state from a proxied object.
|
|
306
|
+
* Returns undefined if the object is not proxied.
|
|
307
|
+
*
|
|
308
|
+
* @internal
|
|
309
|
+
*/
|
|
310
|
+
export declare function _getProxyState(obj: BaseObject): _ProxyState | undefined;
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* Returns all registered API names.
|
|
314
|
+
*
|
|
315
|
+
* @internal
|
|
316
|
+
*/
|
|
317
|
+
export declare function _getRegisteredApiNames(): string[];
|
|
318
|
+
|
|
319
|
+
/**
|
|
320
|
+
* Retrieves a registered custom object constructor by api name.
|
|
321
|
+
*
|
|
322
|
+
* @internal
|
|
323
|
+
*/
|
|
324
|
+
export declare function _getRegisteredClass(apiName: string): _CustomObjectConstructor | undefined;
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* Returns a snapshot of the accumulated slated updates from save() or
|
|
328
|
+
* __queueSave() calls during an action. Callers should call
|
|
329
|
+
* _clearSlatedUpdates after reading to reset for the next invocation.
|
|
330
|
+
*
|
|
331
|
+
* @internal
|
|
332
|
+
*/
|
|
333
|
+
export declare function _getSlatedUpdates(obj: BaseObject): Record<string, unknown>;
|
|
334
|
+
|
|
335
|
+
/**
|
|
336
|
+
* Type guard to check if an object has a proxy state.
|
|
337
|
+
*
|
|
338
|
+
* @internal
|
|
339
|
+
*/
|
|
340
|
+
export declare function _hasProxyState(obj: unknown): obj is Record<typeof _PROXY_STATE, _ProxyState>;
|
|
341
|
+
|
|
342
|
+
/**
|
|
343
|
+
* Symbol key for accessing the instance context (state + handlers).
|
|
344
|
+
*
|
|
345
|
+
* Local (non-global) symbol so that external code cannot reconstruct the key
|
|
346
|
+
* via Symbol.for() and reach into internal proxy state.
|
|
347
|
+
*
|
|
348
|
+
* @internal
|
|
349
|
+
*/
|
|
350
|
+
export declare const _INSTANCE_CONTEXT: unique symbol;
|
|
351
|
+
|
|
352
|
+
/**
|
|
353
|
+
* Context data stored on each proxied instance.
|
|
354
|
+
*
|
|
355
|
+
* @internal
|
|
356
|
+
*/
|
|
357
|
+
export declare interface _InstanceContext {
|
|
358
|
+
/** Proxy state for change tracking */
|
|
359
|
+
state: _ProxyState;
|
|
360
|
+
/** Optional event emitter for telemetry */
|
|
361
|
+
eventEmitter?: _RuntimeEventEmitter;
|
|
362
|
+
/** Optional save handler for persistence */
|
|
363
|
+
saveHandler?: _SaveHandler;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
/**
|
|
367
|
+
* Context type that restricts decorator application to instance methods only.
|
|
368
|
+
* Uses `{ readonly static: false }` to make TypeScript reject `@Action` on static methods.
|
|
369
|
+
*
|
|
370
|
+
* @public
|
|
371
|
+
*/
|
|
372
|
+
export declare type InstanceMethodDecoratorContext = { readonly static: false } & ClassMethodDecoratorContext;
|
|
373
|
+
|
|
374
|
+
/**
|
|
375
|
+
* Event emitted when a method invocation begins.
|
|
376
|
+
*
|
|
377
|
+
* @internal
|
|
378
|
+
*/
|
|
379
|
+
export declare interface _InvokeBeginEvent {
|
|
380
|
+
/** Discriminant for the invoke:begin event. */
|
|
381
|
+
type: 'invoke:begin';
|
|
382
|
+
/** The method invocation request being dispatched. */
|
|
383
|
+
request: _ExecuteMethodRequest;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
/**
|
|
387
|
+
* Event emitted when a method invocation completes successfully.
|
|
388
|
+
*
|
|
389
|
+
* @internal
|
|
390
|
+
*/
|
|
391
|
+
export declare interface _InvokeCompleteEvent {
|
|
392
|
+
/** Discriminant for the invoke:complete event. */
|
|
393
|
+
type: 'invoke:complete';
|
|
394
|
+
/** Value returned by the method. */
|
|
395
|
+
result: unknown;
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
/**
|
|
399
|
+
* Event emitted when a method invocation throws an error.
|
|
400
|
+
*
|
|
401
|
+
* @internal
|
|
402
|
+
*/
|
|
403
|
+
export declare interface _InvokeErrorEvent {
|
|
404
|
+
/** Discriminant for the invoke:error event. */
|
|
405
|
+
type: 'invoke:error';
|
|
406
|
+
/** The thrown error value. */
|
|
407
|
+
error: unknown;
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
/**
|
|
411
|
+
* Checks if a field should be tracked for changes.
|
|
412
|
+
*
|
|
413
|
+
* @internal
|
|
414
|
+
*/
|
|
415
|
+
export declare function _isTrackedField(field: string): boolean;
|
|
416
|
+
|
|
417
|
+
/**
|
|
418
|
+
* Persists a custom object instance to the platform.
|
|
419
|
+
* Throws if the object is not proxied.
|
|
420
|
+
*
|
|
421
|
+
* @internal
|
|
422
|
+
*/
|
|
423
|
+
export declare function _persistObject(obj: BaseObject, options?: _PersistOptions): Promise<void>;
|
|
424
|
+
|
|
425
|
+
/**
|
|
426
|
+
* Options for persistence operations.
|
|
427
|
+
*
|
|
428
|
+
* @internal
|
|
429
|
+
*/
|
|
430
|
+
export declare interface _PersistOptions {
|
|
431
|
+
/** Event emitter for telemetry */
|
|
432
|
+
eventEmitter?: _RuntimeEventEmitter;
|
|
433
|
+
/** Fetch function (for testing with mocks) */
|
|
434
|
+
fetchFn?: typeof fetch;
|
|
435
|
+
/** Base URL for the persistence API */
|
|
436
|
+
baseUrl?: string;
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
/**
|
|
440
|
+
* Platform metadata attached to custom object constructors via decorators.
|
|
441
|
+
*
|
|
442
|
+
* @internal
|
|
443
|
+
*/
|
|
444
|
+
export declare interface _PlatformMetadata {
|
|
445
|
+
/** API name of the custom object */
|
|
446
|
+
apiName: string;
|
|
447
|
+
/** Registered actions by category */
|
|
448
|
+
actions: { instance: Record<string, _ActionMetadata> };
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
/**
|
|
452
|
+
* Result of creating a proxied instance.
|
|
453
|
+
*
|
|
454
|
+
* @internal
|
|
455
|
+
*/
|
|
456
|
+
export declare interface _ProxiedObject<T> {
|
|
457
|
+
/** The proxied instance */
|
|
458
|
+
proxy: T;
|
|
459
|
+
/** The proxy state for change tracking */
|
|
460
|
+
state: _ProxyState;
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
/**
|
|
464
|
+
* Symbol key for accessing the proxy state on a proxied instance.
|
|
465
|
+
*
|
|
466
|
+
* Local (non-global) symbol so that external code cannot reconstruct the key
|
|
467
|
+
* via Symbol.for() and reach into internal proxy state.
|
|
468
|
+
*
|
|
469
|
+
* @internal
|
|
470
|
+
*/
|
|
471
|
+
export declare const _PROXY_STATE: unique symbol;
|
|
472
|
+
|
|
473
|
+
/**
|
|
474
|
+
* Event emitted when a field is set through the proxy.
|
|
475
|
+
*
|
|
476
|
+
* @internal
|
|
477
|
+
*/
|
|
478
|
+
export declare interface _ProxySetEvent {
|
|
479
|
+
/** Discriminant for the proxy:set event. */
|
|
480
|
+
type: 'proxy:set';
|
|
481
|
+
/** Name of the field that was set. */
|
|
482
|
+
field: string;
|
|
483
|
+
/** New value assigned to the field. */
|
|
484
|
+
value: unknown;
|
|
485
|
+
/** Unix epoch milliseconds when the set occurred. */
|
|
486
|
+
timestamp: number;
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
/**
|
|
490
|
+
* Internal state maintained by the proxy for change tracking.
|
|
491
|
+
*
|
|
492
|
+
* @internal
|
|
493
|
+
*/
|
|
494
|
+
export declare interface _ProxyState {
|
|
495
|
+
/** Current field values as seen through the proxy */
|
|
496
|
+
fields: Record<string, unknown>;
|
|
497
|
+
/** Queue of updates since last save */
|
|
498
|
+
pendingUpdates: _UpdateFrame[];
|
|
499
|
+
/** Snapshot of data as it existed at last save */
|
|
500
|
+
lastSavedSnapshot: Record<string, unknown>;
|
|
501
|
+
/**
|
|
502
|
+
* When true, the fields proxy (and its recursive sub-proxies) skip
|
|
503
|
+
* dirty-tracking. Set by the Logic wrapper before hydration from a
|
|
504
|
+
* platform point-read, cleared immediately after. This prevents
|
|
505
|
+
* hydration from producing spurious pending updates.
|
|
506
|
+
*
|
|
507
|
+
* @internal
|
|
508
|
+
*/
|
|
509
|
+
hydrating: boolean;
|
|
510
|
+
/**
|
|
511
|
+
* Accumulated field updates from save() or __queueSave() calls during
|
|
512
|
+
* an action execution. Flushed from pendingUpdates by each save call.
|
|
513
|
+
* The Logic wrapper reads this after the action returns to populate
|
|
514
|
+
* `updatedFields` in the response envelope, then clears it.
|
|
515
|
+
*
|
|
516
|
+
* @internal
|
|
517
|
+
*/
|
|
518
|
+
slatedUpdates: Record<string, unknown>;
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
/**
|
|
522
|
+
* Registers a custom object class by its api name.
|
|
523
|
+
* Validates that the class has platform metadata attached.
|
|
524
|
+
*
|
|
525
|
+
* @internal
|
|
526
|
+
*/
|
|
527
|
+
export declare function _registerClass<T extends BaseObject>(constructor: _CustomObjectConstructor<T>): void;
|
|
528
|
+
|
|
529
|
+
/**
|
|
530
|
+
* Union of all runtime events.
|
|
531
|
+
*
|
|
532
|
+
* @internal
|
|
533
|
+
*/
|
|
534
|
+
export declare type _RuntimeEvent = _InvokeBeginEvent | _InvokeCompleteEvent | _InvokeErrorEvent | _ProxySetEvent | _SaveBeginEvent | _SaveCompleteEvent | _SpanBeginEvent | _SpanEndEvent | _SpanErrorEvent;
|
|
535
|
+
|
|
536
|
+
/**
|
|
537
|
+
* Event emitter interface for runtime telemetry.
|
|
538
|
+
*
|
|
539
|
+
* @internal
|
|
540
|
+
*/
|
|
541
|
+
export declare interface _RuntimeEventEmitter {
|
|
542
|
+
/** Broadcasts an event to all subscribed listeners */
|
|
543
|
+
emit(event: _RuntimeEvent): void;
|
|
544
|
+
/** Registers a listener; returns an unsubscribe function */
|
|
545
|
+
subscribe(listener: (event: _RuntimeEvent) => void): () => void;
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
/**
|
|
549
|
+
* Event emitted when a save operation begins.
|
|
550
|
+
*
|
|
551
|
+
* @internal
|
|
552
|
+
*/
|
|
553
|
+
export declare interface _SaveBeginEvent {
|
|
554
|
+
/** Discriminant for the save:begin event. */
|
|
555
|
+
type: 'save:begin';
|
|
556
|
+
/** Field data being submitted to the platform. */
|
|
557
|
+
payload: Record<string, unknown>;
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
/**
|
|
561
|
+
* Event emitted when a save operation completes successfully.
|
|
562
|
+
*
|
|
563
|
+
* @internal
|
|
564
|
+
*/
|
|
565
|
+
export declare interface _SaveCompleteEvent {
|
|
566
|
+
/** Discriminant for the save:complete event. */
|
|
567
|
+
type: 'save:complete';
|
|
568
|
+
/** Raw response returned by the platform after a successful save. */
|
|
569
|
+
response: Record<string, unknown>;
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
/**
|
|
573
|
+
* Handler function that persists a custom object instance.
|
|
574
|
+
* This is called by BaseObject.save() when configured.
|
|
575
|
+
*
|
|
576
|
+
* @internal
|
|
577
|
+
*/
|
|
578
|
+
export declare type _SaveHandler = (obj: BaseObject, state: _ProxyState, eventEmitter?: _RuntimeEventEmitter) => Promise<SaveResult>;
|
|
579
|
+
|
|
580
|
+
/**
|
|
581
|
+
* Result returned from save operations.
|
|
582
|
+
*
|
|
583
|
+
* @public
|
|
584
|
+
*/
|
|
585
|
+
export declare interface SaveResult {
|
|
586
|
+
/** Number of fields updated */
|
|
587
|
+
updatedFieldCount: number;
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
/**
|
|
591
|
+
* Event emitted when a method execution span begins.
|
|
592
|
+
*
|
|
593
|
+
* @internal
|
|
594
|
+
*/
|
|
595
|
+
export declare interface _SpanBeginEvent {
|
|
596
|
+
/** Discriminant for the span:begin event. */
|
|
597
|
+
type: 'span:begin';
|
|
598
|
+
/** Unique identifier for correlating begin/end/error events within a single span. */
|
|
599
|
+
spanId: string;
|
|
600
|
+
/** Name of the method being executed. */
|
|
601
|
+
name: string;
|
|
602
|
+
/** Arguments passed to the method. */
|
|
603
|
+
params?: unknown;
|
|
604
|
+
/** Whether the method is a static class method. */
|
|
605
|
+
isStatic?: boolean;
|
|
606
|
+
/** Nesting depth for recursive or nested method calls. */
|
|
607
|
+
depth?: number;
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
/**
|
|
611
|
+
* Event emitted when a method execution span ends successfully.
|
|
612
|
+
*
|
|
613
|
+
* @internal
|
|
614
|
+
*/
|
|
615
|
+
export declare interface _SpanEndEvent {
|
|
616
|
+
/** Discriminant for the span:end event. */
|
|
617
|
+
type: 'span:end';
|
|
618
|
+
/** Unique identifier correlating this event to the matching span:begin. */
|
|
619
|
+
spanId: string;
|
|
620
|
+
/** Name of the method that completed. */
|
|
621
|
+
name: string;
|
|
622
|
+
/** Elapsed time in milliseconds from span:begin to span:end. */
|
|
623
|
+
duration: number;
|
|
624
|
+
/** Value returned by the method, if any. */
|
|
625
|
+
result?: unknown;
|
|
626
|
+
/** Whether the method is a static class method. */
|
|
627
|
+
isStatic?: boolean;
|
|
628
|
+
/** Nesting depth for recursive or nested method calls. */
|
|
629
|
+
depth?: number;
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
/**
|
|
633
|
+
* Event emitted when a method execution span encounters an error.
|
|
634
|
+
*
|
|
635
|
+
* @internal
|
|
636
|
+
*/
|
|
637
|
+
export declare interface _SpanErrorEvent {
|
|
638
|
+
/** Discriminant for the span:error event. */
|
|
639
|
+
type: 'span:error';
|
|
640
|
+
/** Unique identifier correlating this event to the matching span:begin. */
|
|
641
|
+
spanId: string;
|
|
642
|
+
/** Name of the method that threw. */
|
|
643
|
+
name: string;
|
|
644
|
+
/** Elapsed time in milliseconds from span:begin to the point of failure. */
|
|
645
|
+
duration: number;
|
|
646
|
+
/** Serializable representation of the thrown error. */
|
|
647
|
+
error: {
|
|
648
|
+
message: string;
|
|
649
|
+
name: string;
|
|
650
|
+
stack?: string;
|
|
651
|
+
};
|
|
652
|
+
/** Whether the method is a static class method. */
|
|
653
|
+
isStatic?: boolean;
|
|
654
|
+
/** Nesting depth for recursive or nested method calls. */
|
|
655
|
+
depth?: number;
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
/**
|
|
659
|
+
* Fields that are not tracked for changes by the proxy.
|
|
660
|
+
* These are system-managed fields that should not appear in pendingUpdates.
|
|
661
|
+
*
|
|
662
|
+
* @internal
|
|
663
|
+
*/
|
|
664
|
+
export declare const _UNTRACKED_FIELDS: Set<string>;
|
|
665
|
+
|
|
666
|
+
/**
|
|
667
|
+
* Represents a single field update in the proxy's change tracking.
|
|
668
|
+
*
|
|
669
|
+
* @internal
|
|
670
|
+
*/
|
|
671
|
+
export declare interface _UpdateFrame {
|
|
672
|
+
/** Name of the field that was modified. */
|
|
673
|
+
field: string;
|
|
674
|
+
/** Value assigned to the field at the time of the update. */
|
|
675
|
+
value: unknown;
|
|
676
|
+
/** Unix epoch milliseconds when the update was recorded. */
|
|
677
|
+
timestamp: number;
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
export { }
|