@croct/plug 0.11.5 → 0.12.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/constants.d.ts CHANGED
@@ -2,4 +2,4 @@ export declare const CDN_URL = "https://cdn.croct.io/js/v1/lib/plug.js";
2
2
  export declare const PLAYGROUND_ORIGIN = "https://play.croct.com";
3
3
  export declare const PLAYGROUND_CONNECT_URL = "https://play.croct.com/connect.html";
4
4
  export declare const PREVIEW_WIDGET_ORIGIN = "https://cdn.croct.io";
5
- export declare const PREVIEW_WIDGET_URL = "https://cdn.croct.io/js/v1/lib/plug/widget-0.11.5.html";
5
+ export declare const PREVIEW_WIDGET_URL = "https://cdn.croct.io/js/v1/lib/plug/widget-0.12.0.html";
package/constants.js CHANGED
@@ -5,5 +5,5 @@ exports.CDN_URL = 'https://cdn.croct.io/js/v1/lib/plug.js';
5
5
  exports.PLAYGROUND_ORIGIN = 'https://play.croct.com';
6
6
  exports.PLAYGROUND_CONNECT_URL = 'https://play.croct.com/connect.html';
7
7
  exports.PREVIEW_WIDGET_ORIGIN = 'https://cdn.croct.io';
8
- exports.PREVIEW_WIDGET_URL = 'https://cdn.croct.io/js/v1/lib/plug/widget-0.11.5.html';
8
+ exports.PREVIEW_WIDGET_URL = 'https://cdn.croct.io/js/v1/lib/plug/widget-0.12.0.html';
9
9
  //# sourceMappingURL=constants.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@croct/plug",
3
- "version": "0.11.5",
3
+ "version": "0.12.0",
4
4
  "description": "A fully-featured devkit for building natively personalized applications.",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -33,8 +33,8 @@
33
33
  "bundle": "rollup -c"
34
34
  },
35
35
  "dependencies": {
36
- "@croct/json": "^1.1.0",
37
- "@croct/sdk": "^0.12.2",
36
+ "@croct/json": "^2.0.1",
37
+ "@croct/sdk": "^0.12.3",
38
38
  "tslib": "^2.2.0"
39
39
  },
40
40
  "devDependencies": {
@@ -42,8 +42,8 @@
42
42
  "@rollup/plugin-commonjs": "^24.0.0",
43
43
  "@rollup/plugin-node-resolve": "^15.0.1",
44
44
  "@rollup/plugin-replace": "^5.0.1",
45
- "@rollup/plugin-terser": "^0.3.0",
46
- "@rollup/plugin-typescript": "^10.0.0",
45
+ "@rollup/plugin-terser": "^0.4.0",
46
+ "@rollup/plugin-typescript": "^11.0.0",
47
47
  "@types/jest": "^29.2.2",
48
48
  "@typescript-eslint/parser": "^5.30.0",
49
49
  "eslint": "^8.27.0",
@@ -51,7 +51,8 @@
51
51
  "jest-environment-jsdom": "^29.3.1",
52
52
  "rollup": "^3.3.0",
53
53
  "ts-jest": "^29.0.3",
54
- "typescript": "^4.9.3"
54
+ "ts-node": "^10.9.1",
55
+ "typescript": "^4.9.5"
55
56
  },
56
57
  "browserslist": [
57
58
  "last 1 version"
package/slot.d.ts CHANGED
@@ -10,21 +10,31 @@ type LatestSlotVersionMap = {
10
10
  };
11
11
  export interface VersionedSlotMap extends LatestSlotVersionMap {
12
12
  }
13
+ /**
14
+ * Creates an intersection of the given types distributing over unions.
15
+ *
16
+ * The difference between this type and the built-in `&` operator is that the
17
+ * `&` operator creates an intersection of the union members instead of
18
+ * creating a union of the intersection members. For example, given the types
19
+ * `Left = A | B` and `Right = C`, the type `Left & Right` expands to
20
+ * `(A | B) & C`, but `Merge<Left, Right>` expands to `A & C | B & C`,
21
+ * which improves type inference when narrowing the type.
22
+ */
23
+ type Intersection<T, E> = T extends infer O ? O & E : never;
24
+ type UnionContent = {
25
+ [K in ComponentVersionId]: Intersection<ComponentContent<K>, {
26
+ _component: K | null;
27
+ }>;
28
+ };
29
+ type UnknownContent = UnionContent[ComponentVersionId] extends never ? (JsonObject & {
30
+ _component: string | null;
31
+ }) : UnionContent[ComponentVersionId];
32
+ type VersionedContent<I extends VersionedSlotId> = Versioned<I, VersionedSlotMap, UnknownContent>;
33
+ export type DynamicSlotId = any;
13
34
  export type SlotId = keyof VersionedSlotMap extends never ? string : keyof VersionedSlotMap;
14
35
  export type SlotVersion<I extends SlotId = SlotId> = Version<VersionedSlotMap, I>;
15
36
  export type SlotVersionId<I extends SlotId = SlotId> = CanonicalVersionId<I, VersionedSlotMap>;
16
37
  export type VersionedSlotId<I extends SlotId = SlotId> = VersionedId<I, VersionedSlotMap>;
17
- export type DynamicSlotId = any;
18
- type DiscriminatedContent<T = Record<never, never>, I extends string | null = null> = T & {
19
- _component: I;
20
- };
21
- type DiscriminatedComponentMap = {
22
- [K in ComponentVersionId]: DiscriminatedContent<ComponentContent<K>, K>;
23
- };
24
- export type CompatibleSlotContent<T extends ComponentVersionId = ComponentVersionId> = DiscriminatedComponentMap[T];
25
- type UnionContent = {
26
- [I in ComponentVersionId]: DiscriminatedComponentMap[I];
27
- }[ComponentVersionId];
28
- type UnknownContent = UnionContent extends never ? JsonObject : UnionContent | DiscriminatedContent;
29
- export type SlotContent<I extends VersionedSlotId = VersionedSlotId, C extends JsonObject = JsonObject> = JsonObject extends C ? string extends I ? UnknownContent : DiscriminatedContent<Versioned<I, VersionedSlotMap, UnknownContent>, string> : C;
38
+ export type CompatibleSlotContent<T extends ComponentVersionId = ComponentVersionId> = UnionContent[T];
39
+ export type SlotContent<I extends VersionedSlotId = VersionedSlotId, C extends JsonObject = JsonObject> = JsonObject extends C ? (string extends I ? UnknownContent : VersionedContent<I>) : C;
30
40
  export {};
package/src/slot.ts CHANGED
@@ -10,32 +10,39 @@ type LatestSlotVersionMap = {[K in keyof SlotMap]: {latest: SlotMap[K]}};
10
10
  export interface VersionedSlotMap extends LatestSlotVersionMap {
11
11
  }
12
12
 
13
- export type SlotId = keyof VersionedSlotMap extends never ? string : keyof VersionedSlotMap;
14
-
15
- export type SlotVersion<I extends SlotId = SlotId> = Version<VersionedSlotMap, I>;
13
+ /**
14
+ * Creates an intersection of the given types distributing over unions.
15
+ *
16
+ * The difference between this type and the built-in `&` operator is that the
17
+ * `&` operator creates an intersection of the union members instead of
18
+ * creating a union of the intersection members. For example, given the types
19
+ * `Left = A | B` and `Right = C`, the type `Left & Right` expands to
20
+ * `(A | B) & C`, but `Merge<Left, Right>` expands to `A & C | B & C`,
21
+ * which improves type inference when narrowing the type.
22
+ */
23
+ type Intersection<T, E> = T extends infer O ? O & E : never;
24
+
25
+ type UnionContent = {
26
+ [K in ComponentVersionId]: Intersection<ComponentContent<K>, {_component: K | null}>;
27
+ };
16
28
 
17
- export type SlotVersionId<I extends SlotId = SlotId> = CanonicalVersionId<I, VersionedSlotMap>;
29
+ type UnknownContent = UnionContent[ComponentVersionId] extends never
30
+ ? (JsonObject & {_component: string | null})
31
+ : UnionContent[ComponentVersionId];
18
32
 
19
- export type VersionedSlotId<I extends SlotId = SlotId> = VersionedId<I, VersionedSlotMap>;
33
+ type VersionedContent<I extends VersionedSlotId> = Versioned<I, VersionedSlotMap, UnknownContent>;
20
34
 
21
35
  export type DynamicSlotId = any;
22
36
 
23
- type DiscriminatedContent<T = Record<never, never>, I extends string|null = null> = T & {_component: I};
37
+ export type SlotId = keyof VersionedSlotMap extends never ? string : keyof VersionedSlotMap;
24
38
 
25
- type DiscriminatedComponentMap = {
26
- [K in ComponentVersionId]: DiscriminatedContent<ComponentContent<K>, K>;
27
- };
39
+ export type SlotVersion<I extends SlotId = SlotId> = Version<VersionedSlotMap, I>;
28
40
 
29
- export type CompatibleSlotContent<T extends ComponentVersionId = ComponentVersionId> =
30
- DiscriminatedComponentMap[T];
41
+ export type SlotVersionId<I extends SlotId = SlotId> = CanonicalVersionId<I, VersionedSlotMap>;
31
42
 
32
- type UnionContent = {[I in ComponentVersionId]: DiscriminatedComponentMap[I]}[ComponentVersionId];
43
+ export type VersionedSlotId<I extends SlotId = SlotId> = VersionedId<I, VersionedSlotMap>;
33
44
 
34
- type UnknownContent = UnionContent extends never ? JsonObject : UnionContent | DiscriminatedContent;
45
+ export type CompatibleSlotContent<T extends ComponentVersionId = ComponentVersionId> = UnionContent[T];
35
46
 
36
47
  export type SlotContent<I extends VersionedSlotId = VersionedSlotId, C extends JsonObject = JsonObject> =
37
- JsonObject extends C
38
- ? string extends I
39
- ? UnknownContent
40
- : DiscriminatedContent<Versioned<I, VersionedSlotMap, UnknownContent>, string>
41
- : C;
48
+ JsonObject extends C ? (string extends I ? UnknownContent : VersionedContent<I>) : C;
package/src/versioning.ts CHANGED
@@ -10,9 +10,14 @@ export type CanonicalVersionId<I extends string, M> = {
10
10
  [K in I]: `${K}@${Extract<Version<M, K>, `${number}`>}`
11
11
  }[I];
12
12
 
13
- export type VersionedId<I extends string, M> = I | {[K in I]: `${K}@${Version<M, K> & string}`}[I];
13
+ /**
14
+ * Utility type that coerces any type to a string if it is not a string literal.
15
+ */
16
+ type CastString<T extends string> = T extends `${infer V}` ? V : string;
14
17
 
15
- export type ExtractId<I extends string> = I extends `${infer V}@${string}` ? V : I;
18
+ export type VersionedId<I extends string, M> = CastString<I> | {[K in I]: `${K}@${Version<M, K> & string}`}[I];
19
+
20
+ export type ExtractId<I extends string> = I extends `${infer V}@${string}` ? V : CastString<I>;
16
21
 
17
22
  export type Version<M, I extends string> = LatestAlias | (I extends keyof M ? keyof M[I] : never);
18
23
 
package/versioning.d.ts CHANGED
@@ -4,9 +4,14 @@ export type ExtractVersion<I extends string> = I extends `${string}@${infer V}`
4
4
  export type CanonicalVersionId<I extends string, M> = {
5
5
  [K in I]: `${K}@${Extract<Version<M, K>, `${number}`>}`;
6
6
  }[I];
7
- export type VersionedId<I extends string, M> = I | {
7
+ /**
8
+ * Utility type that coerces any type to a string if it is not a string literal.
9
+ */
10
+ type CastString<T extends string> = T extends `${infer V}` ? V : string;
11
+ export type VersionedId<I extends string, M> = CastString<I> | {
8
12
  [K in I]: `${K}@${Version<M, K> & string}`;
9
13
  }[I];
10
- export type ExtractId<I extends string> = I extends `${infer V}@${string}` ? V : I;
14
+ export type ExtractId<I extends string> = I extends `${infer V}@${string}` ? V : CastString<I>;
11
15
  export type Version<M, I extends string> = LatestAlias | (I extends keyof M ? keyof M[I] : never);
12
16
  export type Versioned<I extends string, M, C extends JsonObject = JsonObject> = ExtractId<I> extends keyof M ? ExtractVersion<I> extends keyof M[ExtractId<I>] ? M[ExtractId<I>][ExtractVersion<I>] : C : C;
17
+ export {};