@lwc/engine-core 8.0.0-alpha.0 → 8.0.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.
@@ -3,6 +3,6 @@
3
3
  * LWC Components. This function implements the internals of this
4
4
  * decorator.
5
5
  */
6
- export default function api(value: unknown, context: ClassMemberDecoratorContext | string | symbol): void;
6
+ export default function api(value: unknown, context: ClassMemberDecoratorContext): void;
7
7
  export declare function createPublicPropertyDescriptor(key: string): PropertyDescriptor;
8
8
  export declare function createPublicAccessorDescriptor(key: PropertyKey, descriptor: PropertyDescriptor): PropertyDescriptor;
@@ -3,5 +3,6 @@
3
3
  * LWC Components. This function can also be invoked directly
4
4
  * with any value to obtain the trackable version of the value.
5
5
  */
6
- export default function track(value: unknown, context: ClassMemberDecoratorContext | string | symbol): void;
6
+ export default function track(target: undefined, context: ClassFieldDecoratorContext): void;
7
+ export default function track<T>(target: T, context?: never): T;
7
8
  export declare function internalTrackDecorator(key: string): PropertyDescriptor;
@@ -1,4 +1,18 @@
1
- import { WireAdapterConstructor } from '../wiring';
1
+ import type { LightningElement } from '../base-lightning-element';
2
+ import type { ConfigValue, ContextValue, ReplaceReactiveValues, WireAdapterConstructor } from '../wiring';
3
+ /**
4
+ * The decorator returned by `@wire()`; not the `wire` function.
5
+ *
6
+ * For TypeScript users:
7
+ * - If you are seeing an unclear error message, ensure that both the type of the decorated prop and
8
+ * the config used match the types expected by the wire adapter.
9
+ * - String literal types in the config are resolved to the corresponding prop on the component.
10
+ * For example, a component with `id = 555` and `@wire(getBook, {id: "$id"} as const) book` will
11
+ * have `"$id"` resolve to type `number`.
12
+ */
13
+ interface WireDecorator<Value, Class> {
14
+ (target: unknown, context: ClassFieldDecoratorContext<Class, Value | undefined> | ClassMethodDecoratorContext<Class, Value extends (value: any) => any ? Value : (this: Class, value: Value) => void> | ClassGetterDecoratorContext<Class, Value | undefined> | ClassSetterDecoratorContext<Class, Value>): void;
15
+ }
2
16
  /**
3
17
  * Decorator factory to wire a property or method to a wire adapter data source.
4
18
  * @param adapter the adapter used to provision data
@@ -10,5 +24,6 @@ import { WireAdapterConstructor } from '../wiring';
10
24
  * \@wire(getBook, { id: '$bookId'}) book;
11
25
  * }
12
26
  */
13
- export default function wire(adapter: WireAdapterConstructor, config?: Record<string, any>): (value: unknown, context: ClassMemberDecoratorContext | string | symbol) => void;
27
+ export default function wire<ReactiveConfig extends ConfigValue = ConfigValue, Value = any, Context extends ContextValue = ContextValue, Class = LightningElement>(adapter: WireAdapterConstructor<ReplaceReactiveValues<ReactiveConfig, Class>, Value, Context>, config?: ReactiveConfig): WireDecorator<Value, Class>;
14
28
  export declare function internalWireFieldDecorator(key: string): PropertyDescriptor;
29
+ export {};
@@ -1,3 +1,3 @@
1
1
  export { createContextProviderWithRegister, createContextWatcher } from './context';
2
- export { ConfigCallback, ConfigValue, ContextConsumer, ContextProvider, ContextValue, DataCallback, WireAdapter, WireAdapterConstructor, WireAdapterSchemaValue, WireContextSubscriptionPayload, WireContextSubscriptionCallback, } from './types';
2
+ export { ConfigCallback, ConfigValue, ContextConsumer, ContextProvider, ContextValue, DataCallback, ReplaceReactiveValues, WireAdapter, WireAdapterConstructor, WireAdapterSchemaValue, WireContextSubscriptionPayload, WireContextSubscriptionCallback, } from './types';
3
3
  export { connectWireAdapters, disconnectWireAdapters, installWireAdapters, storeWiredFieldMeta, storeWiredMethodMeta, } from './wiring';
@@ -49,3 +49,18 @@ export interface ContextProviderOptions {
49
49
  }
50
50
  export type ContextProvider = (elmOrComponent: EventTarget, options: ContextProviderOptions) => void;
51
51
  export type RegisterContextProviderFn = (element: HostElement, adapterContextToken: string, onContextSubscription: WireContextSubscriptionCallback) => void;
52
+ /** Resolves a property chain to the corresponding value on the target type. */
53
+ type ResolveReactiveValue<
54
+ /** The object to search for properties; initially the component. */
55
+ Target,
56
+ /** A string representing a chain of of property keys, e.g. "data.user.name". */
57
+ Keys extends string> = Keys extends `${infer FirstKey}.${infer Rest}` ? FirstKey extends keyof Target ? ResolveReactiveValue<Target[FirstKey], Rest> : undefined : Keys extends keyof Target ? Target[Keys] : undefined;
58
+ /**
59
+ * Detects if the `Value` type is a property chain starting with "$". If so, it resolves the
60
+ * properties to the corresponding value on the target type.
61
+ */
62
+ type ResolveValueIfReactive<Value, Target> = Value extends string ? string extends Value ? any : Value extends `$${infer Keys}` ? ResolveReactiveValue<Target, Keys> : Value : Value;
63
+ export type ReplaceReactiveValues<Config extends ConfigValue, Component> = {
64
+ [K in keyof Config]: ResolveValueIfReactive<Config[K], Component>;
65
+ };
66
+ export {};
package/dist/index.cjs.js CHANGED
@@ -2378,7 +2378,9 @@ function createPublicAccessorDescriptor(key, descriptor) {
2378
2378
  * SPDX-License-Identifier: MIT
2379
2379
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
2380
2380
  */
2381
- function track(target) {
2381
+ function track(target,
2382
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
2383
+ context) {
2382
2384
  if (arguments.length === 1) {
2383
2385
  return getReactiveProxy(target);
2384
2386
  }
@@ -5856,6 +5858,12 @@ function getVMBeingRendered() {
5856
5858
  function setVMBeingRendered(vm) {
5857
5859
  vmBeingRendered = vm;
5858
5860
  }
5861
+ const VALID_SCOPE_TOKEN_REGEX = /^[a-zA-Z0-9\-_.]+$/;
5862
+ // See W-16614556
5863
+ // TODO [#2826]: freeze the template object
5864
+ function isValidScopeToken(token) {
5865
+ return shared.isString(token) && VALID_SCOPE_TOKEN_REGEX.test(token);
5866
+ }
5859
5867
  function validateSlots(vm) {
5860
5868
  assertNotProd(); // this method should never leak to prod
5861
5869
  const { cmpSlots } = vm;
@@ -6008,9 +6016,9 @@ function buildParseFragmentFn(createFragmentFn) {
6008
6016
  }
6009
6017
  }
6010
6018
  // See W-16614556
6011
- if ((hasStyleToken && !shared.isString(stylesheetToken)) ||
6012
- (hasLegacyToken && !shared.isString(legacyStylesheetToken))) {
6013
- throw new Error('stylesheet token must be a string');
6019
+ if ((hasStyleToken && !isValidScopeToken(stylesheetToken)) ||
6020
+ (hasLegacyToken && !isValidScopeToken(legacyStylesheetToken))) {
6021
+ throw new Error('stylesheet token must be a valid string');
6014
6022
  }
6015
6023
  // If legacy stylesheet tokens are required, then add them to the rendered string
6016
6024
  const stylesheetTokenToRender = stylesheetToken + (hasLegacyToken ? ` ${legacyStylesheetToken}` : '');
@@ -8134,5 +8142,5 @@ exports.swapTemplate = swapTemplate;
8134
8142
  exports.track = track;
8135
8143
  exports.unwrap = unwrap;
8136
8144
  exports.wire = wire;
8137
- /** version: 7.2.4 */
8145
+ /** version: 8.0.0 */
8138
8146
  //# sourceMappingURL=index.cjs.js.map