@furo/open-models 1.15.0 → 1.15.2
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/custom-elements.json +458 -458
- package/dist/FieldNode.d.ts +3 -3
- package/dist/FieldNode.js.map +1 -1
- package/dist/decorators/FieldBindings.d.ts +1 -1
- package/dist/decorators/FieldBindings.js.map +1 -1
- package/dist/decorators/ModelDecorators.d.ts +5 -8
- package/dist/decorators/ModelDecorators.js +5 -5
- package/dist/decorators/ModelDecorators.js.map +1 -1
- package/dist/decorators/ServiceDecorators.d.ts +5 -5
- package/dist/decorators/ServiceDecorators.js +5 -5
- package/dist/decorators/ServiceDecorators.js.map +1 -1
- package/dist/decorators/defaultServiceEventHandlers.d.ts +5 -5
- package/dist/decorators/defaultServiceEventHandlers.js +6 -6
- package/dist/decorators/defaultServiceEventHandlers.js.map +1 -1
- package/dist/index.d.ts +4 -5
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/package.json +5 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { EntityServiceEventMap } from "./EntityServiceTypes.js";
|
|
2
2
|
/**
|
|
3
|
-
* ###
|
|
3
|
+
* ### ServiceBindings Factory
|
|
4
4
|
*
|
|
5
5
|
* Creates type-safe decorators bound to a specific service instance.
|
|
6
6
|
* Use this to bind component properties and methods to service events.
|
|
@@ -12,9 +12,9 @@ import { EntityServiceEventMap } from "./EntityServiceTypes.js";
|
|
|
12
12
|
* Usage:
|
|
13
13
|
* ```typescript
|
|
14
14
|
* import { cubeEntityService } from "./CubeEntityService";
|
|
15
|
-
* import {
|
|
15
|
+
* import { ServiceBindings } from "./ServiceDecorators.js";
|
|
16
16
|
*
|
|
17
|
-
* const cube =
|
|
17
|
+
* const cube = ServiceBindings(cubeEntityService);
|
|
18
18
|
*
|
|
19
19
|
* class MyComponent extends LitElement {
|
|
20
20
|
* // Property binding - type-safe event name, auto-extracts from detail
|
|
@@ -46,14 +46,14 @@ import { EntityServiceEventMap } from "./EntityServiceTypes.js";
|
|
|
46
46
|
* "custom-event": { data: string };
|
|
47
47
|
* }
|
|
48
48
|
*
|
|
49
|
-
* const myBindings =
|
|
49
|
+
* const myBindings = ServiceBindings<MyServiceEventMap>(myService);
|
|
50
50
|
* ```
|
|
51
51
|
*
|
|
52
52
|
* @typeParam TEventMap - The event map type (defaults to EntityServiceEventMap)
|
|
53
53
|
* @param service - The EventTarget service to bind to
|
|
54
54
|
* @returns Object with `bindToEvent` and `onEvent` decorator factories
|
|
55
55
|
*/
|
|
56
|
-
export declare function
|
|
56
|
+
export declare function ServiceBindings<TEventMap extends EntityServiceEventMap = EntityServiceEventMap>(service: EventTarget): {
|
|
57
57
|
/**
|
|
58
58
|
* Binds a property to a service event.
|
|
59
59
|
* When the event fires, the property is automatically updated from event.detail.
|
|
@@ -6,7 +6,7 @@ const PROPERTY_PATCHED = Symbol.for("__servicePropertyPatched__");
|
|
|
6
6
|
const EVENT_PATCHED = Symbol.for("__serviceEventPatched__");
|
|
7
7
|
const EVENT_METHODS = Symbol.for("__serviceEventMethods__");
|
|
8
8
|
/**
|
|
9
|
-
* ###
|
|
9
|
+
* ### ServiceBindings Factory
|
|
10
10
|
*
|
|
11
11
|
* Creates type-safe decorators bound to a specific service instance.
|
|
12
12
|
* Use this to bind component properties and methods to service events.
|
|
@@ -18,9 +18,9 @@ const EVENT_METHODS = Symbol.for("__serviceEventMethods__");
|
|
|
18
18
|
* Usage:
|
|
19
19
|
* ```typescript
|
|
20
20
|
* import { cubeEntityService } from "./CubeEntityService";
|
|
21
|
-
* import {
|
|
21
|
+
* import { ServiceBindings } from "./ServiceDecorators.js";
|
|
22
22
|
*
|
|
23
|
-
* const cube =
|
|
23
|
+
* const cube = ServiceBindings(cubeEntityService);
|
|
24
24
|
*
|
|
25
25
|
* class MyComponent extends LitElement {
|
|
26
26
|
* // Property binding - type-safe event name, auto-extracts from detail
|
|
@@ -52,14 +52,14 @@ const EVENT_METHODS = Symbol.for("__serviceEventMethods__");
|
|
|
52
52
|
* "custom-event": { data: string };
|
|
53
53
|
* }
|
|
54
54
|
*
|
|
55
|
-
* const myBindings =
|
|
55
|
+
* const myBindings = ServiceBindings<MyServiceEventMap>(myService);
|
|
56
56
|
* ```
|
|
57
57
|
*
|
|
58
58
|
* @typeParam TEventMap - The event map type (defaults to EntityServiceEventMap)
|
|
59
59
|
* @param service - The EventTarget service to bind to
|
|
60
60
|
* @returns Object with `bindToEvent` and `onEvent` decorator factories
|
|
61
61
|
*/
|
|
62
|
-
export function
|
|
62
|
+
export function ServiceBindings(service) {
|
|
63
63
|
return {
|
|
64
64
|
/**
|
|
65
65
|
* Binds a property to a service event.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ServiceDecorators.js","sourceRoot":"","sources":["../../src/decorators/ServiceDecorators.ts"],"names":[],"mappings":"AAcA,MAAM,wBAAwB,GAAG,IAAI,OAAO,EAA4C,CAAC;AAczF,mCAAmC;AACnC,MAAM,kBAAkB,GAAG,MAAM,CAAC,GAAG,CAAC,8BAA8B,CAAC,CAAC;AACtE,MAAM,eAAe,GAAG,MAAM,CAAC,GAAG,CAAC,2BAA2B,CAAC,CAAC;AAChE,MAAM,gBAAgB,GAAG,MAAM,CAAC,GAAG,CAAC,4BAA4B,CAAC,CAAC;AAClE,MAAM,aAAa,GAAG,MAAM,CAAC,GAAG,CAAC,yBAAyB,CAAC,CAAC;AAC5D,MAAM,aAAa,GAAG,MAAM,CAAC,GAAG,CAAC,yBAAyB,CAAC,CAAC;AAE5D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqDG;AACH,MAAM,UAAU,eAAe,CAAkE,OAAoB;IACnH,OAAO;QACL;;;;;;;WAOG;QACH,WAAW,CAAqC,SAAY,EAAE,SAAkB;YAC9E,OAAO,SAAS,oBAAoB,CAAC,MAAc,EAAE,WAAmB;gBACtE,kDAAkD;gBAClD,iCAAiC;gBACjC,MAAM,G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C,GAAG,SAAS,CAAC;QAElC,OAAO,CAAC,OAAO,CAAC,CAAC,EAAE,WAAW,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,EAAE,EAAE;YAC9D,MAAM,QAAQ,GAAG,CAAC,CAAC,CAAc,EAAE,EAAE;gBACnC,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC;YAC9B,CAAC,CAAkB,CAAC;YAEpB,SAAS,CAAC,GAAG,CAAC,WAAW,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC,CAAC;YAC7D,OAAO,CAAC,gBAAgB,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;QAChD,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;IAEF,IAAI,CAAC,SAAS,CAAC,oBAAoB,GAAG,SAAS,oBAAoB;QAGjE,MAAM,SAAS,GAAG,IAAI,CAAC,eAAe,CAAC,CAAC;QACxC,IAAI,SAAS,EAAE,CAAC;YACd,SAAS,CAAC,OAAO,CAAC,CAAC,EAAE,QAAQ,EAAE,OAAO,EAAE,SAAS,EAAE,EAAE,EAAE;gBACrD,OAAO,CAAC,mBAAmB,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;YACnD,CAAC,CAAC,CAAC;YACH,SAAS,CAAC,KAAK,EAAE,CAAC;QACpB,CAAC;QAED,oBAAoB,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;IACnC,CAAC,CAAC;AACJ,CAAC","sourcesContent":["/* eslint-disable no-param-reassign */\nimport { LitElement, ReactiveElement } from \"lit\";\n\nimport { EntityServiceEventMap } from \"./EntityServiceTypes\";\n\n/**\n * Metadata storage for property bindings\n * Maps: class prototype -> Map<propertyKey, { service, eventType, detailKey }>\n */\ninterface PropertyBindingMeta {\n service: EventTarget;\n eventType: string;\n detailKey: string;\n}\nconst propertyBindingsMetadata = new WeakMap<object, Map<string, PropertyBindingMeta>>();\n\n/**\n * Metadata storage for event method bindings\n * Maps: class constructor -> Array<{ propertyKey, service, eventType, method }>\n */\ninterface EventBindingMeta {\n propertyKey: string;\n service: EventTarget;\n eventType: string;\n // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\n method: Function;\n}\n\n// Symbol keys for instance storage\nconst PROPERTY_LISTENERS = Symbol.for(\"__servicePropertyListeners__\");\nconst EVENT_LISTENERS = Symbol.for(\"__serviceEventListeners__\");\nconst PROPERTY_PATCHED = Symbol.for(\"__servicePropertyPatched__\");\nconst EVENT_PATCHED = Symbol.for(\"__serviceEventPatched__\");\nconst EVENT_METHODS = Symbol.for(\"__serviceEventMethods__\");\n\n/**\n * ### serviceBindings Factory\n *\n * Creates type-safe decorators bound to a specific service instance.\n * Use this to bind component properties and methods to service events.\n *\n * The factory is generic and works with any `EventTarget`.\n * Event types and their detail payloads are type-checked at compile time\n * via the `TEventMap` type parameter.\n *\n * Usage:\n * ```typescript\n * import { cubeEntityService } from \"./CubeEntityService\";\n * import { serviceBindings } from \"./ServiceDecorators\";\n *\n * const cube = serviceBindings(cubeEntityService);\n *\n * class MyComponent extends LitElement {\n * // Property binding - type-safe event name, auto-extracts from detail\n * @cube.bindToEvent(\"busy-changed\")\n * @state()\n * private busy: boolean = false;\n *\n * // Event binding - type-safe event name and detail type\n * @cube.onEvent(\"response-received\")\n * private onResponseReceived() {\n * console.log(\"Data received!\");\n * }\n *\n * @cube.onEvent(\"error-5xx\")\n * private onError(detail: { serverResponse: Response }) {\n * console.error(\"Server error:\", detail.serverResponse);\n * }\n *\n * // Compile error! \"typo-event\" is not a valid event type\n * // @cube.onEvent(\"typo-event\")\n * }\n * ```\n *\n * ### Custom Event Maps\n *\n * To add custom events, extend the `EntityServiceEventMap`:\n * ```typescript\n * interface MyServiceEventMap extends EntityServiceEventMap {\n * \"custom-event\": { data: string };\n * }\n *\n * const myBindings = serviceBindings<MyServiceEventMap>(myService);\n * ```\n *\n * @typeParam TEventMap - The event map type (defaults to EntityServiceEventMap)\n * @param service - The EventTarget service to bind to\n * @returns Object with `bindToEvent` and `onEvent` decorator factories\n */\nexport function serviceBindings<TEventMap extends EntityServiceEventMap = EntityServiceEventMap>(service: EventTarget) {\n return {\n /**\n * Binds a property to a service event.\n * When the event fires, the property is automatically updated from event.detail.\n *\n * @typeParam K - The event type (constrained to valid event names)\n * @param eventType - The event name to listen for\n * @param detailKey - Optional key to extract from event.detail (defaults to inferring from event type)\n */\n bindToEvent<K extends keyof TEventMap & string>(eventType: K, detailKey?: string) {\n return function bindToEventDecorator(target: object, propertyKey: string) {\n // Infer detailKey from event type if not provided\n // e.g., \"busy-changed\" -> \"busy\"\n const key = detailKey ?? inferDetailKey(eventType, propertyKey);\n\n // Get or create metadata map for this class\n let metadata = propertyBindingsMetadata.get(target);\n if (!metadata) {\n metadata = new Map();\n propertyBindingsMetadata.set(target, metadata);\n }\n metadata.set(propertyKey, { service, eventType, detailKey: key });\n\n // Patch lifecycle methods (only once per class)\n patchPropertyLifecycle(target.constructor as typeof ReactiveElement);\n };\n },\n\n /**\n * Binds a method to a service event.\n * When the event fires, the method is called with event.detail as argument.\n *\n * The detail type is inferred from the event map:\n * - `@cube.onEvent(\"busy-changed\")` → method receives `{ busy: boolean }`\n * - `@cube.onEvent(\"error-5xx\")` → method receives `{ serverResponse: Response }`\n * - `@cube.onEvent(\"response-received\")` → method receives `{ response, serverResponse }`\n *\n * @typeParam K - The event type (constrained to valid event names)\n * @param eventType - The event name to listen for\n */\n onEvent<K extends keyof TEventMap & string>(eventType: K) {\n return function onEventDecorator(target: object, propertyKey: string, descriptor: PropertyDescriptor) {\n const originalMethod = descriptor.value;\n const ctor = target.constructor as typeof ReactiveElement;\n\n // Store method metadata on the constructor\n let methods = (ctor as unknown as Record<symbol, EventBindingMeta[]>)[EVENT_METHODS];\n if (!methods) {\n methods = [];\n (ctor as unknown as Record<symbol, EventBindingMeta[]>)[EVENT_METHODS] = methods;\n }\n methods.push({ propertyKey, service, eventType, method: originalMethod });\n\n // Patch lifecycle methods (only once per class)\n patchEventLifecycle(ctor);\n };\n },\n };\n}\n\n/**\n * Infer the detail key from the event type or property name\n */\nfunction inferDetailKey(eventType: string, propertyKey: string): string {\n // Common patterns: \"busy-changed\" -> \"busy\", \"validity-changed\" -> check property\n const match = eventType.match(/^(.+)-changed$/);\n if (match) {\n return match[1];\n }\n // Fall back to property name\n return propertyKey;\n}\n\n/**\n * Patch connectedCallback/disconnectedCallback for property bindings\n */\nfunction patchPropertyLifecycle(ctor: typeof ReactiveElement): void {\n if ((ctor as unknown as Record<symbol, boolean>)[PROPERTY_PATCHED]) {\n return;\n }\n (ctor as unknown as Record<symbol, boolean>)[PROPERTY_PATCHED] = true;\n\n const originalConnected = ctor.prototype.connectedCallback;\n const originalDisconnected = ctor.prototype.disconnectedCallback;\n\n ctor.prototype.connectedCallback = function connectedCallback(\n this: LitElement & Record<symbol, Map<string, { listener: EventListener; service: EventTarget; eventType: string }>>\n ) {\n originalConnected?.call(this);\n\n const metadata = propertyBindingsMetadata.get(Object.getPrototypeOf(this));\n if (!metadata) return;\n\n const listeners = new Map<string, { listener: EventListener; service: EventTarget; eventType: string }>();\n this[PROPERTY_LISTENERS] = listeners;\n\n metadata.forEach(({ service, eventType, detailKey }, propKey) => {\n const listener = ((e: CustomEvent) => {\n if (e.detail && detailKey in e.detail) {\n (this as unknown as Record<string, unknown>)[propKey] = e.detail[detailKey];\n }\n }) as EventListener;\n\n listeners.set(propKey, { listener, service, eventType });\n service.addEventListener(eventType, listener);\n });\n };\n\n ctor.prototype.disconnectedCallback = function disconnectedCallback(\n this: LitElement & Record<symbol, Map<string, { listener: EventListener; service: EventTarget; eventType: string }>>\n ) {\n const listeners = this[PROPERTY_LISTENERS];\n if (listeners) {\n listeners.forEach(({ listener, service, eventType }) => {\n service.removeEventListener(eventType, listener);\n });\n listeners.clear();\n }\n\n originalDisconnected?.call(this);\n };\n}\n\n/**\n * Patch connectedCallback/disconnectedCallback for event method bindings\n */\nfunction patchEventLifecycle(ctor: typeof ReactiveElement): void {\n if ((ctor as unknown as Record<symbol, boolean>)[EVENT_PATCHED]) {\n return;\n }\n (ctor as unknown as Record<symbol, boolean>)[EVENT_PATCHED] = true;\n\n const originalConnected = ctor.prototype.connectedCallback;\n const originalDisconnected = ctor.prototype.disconnectedCallback;\n\n ctor.prototype.connectedCallback = function connectedCallback(\n this: LitElement & Record<symbol, Map<string, { listener: EventListener; service: EventTarget; eventType: string }>>\n ) {\n originalConnected?.call(this);\n\n const methods = (this.constructor as unknown as Record<symbol, EventBindingMeta[]>)[EVENT_METHODS];\n if (!methods) return;\n\n const listeners = new Map<string, { listener: EventListener; service: EventTarget; eventType: string }>();\n this[EVENT_LISTENERS] = listeners;\n\n methods.forEach(({ propertyKey, service, eventType, method }) => {\n const listener = ((e: CustomEvent) => {\n method.call(this, e.detail);\n }) as EventListener;\n\n listeners.set(propertyKey, { listener, service, eventType });\n service.addEventListener(eventType, listener);\n });\n };\n\n ctor.prototype.disconnectedCallback = function disconnectedCallback(\n this: LitElement & Record<symbol, Map<string, { listener: EventListener; service: EventTarget; eventType: string }>>\n ) {\n const listeners = this[EVENT_LISTENERS];\n if (listeners) {\n listeners.forEach(({ listener, service, eventType }) => {\n service.removeEventListener(eventType, listener);\n });\n listeners.clear();\n }\n\n originalDisconnected?.call(this);\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"ServiceDecorators.js","sourceRoot":"","sources":["../../src/decorators/ServiceDecorators.ts"],"names":[],"mappings":"AAcA,MAAM,wBAAwB,GAAG,IAAI,OAAO,EAA4C,CAAC;AAczF,mCAAmC;AACnC,MAAM,kBAAkB,GAAG,MAAM,CAAC,GAAG,CAAC,8BAA8B,CAAC,CAAC;AACtE,MAAM,eAAe,GAAG,MAAM,CAAC,GAAG,CAAC,2BAA2B,CAAC,CAAC;AAChE,MAAM,gBAAgB,GAAG,MAAM,CAAC,GAAG,CAAC,4BAA4B,CAAC,CAAC;AAClE,MAAM,aAAa,GAAG,MAAM,CAAC,GAAG,CAAC,yBAAyB,C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E,IAAI,CAAC,IAAI,CAAC,CAAC;IACnC,CAAC,CAAC;AACJ,CAAC","sourcesContent":["/* eslint-disable no-param-reassign */\nimport { LitElement, ReactiveElement } from \"lit\";\n\nimport { EntityServiceEventMap } from \"./EntityServiceTypes\";\n\n/**\n * Metadata storage for property bindings\n * Maps: class prototype -> Map<propertyKey, { service, eventType, detailKey }>\n */\ninterface PropertyBindingMeta {\n service: EventTarget;\n eventType: string;\n detailKey: string;\n}\nconst propertyBindingsMetadata = new WeakMap<object, Map<string, PropertyBindingMeta>>();\n\n/**\n * Metadata storage for event method bindings\n * Maps: class constructor -> Array<{ propertyKey, service, eventType, method }>\n */\ninterface EventBindingMeta {\n propertyKey: string;\n service: EventTarget;\n eventType: string;\n // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\n method: Function;\n}\n\n// Symbol keys for instance storage\nconst PROPERTY_LISTENERS = Symbol.for(\"__servicePropertyListeners__\");\nconst EVENT_LISTENERS = Symbol.for(\"__serviceEventListeners__\");\nconst PROPERTY_PATCHED = Symbol.for(\"__servicePropertyPatched__\");\nconst EVENT_PATCHED = Symbol.for(\"__serviceEventPatched__\");\nconst EVENT_METHODS = Symbol.for(\"__serviceEventMethods__\");\n\n/**\n * ### ServiceBindings Factory\n *\n * Creates type-safe decorators bound to a specific service instance.\n * Use this to bind component properties and methods to service events.\n *\n * The factory is generic and works with any `EventTarget`.\n * Event types and their detail payloads are type-checked at compile time\n * via the `TEventMap` type parameter.\n *\n * Usage:\n * ```typescript\n * import { cubeEntityService } from \"./CubeEntityService\";\n * import { ServiceBindings } from \"./ServiceDecorators\";\n *\n * const cube = ServiceBindings(cubeEntityService);\n *\n * class MyComponent extends LitElement {\n * // Property binding - type-safe event name, auto-extracts from detail\n * @cube.bindToEvent(\"busy-changed\")\n * @state()\n * private busy: boolean = false;\n *\n * // Event binding - type-safe event name and detail type\n * @cube.onEvent(\"response-received\")\n * private onResponseReceived() {\n * console.log(\"Data received!\");\n * }\n *\n * @cube.onEvent(\"error-5xx\")\n * private onError(detail: { serverResponse: Response }) {\n * console.error(\"Server error:\", detail.serverResponse);\n * }\n *\n * // Compile error! \"typo-event\" is not a valid event type\n * // @cube.onEvent(\"typo-event\")\n * }\n * ```\n *\n * ### Custom Event Maps\n *\n * To add custom events, extend the `EntityServiceEventMap`:\n * ```typescript\n * interface MyServiceEventMap extends EntityServiceEventMap {\n * \"custom-event\": { data: string };\n * }\n *\n * const myBindings = ServiceBindings<MyServiceEventMap>(myService);\n * ```\n *\n * @typeParam TEventMap - The event map type (defaults to EntityServiceEventMap)\n * @param service - The EventTarget service to bind to\n * @returns Object with `bindToEvent` and `onEvent` decorator factories\n */\nexport function ServiceBindings<TEventMap extends EntityServiceEventMap = EntityServiceEventMap>(service: EventTarget) {\n return {\n /**\n * Binds a property to a service event.\n * When the event fires, the property is automatically updated from event.detail.\n *\n * @typeParam K - The event type (constrained to valid event names)\n * @param eventType - The event name to listen for\n * @param detailKey - Optional key to extract from event.detail (defaults to inferring from event type)\n */\n bindToEvent<K extends keyof TEventMap & string>(eventType: K, detailKey?: string) {\n return function bindToEventDecorator(target: object, propertyKey: string) {\n // Infer detailKey from event type if not provided\n // e.g., \"busy-changed\" -> \"busy\"\n const key = detailKey ?? inferDetailKey(eventType, propertyKey);\n\n // Get or create metadata map for this class\n let metadata = propertyBindingsMetadata.get(target);\n if (!metadata) {\n metadata = new Map();\n propertyBindingsMetadata.set(target, metadata);\n }\n metadata.set(propertyKey, { service, eventType, detailKey: key });\n\n // Patch lifecycle methods (only once per class)\n patchPropertyLifecycle(target.constructor as typeof ReactiveElement);\n };\n },\n\n /**\n * Binds a method to a service event.\n * When the event fires, the method is called with event.detail as argument.\n *\n * The detail type is inferred from the event map:\n * - `@cube.onEvent(\"busy-changed\")` → method receives `{ busy: boolean }`\n * - `@cube.onEvent(\"error-5xx\")` → method receives `{ serverResponse: Response }`\n * - `@cube.onEvent(\"response-received\")` → method receives `{ response, serverResponse }`\n *\n * @typeParam K - The event type (constrained to valid event names)\n * @param eventType - The event name to listen for\n */\n onEvent<K extends keyof TEventMap & string>(eventType: K) {\n return function onEventDecorator(target: object, propertyKey: string, descriptor: PropertyDescriptor) {\n const originalMethod = descriptor.value;\n const ctor = target.constructor as typeof ReactiveElement;\n\n // Store method metadata on the constructor\n let methods = (ctor as unknown as Record<symbol, EventBindingMeta[]>)[EVENT_METHODS];\n if (!methods) {\n methods = [];\n (ctor as unknown as Record<symbol, EventBindingMeta[]>)[EVENT_METHODS] = methods;\n }\n methods.push({ propertyKey, service, eventType, method: originalMethod });\n\n // Patch lifecycle methods (only once per class)\n patchEventLifecycle(ctor);\n };\n },\n };\n}\n\n/**\n * Infer the detail key from the event type or property name\n */\nfunction inferDetailKey(eventType: string, propertyKey: string): string {\n // Common patterns: \"busy-changed\" -> \"busy\", \"validity-changed\" -> check property\n const match = eventType.match(/^(.+)-changed$/);\n if (match) {\n return match[1];\n }\n // Fall back to property name\n return propertyKey;\n}\n\n/**\n * Patch connectedCallback/disconnectedCallback for property bindings\n */\nfunction patchPropertyLifecycle(ctor: typeof ReactiveElement): void {\n if ((ctor as unknown as Record<symbol, boolean>)[PROPERTY_PATCHED]) {\n return;\n }\n (ctor as unknown as Record<symbol, boolean>)[PROPERTY_PATCHED] = true;\n\n const originalConnected = ctor.prototype.connectedCallback;\n const originalDisconnected = ctor.prototype.disconnectedCallback;\n\n ctor.prototype.connectedCallback = function connectedCallback(\n this: LitElement & Record<symbol, Map<string, { listener: EventListener; service: EventTarget; eventType: string }>>\n ) {\n originalConnected?.call(this);\n\n const metadata = propertyBindingsMetadata.get(Object.getPrototypeOf(this));\n if (!metadata) return;\n\n const listeners = new Map<string, { listener: EventListener; service: EventTarget; eventType: string }>();\n this[PROPERTY_LISTENERS] = listeners;\n\n metadata.forEach(({ service, eventType, detailKey }, propKey) => {\n const listener = ((e: CustomEvent) => {\n if (e.detail && detailKey in e.detail) {\n (this as unknown as Record<string, unknown>)[propKey] = e.detail[detailKey];\n }\n }) as EventListener;\n\n listeners.set(propKey, { listener, service, eventType });\n service.addEventListener(eventType, listener);\n });\n };\n\n ctor.prototype.disconnectedCallback = function disconnectedCallback(\n this: LitElement & Record<symbol, Map<string, { listener: EventListener; service: EventTarget; eventType: string }>>\n ) {\n const listeners = this[PROPERTY_LISTENERS];\n if (listeners) {\n listeners.forEach(({ listener, service, eventType }) => {\n service.removeEventListener(eventType, listener);\n });\n listeners.clear();\n }\n\n originalDisconnected?.call(this);\n };\n}\n\n/**\n * Patch connectedCallback/disconnectedCallback for event method bindings\n */\nfunction patchEventLifecycle(ctor: typeof ReactiveElement): void {\n if ((ctor as unknown as Record<symbol, boolean>)[EVENT_PATCHED]) {\n return;\n }\n (ctor as unknown as Record<symbol, boolean>)[EVENT_PATCHED] = true;\n\n const originalConnected = ctor.prototype.connectedCallback;\n const originalDisconnected = ctor.prototype.disconnectedCallback;\n\n ctor.prototype.connectedCallback = function connectedCallback(\n this: LitElement & Record<symbol, Map<string, { listener: EventListener; service: EventTarget; eventType: string }>>\n ) {\n originalConnected?.call(this);\n\n const methods = (this.constructor as unknown as Record<symbol, EventBindingMeta[]>)[EVENT_METHODS];\n if (!methods) return;\n\n const listeners = new Map<string, { listener: EventListener; service: EventTarget; eventType: string }>();\n this[EVENT_LISTENERS] = listeners;\n\n methods.forEach(({ propertyKey, service, eventType, method }) => {\n const listener = ((e: CustomEvent) => {\n method.call(this, e.detail);\n }) as EventListener;\n\n listeners.set(propertyKey, { listener, service, eventType });\n service.addEventListener(eventType, listener);\n });\n };\n\n ctor.prototype.disconnectedCallback = function disconnectedCallback(\n this: LitElement & Record<symbol, Map<string, { listener: EventListener; service: EventTarget; eventType: string }>>\n ) {\n const listeners = this[EVENT_LISTENERS];\n if (listeners) {\n listeners.forEach(({ listener, service, eventType }) => {\n service.removeEventListener(eventType, listener);\n });\n listeners.clear();\n }\n\n originalDisconnected?.call(this);\n };\n}\n"]}
|
|
@@ -17,7 +17,7 @@ export interface DefaultServiceEventHandlersOptions {
|
|
|
17
17
|
isLoading?: () => boolean;
|
|
18
18
|
}
|
|
19
19
|
/**
|
|
20
|
-
* ###
|
|
20
|
+
* ### DefaultServiceEventHandlers
|
|
21
21
|
*
|
|
22
22
|
* Creates default service handlers that dispatch standard events.
|
|
23
23
|
* Use this to reduce boilerplate when setting up service handlers.
|
|
@@ -32,7 +32,7 @@ export interface DefaultServiceEventHandlersOptions {
|
|
|
32
32
|
*
|
|
33
33
|
* setupHandlers() {
|
|
34
34
|
* this.service.Get.setHandlers({
|
|
35
|
-
* ...
|
|
35
|
+
* ...DefaultServiceEventHandlers(this.dispatch),
|
|
36
36
|
* onResponse: (response, serverResponse) => {
|
|
37
37
|
* // Your custom response handling
|
|
38
38
|
* this.entity.fromLiteral(response.entity);
|
|
@@ -46,7 +46,7 @@ export interface DefaultServiceEventHandlersOptions {
|
|
|
46
46
|
* With loading check:
|
|
47
47
|
* ```typescript
|
|
48
48
|
* this.service.Get.setHandlers({
|
|
49
|
-
* ...
|
|
49
|
+
* ...DefaultServiceEventHandlers(this.dispatch, {
|
|
50
50
|
* isLoading: () => this.service.Get.isLoading || this.service.Update.isLoading,
|
|
51
51
|
* }),
|
|
52
52
|
* onResponse: (response, serverResponse) => { ... },
|
|
@@ -57,7 +57,7 @@ export interface DefaultServiceEventHandlersOptions {
|
|
|
57
57
|
* @param options - Optional configuration
|
|
58
58
|
* @returns Object with all standard handlers except onResponse
|
|
59
59
|
*/
|
|
60
|
-
export declare function
|
|
60
|
+
export declare function DefaultServiceEventHandlers(dispatch: DispatchFn, options?: DefaultServiceEventHandlersOptions): {
|
|
61
61
|
onRequestStarted(request: unknown): void;
|
|
62
62
|
onRequestFinished(request: unknown): void;
|
|
63
63
|
onResponseError(parsedResponse: unknown, serverResponse: Response): void;
|
|
@@ -85,5 +85,5 @@ export declare function defaultServiceEventHandlers(dispatch: DispatchFn, option
|
|
|
85
85
|
* @param target - The EventTarget to dispatch events on
|
|
86
86
|
* @returns A typed dispatch function
|
|
87
87
|
*/
|
|
88
|
-
export declare function
|
|
88
|
+
export declare function CreateDispatch(target: EventTarget): DispatchFn;
|
|
89
89
|
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* ###
|
|
2
|
+
* ### DefaultServiceEventHandlers
|
|
3
3
|
*
|
|
4
4
|
* Creates default service handlers that dispatch standard events.
|
|
5
5
|
* Use this to reduce boilerplate when setting up service handlers.
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
*
|
|
15
15
|
* setupHandlers() {
|
|
16
16
|
* this.service.Get.setHandlers({
|
|
17
|
-
* ...
|
|
17
|
+
* ...DefaultServiceEventHandlers(this.dispatch),
|
|
18
18
|
* onResponse: (response, serverResponse) => {
|
|
19
19
|
* // Your custom response handling
|
|
20
20
|
* this.entity.fromLiteral(response.entity);
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
* With loading check:
|
|
29
29
|
* ```typescript
|
|
30
30
|
* this.service.Get.setHandlers({
|
|
31
|
-
* ...
|
|
31
|
+
* ...DefaultServiceEventHandlers(this.dispatch, {
|
|
32
32
|
* isLoading: () => this.service.Get.isLoading || this.service.Update.isLoading,
|
|
33
33
|
* }),
|
|
34
34
|
* onResponse: (response, serverResponse) => { ... },
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
* @param options - Optional configuration
|
|
40
40
|
* @returns Object with all standard handlers except onResponse
|
|
41
41
|
*/
|
|
42
|
-
export function
|
|
42
|
+
export function DefaultServiceEventHandlers(dispatch, options = {}) {
|
|
43
43
|
const { isLoading } = options;
|
|
44
44
|
return {
|
|
45
45
|
onRequestStarted(request) {
|
|
@@ -92,9 +92,9 @@ export function defaultServiceEventHandlers(dispatch, options = {}) {
|
|
|
92
92
|
* @param target - The EventTarget to dispatch events on
|
|
93
93
|
* @returns A typed dispatch function
|
|
94
94
|
*/
|
|
95
|
-
export function
|
|
95
|
+
export function CreateDispatch(target) {
|
|
96
96
|
return function dispatchEvent(type, detail) {
|
|
97
97
|
target.dispatchEvent(new CustomEvent(type, { detail }));
|
|
98
98
|
};
|
|
99
99
|
}
|
|
100
|
-
//# sourceMappingURL=
|
|
100
|
+
//# sourceMappingURL=DefaultServiceEventHandlers.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"
|
|
1
|
+
{"version":3,"file":"DefaultServiceEventHandlers.js","sourceRoot":"","sources":["../../src/decorators/DefaultServiceEventHandlers.ts"],"names":[],"mappings":"AAqBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,MAAM,UAAU,2BAA2B,CAAC,QAAoB,EAAE,UAA8C,EAAE;IAChH,MAAM,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC;IAE9B,OAAO;QACL,gBAAgB,CAAC,OAAgB;YAC/B,QAAQ,CAAC,iBAAiB,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC;YACzC,QAAQ,CAAC,cAAc,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;QAC3C,CAAC;QAED,iBAAiB,CAAC,OAAgB;YAChC,QAAQ,CAAC,kBAAkB,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC;YAC1C,QAAQ,CAAC,cAAc,EAAE,EAAE,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC;QACtE,CAAC;QAED,eAAe,CAAC,cAAuB,EAAE,cAAwB;YAC/D,QAAQ,CAAC,gBAAgB,EAAE,EAAE,cAAc,EAAE,cAAc,EAAE,CAAC,CAAC;YAC/D,IAAI,cAAc,CAAC,MAAM,KAAK,GAAG,EAAE,CAAC;gBAClC,QAAQ,CAAC,WAAW,EAAE,EAAE,cAAc,EAAE,CAAC,CAAC;YAC5C,CAAC;YACD,IAAI,cAAc,CAAC,MAAM,IAAI,GAAG,EAAE,CAAC;gBACjC,QAAQ,CAAC,WAAW,EAAE,EAAE,cAAc,EAAE,CAAC,CAAC;YAC5C,CAAC;QACH,CAAC;QAED,kBAAkB,CAAC,cAAwB;YACzC,QAAQ,CAAC,WAAW,EAAE,EAAE,cAAc,EAAE,CAAC,CAAC;QAC5C,CAAC;QAED,aAAa,CAAC,cAAwB;YACpC,QAAQ,CAAC,cAAc,EAAE,EAAE,cAAc,EAAE,CAAC,CAAC;QAC/C,CAAC;QAED,gBAAgB,CAAC,MAAe;YAC9B,QAAQ,CAAC,iBAAiB,EAAE,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QAC1D,CAAC;QAED,YAAY,CAAC,KAAc;YACzB,QAAQ,CAAC,aAAa,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;QACrC,CAAC;KACF,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,cAAc,CAAC,MAAmB;IAChD,OAAO,SAAS,aAAa,CAAmC,IAAO,EAAE,MAAgC;QACvG,MAAM,CAAC,aAAa,CAAC,IAAI,WAAW,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC;IAC1D,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import { EntityServiceEventMap, EntityServiceEventType } from \"./EntityServiceTypes\";\n\n/**\n * Dispatch function type for entity service events.\n * Accepts any function that can dispatch the standard EntityServiceEventType events.\n * This allows extended event maps (like CubeServiceEventMap) to be used.\n */\ntype DispatchFn = (type: EntityServiceEventType, detail: EntityServiceEventMap[EntityServiceEventType]) => void;\n\n/**\n * Options for creating default service event handlers.\n */\nexport interface DefaultServiceEventHandlersOptions {\n /**\n * Function to check if the service is still loading.\n * Used by `onRequestFinished` to determine the busy state.\n * If not provided, busy is set to false on request finish.\n */\n isLoading?: () => boolean;\n}\n\n/**\n * ### DefaultServiceEventHandlers\n *\n * Creates default service handlers that dispatch standard events.\n * Use this to reduce boilerplate when setting up service handlers.\n *\n * The `onResponse` handler is intentionally NOT included - you must provide your own\n * implementation since response handling is typically service-specific.\n *\n * Usage:\n * ```typescript\n * class MyEntityService extends EventTarget {\n * private dispatch = createDispatch(this);\n *\n * setupHandlers() {\n * this.service.Get.setHandlers({\n * ...DefaultServiceEventHandlers(this.dispatch),\n * onResponse: (response, serverResponse) => {\n * // Your custom response handling\n * this.entity.fromLiteral(response.entity);\n * this.dispatch(\"response-received\", { response, serverResponse });\n * },\n * });\n * }\n * }\n * ```\n *\n * With loading check:\n * ```typescript\n * this.service.Get.setHandlers({\n * ...DefaultServiceEventHandlers(this.dispatch, {\n * isLoading: () => this.service.Get.isLoading || this.service.Update.isLoading,\n * }),\n * onResponse: (response, serverResponse) => { ... },\n * });\n * ```\n *\n * @param dispatch - Function to dispatch events (typically bound to the service's dispatchEvent)\n * @param options - Optional configuration\n * @returns Object with all standard handlers except onResponse\n */\nexport function DefaultServiceEventHandlers(dispatch: DispatchFn, options: DefaultServiceEventHandlersOptions = {}) {\n const { isLoading } = options;\n\n return {\n onRequestStarted(request: unknown) {\n dispatch(\"request-started\", { request });\n dispatch(\"busy-changed\", { busy: true });\n },\n\n onRequestFinished(request: unknown) {\n dispatch(\"request-finished\", { request });\n dispatch(\"busy-changed\", { busy: isLoading ? isLoading() : false });\n },\n\n onResponseError(parsedResponse: unknown, serverResponse: Response) {\n dispatch(\"response-error\", { parsedResponse, serverResponse });\n if (serverResponse.status === 404) {\n dispatch(\"error-404\", { serverResponse });\n }\n if (serverResponse.status >= 500) {\n dispatch(\"error-5xx\", { serverResponse });\n }\n },\n\n onResponseErrorRaw(serverResponse: Response) {\n dispatch(\"raw-error\", { serverResponse });\n },\n\n onResponseRaw(serverResponse: Response) {\n dispatch(\"raw-response\", { serverResponse });\n },\n\n onRequestAborted(reason: unknown) {\n dispatch(\"request-aborted\", { reason: String(reason) });\n },\n\n onFatalError(error: unknown) {\n dispatch(\"fatal-error\", { error });\n },\n };\n}\n\n/**\n * ### createDispatch\n *\n * Helper to create a typed dispatch function for an EventTarget.\n *\n * Usage:\n * ```typescript\n * class MyService extends EventTarget {\n * private dispatch = createDispatch(this);\n *\n * doSomething() {\n * this.dispatch(\"busy-changed\", { busy: true });\n * }\n * }\n * ```\n *\n * @param target - The EventTarget to dispatch events on\n * @returns A typed dispatch function\n */\nexport function CreateDispatch(target: EventTarget): DispatchFn {\n return function dispatchEvent<K extends EntityServiceEventType>(type: K, detail: EntityServiceEventMap[K]) {\n target.dispatchEvent(new CustomEvent(type, { detail }));\n };\n}\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { FieldNode, ValueStateSummary } from './FieldNode.js';
|
|
1
|
+
export { FieldNode, ValueStateSummary, type ModelEventType } from './FieldNode.js';
|
|
2
2
|
export { Registry } from './Registry.js';
|
|
3
3
|
export { ValueState } from './ValueState.js';
|
|
4
4
|
export { OPEN_MODELS_OPTIONS } from './OPEN_MODELS_OPTIONS.js';
|
|
@@ -36,13 +36,12 @@ export { FieldMask } from './well_known/FieldMask.js';
|
|
|
36
36
|
export { ARRAY } from './proxies/ARRAY.js';
|
|
37
37
|
export { MAP } from './proxies/MAP.js';
|
|
38
38
|
export { RECURSION } from './proxies/RECURSION.js';
|
|
39
|
-
export {
|
|
40
|
-
export {
|
|
41
|
-
export type { ModelEventType } from './decorators/ModelDecorators.js';
|
|
39
|
+
export { ServiceBindings } from './decorators/ServiceDecorators.js';
|
|
40
|
+
export { ModelBindings } from './decorators/ModelDecorators.js';
|
|
42
41
|
export { fieldBindings } from './decorators/FieldBindings.js';
|
|
43
42
|
export type { BindableComponent, FieldNodeLike } from './decorators/FieldBindings.js';
|
|
44
43
|
export { SchemaBuilder } from './decorators/SchemaBuilder.js';
|
|
45
|
-
export {
|
|
44
|
+
export { DefaultServiceEventHandlers, CreateDispatch } from './decorators/DefaultServiceEventHandlers.js';
|
|
46
45
|
export type { EntityServiceEventType, TypedEntityService } from './decorators/EntityServiceTypes.js';
|
|
47
46
|
export type { EntityServiceEventMap } from './decorators/EntityServiceTypes.js';
|
|
48
47
|
export interface IAny {
|
package/dist/index.js
CHANGED
|
@@ -37,9 +37,9 @@ export { ARRAY } from './proxies/ARRAY.js';
|
|
|
37
37
|
export { MAP } from './proxies/MAP.js';
|
|
38
38
|
export { RECURSION } from './proxies/RECURSION.js';
|
|
39
39
|
// Decorators
|
|
40
|
-
export {
|
|
41
|
-
export {
|
|
40
|
+
export { ServiceBindings } from './decorators/ServiceDecorators.js';
|
|
41
|
+
export { ModelBindings } from './decorators/ModelDecorators.js';
|
|
42
42
|
export { fieldBindings } from './decorators/FieldBindings.js';
|
|
43
43
|
export { SchemaBuilder } from './decorators/SchemaBuilder.js';
|
|
44
|
-
export {
|
|
44
|
+
export { DefaultServiceEventHandlers, CreateDispatch } from './decorators/DefaultServiceEventHandlers.js';
|
|
45
45
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAA0C,MAAM,aAAa,CAAC;AAChF,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAGvD,aAAa;AACb,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,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E,MAAM,eAAe,CAAC;AACpC,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAEhD,aAAa;AACb,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AACjE,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAE3D,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAE,2BAA2B,EAAE,cAAc,EAAE,MAAM,0CAA0C,CAAC","sourcesContent":["export { FieldNode, ValueStateSummary, type ModelEventType } from './FieldNode';\nexport { Registry } from './Registry';\nexport { ValueState } from './ValueState';\nexport { OPEN_MODELS_OPTIONS } from './OPEN_MODELS_OPTIONS';\nexport { ToString, ValueOf } from './CustomPrototypes';\nexport { FieldConstraints } from './FieldConstraints';\n\n// Primitives\nexport { BOOLEAN } from './primitives/BOOLEAN';\nexport { ENUM } from './primitives/ENUM';\nexport { INT32 } from './primitives/INT32';\nexport { INT64 } from './primitives/INT64';\nexport { SINT32 } from './primitives/SINT32';\nexport { SINT64 } from './primitives/SINT64';\nexport { UINT32 } from './primitives/UINT32';\nexport { UINT64 } from './primitives/UINT64';\nexport { STRING } from './primitives/STRING';\nexport { BYTES } from './primitives/BYTES';\nexport { DOUBLE } from './primitives/DOUBLE';\nexport { FLOAT } from './primitives/FLOAT';\n\n// well known\nexport { EMPTY } from './well_known/EMPTY';\nexport { ANY } from './well_known/ANY';\nexport { Int32Value } from './well_known/Int32Value';\nexport { Int64Value } from './well_known/Int64Value';\nexport { UInt32Value } from './well_known/UInt32Value';\nexport { UInt64Value } from './well_known/UInt64Value';\nexport { DoubleValue } from './well_known/DoubleValue';\nexport { FloatValue } from './well_known/FloatValue';\nexport { BoolValue } from './well_known/BoolValue';\nexport { BytesValue } from './well_known/BytesValue';\nexport { StringValue } from './well_known/StringValue';\nexport { Timestamp } from './well_known/Timestamp';\nexport { Struct } from './well_known/Struct';\n\nexport { JSONValue } from './well_known/Struct';\nexport { JSONObject } from './well_known/Struct';\nexport { Duration } from './well_known/Duration';\nexport { FieldMask } from './well_known/FieldMask';\n\n// proxies\nexport { ARRAY } from './proxies/ARRAY';\nexport { MAP } from './proxies/MAP';\nexport { RECURSION } from './proxies/RECURSION';\n\n// Decorators\nexport { ServiceBindings } from './decorators/ServiceDecorators';\nexport { ModelBindings } from './decorators/ModelDecorators';\nexport { fieldBindings } from './decorators/FieldBindings';\nexport type { BindableComponent, FieldNodeLike } from './decorators/FieldBindings';\nexport { SchemaBuilder } from './decorators/SchemaBuilder';\nexport { DefaultServiceEventHandlers, CreateDispatch } from './decorators/DefaultServiceEventHandlers';\nexport type { EntityServiceEventType, TypedEntityService } from './decorators/EntityServiceTypes';\nexport type { EntityServiceEventMap } from './decorators/EntityServiceTypes';\n\nexport interface IAny {\n '@type': string;\n [key: string]: unknown;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"url": "git+ssh://git@github.com/eclipse/eclipsefuro-web.git"
|
|
9
9
|
},
|
|
10
10
|
"author": "eclipse furo",
|
|
11
|
-
"version": "1.15.
|
|
11
|
+
"version": "1.15.2",
|
|
12
12
|
"type": "module",
|
|
13
13
|
"main": "dist/index.js",
|
|
14
14
|
"module": "dist/index.js",
|
|
@@ -45,6 +45,10 @@
|
|
|
45
45
|
"custom-elements.json",
|
|
46
46
|
"web-types.json"
|
|
47
47
|
],
|
|
48
|
+
"dependencies": {
|
|
49
|
+
"@types/json-schema": "^7.0.15",
|
|
50
|
+
"json-schema": "^0.4.0"
|
|
51
|
+
},
|
|
48
52
|
"devDependencies": {
|
|
49
53
|
"@bufbuild/buf": "^1.38.0",
|
|
50
54
|
"@bufbuild/protobuf": "^2.0.0",
|