@croct/plug 0.11.4 → 0.11.6

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/component.d.ts ADDED
@@ -0,0 +1,16 @@
1
+ import { CanonicalVersionId, Version, Versioned, VersionedId } from './versioning';
2
+ export interface ComponentMap {
3
+ }
4
+ type LatestComponentVersionMap = {
5
+ [K in keyof ComponentMap]: {
6
+ latest: ComponentMap[K];
7
+ };
8
+ };
9
+ export interface VersionedComponentMap extends LatestComponentVersionMap {
10
+ }
11
+ export type ComponentId = keyof VersionedComponentMap extends never ? string : keyof VersionedComponentMap;
12
+ export type ComponentVersion<I extends ComponentId = ComponentId> = Version<VersionedComponentMap, I>;
13
+ export type ComponentVersionId<I extends ComponentId = ComponentId> = CanonicalVersionId<I, VersionedComponentMap>;
14
+ export type VersionedComponentId<I extends ComponentId = ComponentId> = VersionedId<I, VersionedComponentMap>;
15
+ export type ComponentContent<I extends VersionedComponentId> = Versioned<I, VersionedComponentMap>;
16
+ export {};
package/component.js ADDED
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=component.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"component.js","sourceRoot":"","sources":["src/component.ts"],"names":[],"mappings":""}
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.4.html";
5
+ export declare const PREVIEW_WIDGET_URL = "https://cdn.croct.io/js/v1/lib/plug/widget-0.11.6.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.4.html';
8
+ exports.PREVIEW_WIDGET_URL = 'https://cdn.croct.io/js/v1/lib/plug/widget-0.11.6.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.4",
3
+ "version": "0.11.6",
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.0",
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.2.0",
46
- "@rollup/plugin-typescript": "^10.0.0",
45
+ "@rollup/plugin-terser": "^0.3.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,6 +51,7 @@
51
51
  "jest-environment-jsdom": "^29.3.1",
52
52
  "rollup": "^3.3.0",
53
53
  "ts-jest": "^29.0.3",
54
+ "ts-node": "^10.9.1",
54
55
  "typescript": "^4.9.3"
55
56
  },
56
57
  "browserslist": [
package/slot.d.ts CHANGED
@@ -1,4 +1,6 @@
1
1
  import { JsonObject } from '@croct/json';
2
+ import { CanonicalVersionId, Version, Versioned, VersionedId } from './versioning';
3
+ import { ComponentContent, ComponentVersionId } from './component';
2
4
  export interface SlotMap {
3
5
  }
4
6
  type LatestSlotVersionMap = {
@@ -8,14 +10,38 @@ type LatestSlotVersionMap = {
8
10
  };
9
11
  export interface VersionedSlotMap extends LatestSlotVersionMap {
10
12
  }
11
- type LatestAlias = 'latest';
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 DiscriminatedSlotMap = {
25
+ [K in keyof VersionedSlotMap]: {
26
+ [V in keyof VersionedSlotMap[K]]: Intersection<VersionedSlotMap[K][V], {
27
+ _component: string | null;
28
+ }>;
29
+ };
30
+ };
31
+ type UnionContent = {
32
+ [K in ComponentVersionId]: Intersection<ComponentContent<K>, {
33
+ _component: K;
34
+ }>;
35
+ };
36
+ type UnknownContent = UnionContent[ComponentVersionId] extends never ? (JsonObject & {
37
+ _component: string | null;
38
+ }) : UnionContent[ComponentVersionId];
39
+ type VersionedContent<I extends VersionedSlotId> = Versioned<I, DiscriminatedSlotMap, UnknownContent>;
40
+ export type DynamicSlotId = any;
12
41
  export type SlotId = keyof VersionedSlotMap extends never ? string : keyof VersionedSlotMap;
13
- export type SlotVersion<I extends SlotId = SlotId> = LatestAlias | (I extends keyof VersionedSlotMap ? keyof VersionedSlotMap[I] : never);
14
- export type VersionedSlotId<I extends SlotId = SlotId> = I | {
15
- [K in SlotId]: `${K}@${SlotVersion<K> & string}`;
16
- }[I];
17
- type VersionedSlotContent<I extends SlotId, V extends string = LatestAlias, C extends JsonObject = JsonObject> = I extends keyof VersionedSlotMap ? (V extends keyof VersionedSlotMap[I] ? VersionedSlotMap[I][V] : C) : C;
18
- export type ExtractSlotVersion<I extends string> = I extends `${string}@${infer V}` ? (LatestAlias extends V ? LatestAlias : (V extends `${number}` ? V : never)) : LatestAlias;
19
- export type ExtractSlotId<I extends string> = I extends `${infer V}@${string}` ? V : I;
20
- export type SlotContent<I extends VersionedSlotId, C extends JsonObject = JsonObject> = VersionedSlotContent<ExtractSlotId<I>, ExtractSlotVersion<I>, C>;
42
+ export type SlotVersion<I extends SlotId = SlotId> = Version<VersionedSlotMap, I>;
43
+ export type SlotVersionId<I extends SlotId = SlotId> = CanonicalVersionId<I, VersionedSlotMap>;
44
+ export type VersionedSlotId<I extends SlotId = SlotId> = VersionedId<I, VersionedSlotMap>;
45
+ export type CompatibleSlotContent<T extends ComponentVersionId = ComponentVersionId> = UnionContent[T];
46
+ export type SlotContent<I extends VersionedSlotId = VersionedSlotId, C extends JsonObject = JsonObject> = JsonObject extends C ? (string extends I ? UnknownContent : VersionedContent<I>) : C;
21
47
  export {};
@@ -0,0 +1,19 @@
1
+ import {CanonicalVersionId, Version, Versioned, VersionedId} from './versioning';
2
+
3
+ export interface ComponentMap {
4
+ }
5
+
6
+ type LatestComponentVersionMap = {[K in keyof ComponentMap]: {latest: ComponentMap[K]}};
7
+
8
+ export interface VersionedComponentMap extends LatestComponentVersionMap {
9
+ }
10
+
11
+ export type ComponentId = keyof VersionedComponentMap extends never ? string : keyof VersionedComponentMap;
12
+
13
+ export type ComponentVersion<I extends ComponentId = ComponentId> = Version<VersionedComponentMap, I>;
14
+
15
+ export type ComponentVersionId<I extends ComponentId = ComponentId> = CanonicalVersionId<I, VersionedComponentMap>;
16
+
17
+ export type VersionedComponentId<I extends ComponentId = ComponentId> = VersionedId<I, VersionedComponentMap>;
18
+
19
+ export type ComponentContent<I extends VersionedComponentId> = Versioned<I, VersionedComponentMap>;
package/src/slot.ts CHANGED
@@ -1,4 +1,6 @@
1
1
  import {JsonObject} from '@croct/json';
2
+ import {CanonicalVersionId, Version, Versioned, VersionedId} from './versioning';
3
+ import {ComponentContent, ComponentVersionId} from './component';
2
4
 
3
5
  export interface SlotMap {
4
6
  }
@@ -8,30 +10,45 @@ type LatestSlotVersionMap = {[K in keyof SlotMap]: {latest: SlotMap[K]}};
8
10
  export interface VersionedSlotMap extends LatestSlotVersionMap {
9
11
  }
10
12
 
11
- type LatestAlias = 'latest';
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;
12
24
 
13
- export type SlotId = keyof VersionedSlotMap extends never ? string : keyof VersionedSlotMap;
25
+ type DiscriminatedSlotMap = {
26
+ [K in keyof VersionedSlotMap]: {
27
+ [V in keyof VersionedSlotMap[K]]: Intersection<VersionedSlotMap[K][V], {_component: string | null}>
28
+ }
29
+ };
30
+
31
+ type UnionContent = {
32
+ [K in ComponentVersionId]: Intersection<ComponentContent<K>, {_component: K}>;
33
+ };
34
+
35
+ type UnknownContent = UnionContent[ComponentVersionId] extends never
36
+ ? (JsonObject & {_component: string | null})
37
+ : UnionContent[ComponentVersionId];
14
38
 
15
- export type SlotVersion<I extends SlotId = SlotId> = LatestAlias | (
16
- I extends keyof VersionedSlotMap
17
- ? keyof VersionedSlotMap[I]
18
- : never
19
- );
39
+ type VersionedContent<I extends VersionedSlotId> = Versioned<I, DiscriminatedSlotMap, UnknownContent>;
40
+
41
+ export type DynamicSlotId = any;
42
+
43
+ export type SlotId = keyof VersionedSlotMap extends never ? string : keyof VersionedSlotMap;
20
44
 
21
- export type VersionedSlotId<I extends SlotId = SlotId> = I | {[K in SlotId]: `${K}@${SlotVersion<K> & string}`}[I];
45
+ export type SlotVersion<I extends SlotId = SlotId> = Version<VersionedSlotMap, I>;
22
46
 
23
- type VersionedSlotContent<I extends SlotId, V extends string = LatestAlias, C extends JsonObject = JsonObject> =
24
- I extends keyof VersionedSlotMap
25
- ? (V extends keyof VersionedSlotMap[I]
26
- ? VersionedSlotMap[I][V]
27
- : C)
28
- : C;
47
+ export type SlotVersionId<I extends SlotId = SlotId> = CanonicalVersionId<I, VersionedSlotMap>;
29
48
 
30
- export type ExtractSlotVersion<I extends string> = I extends `${string}@${infer V}`
31
- ? (LatestAlias extends V ? LatestAlias : (V extends `${number}` ? V : never))
32
- : LatestAlias;
49
+ export type VersionedSlotId<I extends SlotId = SlotId> = VersionedId<I, VersionedSlotMap>;
33
50
 
34
- export type ExtractSlotId<I extends string> = I extends `${infer V}@${string}` ? V : I;
51
+ export type CompatibleSlotContent<T extends ComponentVersionId = ComponentVersionId> = UnionContent[T];
35
52
 
36
- export type SlotContent<I extends VersionedSlotId, C extends JsonObject = JsonObject> =
37
- VersionedSlotContent<ExtractSlotId<I>, ExtractSlotVersion<I>, C>;
53
+ export type SlotContent<I extends VersionedSlotId = VersionedSlotId, C extends JsonObject = JsonObject> =
54
+ JsonObject extends C ? (string extends I ? UnknownContent : VersionedContent<I>) : C;
@@ -0,0 +1,29 @@
1
+ import {JsonObject} from '@croct/json';
2
+
3
+ export type LatestAlias = 'latest';
4
+
5
+ export type ExtractVersion<I extends string> = I extends `${string}@${infer V}`
6
+ ? (LatestAlias extends V ? LatestAlias : (V extends `${number}` ? V : never))
7
+ : LatestAlias;
8
+
9
+ export type CanonicalVersionId<I extends string, M> = {
10
+ [K in I]: `${K}@${Extract<Version<M, K>, `${number}`>}`
11
+ }[I];
12
+
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;
17
+
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>;
21
+
22
+ export type Version<M, I extends string> = LatestAlias | (I extends keyof M ? keyof M[I] : never);
23
+
24
+ export type Versioned<I extends string, M, C extends JsonObject = JsonObject> =
25
+ ExtractId<I> extends keyof M
26
+ ? ExtractVersion<I> extends keyof M[ExtractId<I>]
27
+ ? M[ExtractId<I>][ExtractVersion<I>]
28
+ : C
29
+ : C;
@@ -0,0 +1,17 @@
1
+ import { JsonObject } from '@croct/json';
2
+ export type LatestAlias = 'latest';
3
+ export type ExtractVersion<I extends string> = I extends `${string}@${infer V}` ? (LatestAlias extends V ? LatestAlias : (V extends `${number}` ? V : never)) : LatestAlias;
4
+ export type CanonicalVersionId<I extends string, M> = {
5
+ [K in I]: `${K}@${Extract<Version<M, K>, `${number}`>}`;
6
+ }[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> | {
12
+ [K in I]: `${K}@${Version<M, K> & string}`;
13
+ }[I];
14
+ export type ExtractId<I extends string> = I extends `${infer V}@${string}` ? V : CastString<I>;
15
+ export type Version<M, I extends string> = LatestAlias | (I extends keyof M ? keyof M[I] : never);
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 {};
package/versioning.js ADDED
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=versioning.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"versioning.js","sourceRoot":"","sources":["src/versioning.ts"],"names":[],"mappings":""}