@composable-os/sdk 0.0.0-stage → 0.1.0-beta.11

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 (81) hide show
  1. package/LICENSE +109 -0
  2. package/dist/allowance.d.ts +198 -0
  3. package/dist/allowance.js +374 -0
  4. package/dist/automation-check.d.ts +38 -0
  5. package/dist/automation-check.js +454 -0
  6. package/dist/automation.d.ts +767 -0
  7. package/dist/automation.js +303 -0
  8. package/dist/behaviour.d.ts +3 -0
  9. package/dist/behaviour.js +153 -0
  10. package/dist/capacity.d.ts +146 -0
  11. package/dist/capacity.js +189 -0
  12. package/dist/contract.d.ts +851 -0
  13. package/dist/contract.js +42 -0
  14. package/dist/document.d.ts +211 -0
  15. package/dist/document.js +726 -0
  16. package/dist/field-types.d.ts +11 -0
  17. package/dist/field-types.js +98 -0
  18. package/dist/formula/ast.d.ts +67 -0
  19. package/dist/formula/ast.js +22 -0
  20. package/dist/formula/compile.d.ts +37 -0
  21. package/dist/formula/compile.js +379 -0
  22. package/dist/formula/index.d.ts +3 -0
  23. package/dist/formula/index.js +4 -0
  24. package/dist/formula/parser.d.ts +13 -0
  25. package/dist/formula/parser.js +365 -0
  26. package/dist/index.d.ts +20 -0
  27. package/dist/index.js +24 -0
  28. package/dist/manifest.d.ts +1708 -0
  29. package/dist/manifest.js +1494 -0
  30. package/dist/media.d.ts +41 -0
  31. package/dist/media.js +90 -0
  32. package/dist/permissions.d.ts +17 -0
  33. package/dist/permissions.js +44 -0
  34. package/dist/recurring.d.ts +114 -0
  35. package/dist/recurring.js +173 -0
  36. package/dist/renamed.d.ts +16 -0
  37. package/dist/renamed.js +59 -0
  38. package/dist/rich-text-fixture.d.ts +121 -0
  39. package/dist/rich-text-fixture.js +67 -0
  40. package/dist/rich-text.d.ts +48 -0
  41. package/dist/rich-text.js +184 -0
  42. package/dist/runtime.d.ts +95 -0
  43. package/dist/runtime.js +312 -0
  44. package/dist/sellable.d.ts +331 -0
  45. package/dist/sellable.js +746 -0
  46. package/dist/slug.d.ts +11 -0
  47. package/dist/slug.js +23 -0
  48. package/dist/states.d.ts +292 -0
  49. package/dist/states.js +383 -0
  50. package/dist/testing.d.ts +151 -0
  51. package/dist/testing.js +679 -0
  52. package/dist/unique.d.ts +20 -0
  53. package/dist/unique.js +58 -0
  54. package/package.json +34 -4
  55. package/src/allowance.ts +522 -0
  56. package/src/automation-check.ts +534 -0
  57. package/src/automation.ts +743 -0
  58. package/src/behaviour.ts +215 -0
  59. package/src/capacity.ts +303 -0
  60. package/src/contract.ts +909 -0
  61. package/src/document.ts +935 -0
  62. package/src/field-types.ts +111 -0
  63. package/src/formula/ast.ts +72 -0
  64. package/src/formula/compile.ts +454 -0
  65. package/src/formula/index.ts +4 -0
  66. package/src/formula/parser.ts +417 -0
  67. package/src/index.ts +36 -0
  68. package/src/manifest.ts +1785 -0
  69. package/src/media.ts +108 -0
  70. package/src/permissions.ts +60 -0
  71. package/src/recurring.ts +321 -0
  72. package/src/renamed.ts +63 -0
  73. package/src/rich-text-fixture.ts +68 -0
  74. package/src/rich-text.ts +221 -0
  75. package/src/runtime.ts +410 -0
  76. package/src/sellable.ts +1138 -0
  77. package/src/slug.ts +25 -0
  78. package/src/states.ts +598 -0
  79. package/src/testing.ts +847 -0
  80. package/src/unique.ts +81 -0
  81. package/README.md +0 -3
package/src/unique.ts ADDED
@@ -0,0 +1,81 @@
1
+ // Declared uniqueness (stage 31, ADR 0502): an object says that among its live records in some
2
+ // states, no two share the values of some fields (one active booking per Person per class). The
3
+ // host refuses the second in the database, for every actor, however many write at once.
4
+ import { z } from "zod";
5
+ import type { ExtensionManifest, ObjectManifest } from "./manifest.ts";
6
+
7
+ /**
8
+ * One uniqueness rule: no two live records with the same values of `fields` (one to four
9
+ * single-valued fields of this object; a record with any of them empty is not counted) while
10
+ * their state (the object's `states` field) is one of `states`. Left without `states`, every
11
+ * live record counts. The database refuses a second record, or a move back into a counted state,
12
+ * as a conflict (`rule: "unique"`).
13
+ */
14
+ export interface UniqueSpec {
15
+ fields: readonly string[];
16
+ states?: readonly string[];
17
+ }
18
+
19
+ export const uniqueManifestSchema = z
20
+ .array(
21
+ z
22
+ .object({
23
+ fields: z.array(z.string().max(40)).min(1).max(4),
24
+ states: z.array(z.string().min(1).max(100)).min(1).max(20).optional(),
25
+ })
26
+ .strict(),
27
+ )
28
+ .min(1)
29
+ .max(4);
30
+ export type UniqueManifest = z.infer<typeof uniqueManifestSchema>;
31
+
32
+ const UNIQUE_TYPES = new Set([
33
+ "text",
34
+ "number",
35
+ "date",
36
+ "datetime",
37
+ "boolean",
38
+ "select",
39
+ "relation",
40
+ "user",
41
+ "email",
42
+ "phone",
43
+ "url",
44
+ "slug",
45
+ "timezone",
46
+ ]);
47
+
48
+ /** Reports problems with `objects.<name>.unique` through `contract`. */
49
+ export function checkObjectUnique(
50
+ _m: ExtensionManifest,
51
+ name: string,
52
+ object: ObjectManifest,
53
+ contract: (path: string, message: string) => void,
54
+ ): void {
55
+ (object.unique ?? []).forEach((rule, i) => {
56
+ const path = `objects.${name}.unique.${i}`;
57
+ if (new Set(rule.fields).size !== rule.fields.length) {
58
+ contract(`${path}.fields`, "List each field once");
59
+ }
60
+ for (const local of rule.fields) {
61
+ const field = Object.hasOwn(object.fields, local) ? object.fields[local] : undefined;
62
+ if (!field || field.many || !UNIQUE_TYPES.has(field.type)) {
63
+ contract(`${path}.fields`, `"${local}" must be a single-valued, stored field of ${name}`);
64
+ }
65
+ }
66
+ if (rule.states) {
67
+ const states = object.states;
68
+ if (!states) {
69
+ contract(`${path}.states`, `${name} has no states`);
70
+ return;
71
+ }
72
+ const field = Object.hasOwn(object.fields, states.field)
73
+ ? object.fields[states.field]
74
+ : undefined;
75
+ const values = new Set((field?.options ?? []).map((o) => o.value));
76
+ for (const state of rule.states) {
77
+ if (!values.has(state)) contract(`${path}.states`, `"${state}" is not a state of ${name}`);
78
+ }
79
+ }
80
+ });
81
+ }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.