@media-quest/engine 0.0.22 → 0.0.23

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.
Files changed (51) hide show
  1. package/package.json +1 -1
  2. package/src/Delement/DElement.dto.ts +5 -5
  3. package/src/Delement/DElement.ts +88 -88
  4. package/src/Delement/DImg.ts +39 -39
  5. package/src/Delement/DStyle-utils.ts +616 -616
  6. package/src/Delement/DStyle.ts +165 -165
  7. package/src/Delement/DText.ts +13 -13
  8. package/src/Delement/Ddiv.ts +25 -25
  9. package/src/Delement/button-click-action.ts +35 -35
  10. package/src/Delement/css.spec.ts +36 -36
  11. package/src/Delement/css.ts +46 -46
  12. package/src/Delement/element-factory.ts +40 -40
  13. package/src/common/DMaybe.ts +46 -46
  14. package/src/common/DTimestamp.ts +20 -20
  15. package/src/common/DTmestamp.spec.ts +11 -11
  16. package/src/common/result.ts +41 -41
  17. package/src/engine/SchemaDto.ts +24 -24
  18. package/src/engine/SchemaEngine.ts +150 -150
  19. package/src/engine/SchemaResult.ts +10 -10
  20. package/src/engine/dplayer.spec.ts +91 -91
  21. package/src/engine/dplayer.ts +104 -104
  22. package/src/engine/history-que.spec.ts +67 -67
  23. package/src/engine/history-que.ts +17 -17
  24. package/src/engine/next-que.spec.ts +121 -121
  25. package/src/engine/next-que.ts +101 -101
  26. package/src/engine/page-que-ruleengine-action.ts +6 -6
  27. package/src/engine/scale.spec.ts +38 -38
  28. package/src/engine/scale.ts +70 -70
  29. package/src/events/mq-events.ts +63 -63
  30. package/src/page/Page.ts +182 -182
  31. package/src/page/media-player.ts +117 -117
  32. package/src/page/page-component.ts +113 -113
  33. package/src/page/page-result.ts +11 -11
  34. package/src/page/task-manager.ts +240 -240
  35. package/src/page/task-state.ts +55 -55
  36. package/src/page/task.ts +90 -90
  37. package/src/public-api.ts +26 -26
  38. package/src/rules/__test__/complex-condition.spec.ts +15 -15
  39. package/src/rules/__test__/conditon.spec.ts +124 -124
  40. package/src/rules/__test__/numeric-condition.spec.ts +84 -84
  41. package/src/rules/__test__/rule-engine.spec.ts +348 -348
  42. package/src/rules/__test__/rule-evaluation.spec.ts +140 -140
  43. package/src/rules/__test__/string-condition.spec.ts +41 -41
  44. package/src/rules/condition.ts +191 -191
  45. package/src/rules/fact.ts +18 -18
  46. package/src/rules/rule-engine.ts +45 -45
  47. package/src/rules/rule.ts +40 -40
  48. package/src/utils/DUtil.ts +116 -116
  49. package/src/utils/ID.spec.ts +39 -39
  50. package/src/utils/ID.ts +73 -73
  51. package/tsconfig.json +19 -19
@@ -1,116 +1,116 @@
1
- export type RandomObjectId = string & { randomObjectId: true };
2
- export namespace DUtil {
3
- export const randomString = (length: number): string => {
4
- const letters = "abcdefghijklmnopqrstuvxyz";
5
- const uppercase = letters.toUpperCase();
6
- const all = letters + uppercase;
7
- const abs = Math.abs(length);
8
- let result = "";
9
-
10
- for (let i = 0; i < abs; i++) {
11
- const char = all.charAt(Math.floor(Math.random() * all.length));
12
- result += char;
13
- }
14
- return result;
15
- };
16
-
17
- export const randomObjectId = () => randomString(32) as RandomObjectId;
18
-
19
- export const deleteProp = <Obj, Key extends keyof Obj>(obj: Obj, key: Key): Omit<Obj, Key> => {
20
- delete obj[key];
21
- return obj;
22
- };
23
-
24
- export const isInRange = (min: number, max: number) => {
25
- return (value: number) => value >= min && value <= max;
26
- };
27
- export const isInfinity = (number: number) => {
28
- return (
29
- number === Number.POSITIVE_INFINITY ||
30
- number === Number.NEGATIVE_INFINITY ||
31
- number === Infinity
32
- );
33
- };
34
- export type NonEmptyArray<T> = [T, ...T[]];
35
- export const isNonEmptyArray = <T>(array: Array<T>): array is NonEmptyArray<T> => {
36
- return array.length > 0;
37
- };
38
-
39
- export const neverCheck = (args: never) => {
40
- console.log("OOPS: This value slipped through the never-check", args);
41
- };
42
-
43
- export const isString = (str: unknown): str is string => typeof str === "string";
44
-
45
- export const hasKey = <T extends string>(
46
- obj: unknown,
47
- key: T,
48
- ): obj is Record<typeof key, unknown> => {
49
- if (!isRecord(obj)) {
50
- return false;
51
- }
52
- return Object.prototype.hasOwnProperty.call(obj, key);
53
- };
54
-
55
- export const isRecord = (obj: unknown): obj is Record<string, unknown> => {
56
- if (!obj) {
57
- return false;
58
- }
59
-
60
- if (Array.isArray(obj)) {
61
- return false;
62
- }
63
-
64
- if (typeof obj !== "object") {
65
- return false;
66
- }
67
-
68
- if (obj === null) {
69
- return false;
70
- }
71
- return true;
72
- };
73
-
74
- export const isBool = (obj?: boolean): obj is boolean => typeof obj === "boolean";
75
-
76
- export const isTrue = (bool?: boolean): bool is true => bool === true;
77
-
78
- export const isFalse = (bool?: boolean): bool is false => bool === false;
79
-
80
- export const isDefined = (obj: unknown): boolean => {
81
- const notNull = obj !== null;
82
- const notUndefined = obj !== undefined;
83
- return notNull && notUndefined;
84
- };
85
-
86
- export const hasKind = (obj: unknown): obj is { readonly kind: string } => {
87
- if (!hasKey(obj, "kind")) {
88
- return false;
89
- }
90
- if (typeof obj.kind !== "string") {
91
- return false;
92
- }
93
- return obj.kind.length > 0;
94
- };
95
-
96
- export const hasValue = (obj: unknown): obj is { value: unknown } => {
97
- return hasKey(obj, "value");
98
- };
99
- export const isNumber = (value?: number): value is number => {
100
- const isNumber = typeof value === "number";
101
- const notNaN = !Number.isNaN(value);
102
- return isNumber && notNaN;
103
- };
104
-
105
- export const maxFn = (upperLimit: number) => {
106
- return (value: number) => {
107
- return Math.min(value, upperLimit);
108
- };
109
- };
110
-
111
- export const minFn = (lowerLimit: number) => {
112
- return (value: number) => {
113
- return Math.min(value, lowerLimit);
114
- };
115
- };
116
- }
1
+ export type RandomObjectId = string & { randomObjectId: true };
2
+ export namespace DUtil {
3
+ export const randomString = (length: number): string => {
4
+ const letters = "abcdefghijklmnopqrstuvxyz";
5
+ const uppercase = letters.toUpperCase();
6
+ const all = letters + uppercase;
7
+ const abs = Math.abs(length);
8
+ let result = "";
9
+
10
+ for (let i = 0; i < abs; i++) {
11
+ const char = all.charAt(Math.floor(Math.random() * all.length));
12
+ result += char;
13
+ }
14
+ return result;
15
+ };
16
+
17
+ export const randomObjectId = () => randomString(32) as RandomObjectId;
18
+
19
+ export const deleteProp = <Obj, Key extends keyof Obj>(obj: Obj, key: Key): Omit<Obj, Key> => {
20
+ delete obj[key];
21
+ return obj;
22
+ };
23
+
24
+ export const isInRange = (min: number, max: number) => {
25
+ return (value: number) => value >= min && value <= max;
26
+ };
27
+ export const isInfinity = (number: number) => {
28
+ return (
29
+ number === Number.POSITIVE_INFINITY ||
30
+ number === Number.NEGATIVE_INFINITY ||
31
+ number === Infinity
32
+ );
33
+ };
34
+ export type NonEmptyArray<T> = [T, ...T[]];
35
+ export const isNonEmptyArray = <T>(array: Array<T>): array is NonEmptyArray<T> => {
36
+ return array.length > 0;
37
+ };
38
+
39
+ export const neverCheck = (args: never) => {
40
+ console.log("OOPS: This value slipped through the never-check", args);
41
+ };
42
+
43
+ export const isString = (str: unknown): str is string => typeof str === "string";
44
+
45
+ export const hasKey = <T extends string>(
46
+ obj: unknown,
47
+ key: T,
48
+ ): obj is Record<typeof key, unknown> => {
49
+ if (!isRecord(obj)) {
50
+ return false;
51
+ }
52
+ return Object.prototype.hasOwnProperty.call(obj, key);
53
+ };
54
+
55
+ export const isRecord = (obj: unknown): obj is Record<string, unknown> => {
56
+ if (!obj) {
57
+ return false;
58
+ }
59
+
60
+ if (Array.isArray(obj)) {
61
+ return false;
62
+ }
63
+
64
+ if (typeof obj !== "object") {
65
+ return false;
66
+ }
67
+
68
+ if (obj === null) {
69
+ return false;
70
+ }
71
+ return true;
72
+ };
73
+
74
+ export const isBool = (obj?: boolean): obj is boolean => typeof obj === "boolean";
75
+
76
+ export const isTrue = (bool?: boolean): bool is true => bool === true;
77
+
78
+ export const isFalse = (bool?: boolean): bool is false => bool === false;
79
+
80
+ export const isDefined = (obj: unknown): boolean => {
81
+ const notNull = obj !== null;
82
+ const notUndefined = obj !== undefined;
83
+ return notNull && notUndefined;
84
+ };
85
+
86
+ export const hasKind = (obj: unknown): obj is { readonly kind: string } => {
87
+ if (!hasKey(obj, "kind")) {
88
+ return false;
89
+ }
90
+ if (typeof obj.kind !== "string") {
91
+ return false;
92
+ }
93
+ return obj.kind.length > 0;
94
+ };
95
+
96
+ export const hasValue = (obj: unknown): obj is { value: unknown } => {
97
+ return hasKey(obj, "value");
98
+ };
99
+ export const isNumber = (value?: number): value is number => {
100
+ const isNumber = typeof value === "number";
101
+ const notNaN = !Number.isNaN(value);
102
+ return isNumber && notNaN;
103
+ };
104
+
105
+ export const maxFn = (upperLimit: number) => {
106
+ return (value: number) => {
107
+ return Math.min(value, upperLimit);
108
+ };
109
+ };
110
+
111
+ export const minFn = (lowerLimit: number) => {
112
+ return (value: number) => {
113
+ return Math.min(value, lowerLimit);
114
+ };
115
+ };
116
+ }
@@ -1,39 +1,39 @@
1
- import { PageID, SchemaID } from "./ID";
2
-
3
- describe("ID Functions work", () => {
4
- //Generate test for schema prefix
5
- test("SCHEMA_ID isFunction works", () => {
6
- const id = SchemaID.create();
7
- expect(SchemaID.is(id)).toBe(true);
8
- expect(SchemaID.is("")).toBe(false);
9
- expect(SchemaID.is("a")).toBe(false);
10
- expect(SchemaID.is("a".repeat(10))).toBe(true);
11
- expect(SchemaID.is("a".repeat(9))).toBe(false);
12
- });
13
- test("SCHEMA_ID ensure works", () => {
14
- const id = SchemaID.create();
15
- expect(SchemaID.ensure(id)).toBe(id);
16
- expect(SchemaID.ensure("")).not.toBe("");
17
- expect(SchemaID.ensure("")).not.toBe("a");
18
- expect(SchemaID.ensure("a".repeat(10))).toBe("a".repeat(10));
19
- expect(SchemaID.ensure("a".repeat(9))).not.toBe("a".repeat(9));
20
- expect(SchemaID.ensure("ABcdefghigKLML")).toBe("ABcdefghigKLML");
21
- });
22
- test("PageID isFunction works", () => {
23
- const id = PageID.create();
24
- expect(PageID.is(id)).toBe(true);
25
- expect(PageID.is("")).toBe(false);
26
- expect(PageID.is("a")).toBe(false);
27
- expect(PageID.is("a".repeat(10))).toBe(true);
28
- expect(PageID.is("a".repeat(9))).toBe(false);
29
- });
30
- test("PageID ensure works", () => {
31
- const id = PageID.create();
32
- expect(PageID.ensure(id)).toBe(id);
33
- expect(PageID.ensure("")).not.toBe("");
34
- expect(PageID.ensure("")).not.toBe("a");
35
- expect(PageID.ensure("a".repeat(10))).toBe("a".repeat(10));
36
- expect(PageID.ensure("a".repeat(9))).not.toBe("a".repeat(9));
37
- expect(PageID.ensure("ABcdefghigKLML")).toBe("ABcdefghigKLML");
38
- });
39
- });
1
+ import { PageID, SchemaID } from "./ID";
2
+
3
+ describe("ID Functions work", () => {
4
+ //Generate test for schema prefix
5
+ test("SCHEMA_ID isFunction works", () => {
6
+ const id = SchemaID.create();
7
+ expect(SchemaID.is(id)).toBe(true);
8
+ expect(SchemaID.is("")).toBe(false);
9
+ expect(SchemaID.is("a")).toBe(false);
10
+ expect(SchemaID.is("a".repeat(10))).toBe(true);
11
+ expect(SchemaID.is("a".repeat(9))).toBe(false);
12
+ });
13
+ test("SCHEMA_ID ensure works", () => {
14
+ const id = SchemaID.create();
15
+ expect(SchemaID.ensure(id)).toBe(id);
16
+ expect(SchemaID.ensure("")).not.toBe("");
17
+ expect(SchemaID.ensure("")).not.toBe("a");
18
+ expect(SchemaID.ensure("a".repeat(10))).toBe("a".repeat(10));
19
+ expect(SchemaID.ensure("a".repeat(9))).not.toBe("a".repeat(9));
20
+ expect(SchemaID.ensure("ABcdefghigKLML")).toBe("ABcdefghigKLML");
21
+ });
22
+ test("PageID isFunction works", () => {
23
+ const id = PageID.create();
24
+ expect(PageID.is(id)).toBe(true);
25
+ expect(PageID.is("")).toBe(false);
26
+ expect(PageID.is("a")).toBe(false);
27
+ expect(PageID.is("a".repeat(10))).toBe(true);
28
+ expect(PageID.is("a".repeat(9))).toBe(false);
29
+ });
30
+ test("PageID ensure works", () => {
31
+ const id = PageID.create();
32
+ expect(PageID.ensure(id)).toBe(id);
33
+ expect(PageID.ensure("")).not.toBe("");
34
+ expect(PageID.ensure("")).not.toBe("a");
35
+ expect(PageID.ensure("a".repeat(10))).toBe("a".repeat(10));
36
+ expect(PageID.ensure("a".repeat(9))).not.toBe("a".repeat(9));
37
+ expect(PageID.ensure("ABcdefghigKLML")).toBe("ABcdefghigKLML");
38
+ });
39
+ });
package/src/utils/ID.ts CHANGED
@@ -1,73 +1,73 @@
1
- // The default length of an ID
2
- const ID_LENGTH = 32;
3
-
4
- // The minimum length of an ID
5
- const MIN_LENGTH = 10;
6
-
7
- // const SPLITTER = "_";
8
-
9
- export type ID<B extends string> = string & { __ID__: B };
10
-
11
- const isID = <const B extends string>(idName: B, id?: string): id is ID<B> => {
12
- if (typeof id !== "string") return false;
13
- return id.length >= MIN_LENGTH;
14
- };
15
-
16
- const createIDByName = <const B extends string>(idName: B): ID<B> => {
17
- const letters = "abcdefghijklmnopqrstuvyz";
18
- const all = letters + letters.toUpperCase();
19
- let result = "";
20
- for (let i = 0; i < ID_LENGTH; i++) {
21
- const char = all.charAt(Math.floor(Math.random() * all.length));
22
- result += char;
23
- }
24
- return result as ID<B>;
25
- };
26
-
27
- /**
28
- * Creates a object with helper functions for a specific ID type
29
- * @param idName
30
- */
31
- export const createTypedIdSingleton = <const B extends string>(idName: B) => {
32
- /**
33
- * Creates a new ID of the correct type
34
- */
35
- const create = (): ID<B> => createIDByName(idName);
36
-
37
- /**
38
- * Checks if the id is of the correct type
39
- * @param id
40
- */
41
- const is = (id: string): id is ID<B> => isID(idName, id);
42
-
43
- /**
44
- * Checks if the id is of the correct type, if not it throws an error
45
- * @param id
46
- */
47
- const validateOrThrow = (id: string): ID<B> => {
48
- if (!is(id)) {
49
- throw new Error(`Invalid id: ${id}`);
50
- }
51
- return id;
52
- };
53
-
54
- /**
55
- * The lowercase name of the id (SCHEMA, PAGE, etc)
56
- */
57
- const name: B = idName;
58
-
59
- /**
60
- * Ensures that the id is of the correct type, if not it creates a new one
61
- * @param id
62
- */
63
- const ensure = (id: string): ID<B> => {
64
- return is(id) ? id : create();
65
- };
66
-
67
- return Object.freeze({ create, is, ensure, validateOrThrow, name });
68
- };
69
-
70
- export type SchemaID = ID<"SCHEMA">;
71
- export const SchemaID = createTypedIdSingleton("SCHEMA");
72
- export type PageID = ID<"PAGE">;
73
- export const PageID = createTypedIdSingleton("PAGE");
1
+ // The default length of an ID
2
+ const ID_LENGTH = 32;
3
+
4
+ // The minimum length of an ID
5
+ const MIN_LENGTH = 10;
6
+
7
+ // const SPLITTER = "_";
8
+
9
+ export type ID<B extends string> = string & { __ID__: B };
10
+
11
+ const isID = <const B extends string>(idName: B, id?: string): id is ID<B> => {
12
+ if (typeof id !== "string") return false;
13
+ return id.length >= MIN_LENGTH;
14
+ };
15
+
16
+ const createIDByName = <const B extends string>(idName: B): ID<B> => {
17
+ const letters = "abcdefghijklmnopqrstuvyz";
18
+ const all = letters + letters.toUpperCase();
19
+ let result = "";
20
+ for (let i = 0; i < ID_LENGTH; i++) {
21
+ const char = all.charAt(Math.floor(Math.random() * all.length));
22
+ result += char;
23
+ }
24
+ return result as ID<B>;
25
+ };
26
+
27
+ /**
28
+ * Creates a object with helper functions for a specific ID type
29
+ * @param idName
30
+ */
31
+ export const createTypedIdSingleton = <const B extends string>(idName: B) => {
32
+ /**
33
+ * Creates a new ID of the correct type
34
+ */
35
+ const create = (): ID<B> => createIDByName(idName);
36
+
37
+ /**
38
+ * Checks if the id is of the correct type
39
+ * @param id
40
+ */
41
+ const is = (id: string): id is ID<B> => isID(idName, id);
42
+
43
+ /**
44
+ * Checks if the id is of the correct type, if not it throws an error
45
+ * @param id
46
+ */
47
+ const validateOrThrow = (id: string): ID<B> => {
48
+ if (!is(id)) {
49
+ throw new Error(`Invalid id: ${id}`);
50
+ }
51
+ return id;
52
+ };
53
+
54
+ /**
55
+ * The lowercase name of the id (SCHEMA, PAGE, etc)
56
+ */
57
+ const name: B = idName;
58
+
59
+ /**
60
+ * Ensures that the id is of the correct type, if not it creates a new one
61
+ * @param id
62
+ */
63
+ const ensure = (id: string): ID<B> => {
64
+ return is(id) ? id : create();
65
+ };
66
+
67
+ return Object.freeze({ create, is, ensure, validateOrThrow, name });
68
+ };
69
+
70
+ export type SchemaID = ID<"SCHEMA">;
71
+ export const SchemaID = createTypedIdSingleton("SCHEMA");
72
+ export type PageID = ID<"PAGE">;
73
+ export const PageID = createTypedIdSingleton("PAGE");
package/tsconfig.json CHANGED
@@ -1,19 +1,19 @@
1
- {
2
- "compilerOptions": {
3
- "target": "es2022",
4
- "module": "commonjs",
5
- "moduleResolution": "node",
6
- "declaration": true,
7
- "strict": true,
8
- // "incremental": true,
9
- "esModuleInterop": true,
10
- "skipLibCheck": true,
11
- "forceConsistentCasingInFileNames": true,
12
- "rootDir": "./src",
13
- "strictPropertyInitialization": true,
14
- "strictNullChecks": true,
15
- "outDir": "./dist",
16
- "composite": true
17
- },
18
- "include": ["src"]
19
- }
1
+ {
2
+ "compilerOptions": {
3
+ "target": "es2022",
4
+ "module": "commonjs",
5
+ "moduleResolution": "node",
6
+ "declaration": true,
7
+ "strict": true,
8
+ // "incremental": true,
9
+ "esModuleInterop": true,
10
+ "skipLibCheck": true,
11
+ "forceConsistentCasingInFileNames": true,
12
+ "rootDir": "./src",
13
+ "strictPropertyInitialization": true,
14
+ "strictNullChecks": true,
15
+ "outDir": "./dist",
16
+ "composite": true
17
+ },
18
+ "include": ["src"]
19
+ }