@hraness/oh 0.3.1 → 0.4.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.
Files changed (72) hide show
  1. package/README.md +194 -127
  2. package/dist/cli.d.ts +1 -1
  3. package/dist/cli.d.ts.map +1 -1
  4. package/dist/cli.js +811 -97
  5. package/dist/errors.d.ts +39 -0
  6. package/dist/errors.d.ts.map +1 -0
  7. package/dist/graph.d.ts.map +1 -1
  8. package/dist/index.js +676 -61
  9. package/dist/libsql-semantic-v2.d.ts +160 -0
  10. package/dist/libsql-semantic-v2.d.ts.map +1 -0
  11. package/dist/libsql.d.ts.map +1 -1
  12. package/dist/libsql.js +162 -35
  13. package/dist/memory-page.js +2 -2
  14. package/dist/memory.d.ts +87 -6
  15. package/dist/memory.d.ts.map +1 -1
  16. package/dist/memory.js +1106 -148
  17. package/dist/operation.d.ts +3 -1
  18. package/dist/operation.d.ts.map +1 -1
  19. package/dist/projection-public.js +2 -2
  20. package/dist/projection-suss.js +2 -2
  21. package/dist/sdk.js +780 -88
  22. package/dist/semantic-cloud.d.ts +1 -0
  23. package/dist/semantic-cloud.d.ts.map +1 -1
  24. package/dist/semantic-cloud.js +1545 -2
  25. package/dist/semantic.js +2 -2
  26. package/dist/sqlite/index.js +1251 -306
  27. package/dist/sqlite/port.d.ts +31 -3
  28. package/dist/sqlite/port.d.ts.map +1 -1
  29. package/dist/sqlite/store.d.ts +18 -2
  30. package/dist/sqlite/store.d.ts.map +1 -1
  31. package/dist/store.d.ts +3 -12
  32. package/dist/store.d.ts.map +1 -1
  33. package/dist/store.js +154 -32
  34. package/dist/sync.d.ts +7 -1
  35. package/dist/sync.d.ts.map +1 -1
  36. package/dist/sync.js +668 -35
  37. package/package.json +5 -1
  38. package/skills/oh/SKILL.md +42 -16
  39. package/spec/README.md +10 -3
  40. package/spec/manifest.json +5 -1
  41. package/spec/v1/libsql-semantic-cache-schema-v1.sql +114 -0
  42. package/spec/v1/libsql-semantic-digest-fixture-v1.json +13 -0
  43. package/spec/v1/memory.md +134 -16
  44. package/spec/v1/storage.md +8 -5
  45. package/spec/v1/store.md +20 -0
  46. package/spec/v1/sync.md +77 -8
  47. package/spec/v2/libsql-semantic-cache-schema-v2.sql +175 -0
  48. package/spec/v2/libsql-semantic-digest-fixture-v2.json +14 -0
  49. package/spec/v2/manifest.json +11 -0
  50. package/spec/v2/semantic-cloud.md +106 -0
  51. package/src/cli.test.ts +53 -1
  52. package/src/cli.ts +34 -8
  53. package/src/errors.test.ts +87 -0
  54. package/src/errors.ts +185 -0
  55. package/src/graph.ts +2 -2
  56. package/src/libsql-semantic-v2.test.ts +1114 -0
  57. package/src/libsql-semantic-v2.ts +1891 -0
  58. package/src/libsql-semantic.test.ts +50 -1
  59. package/src/libsql.test.ts +36 -0
  60. package/src/libsql.ts +26 -5
  61. package/src/memory.test.ts +1488 -18
  62. package/src/memory.ts +1199 -122
  63. package/src/operation.ts +13 -3
  64. package/src/semantic-cloud.ts +1 -0
  65. package/src/sqlite/port.test.ts +209 -0
  66. package/src/sqlite/port.ts +118 -4
  67. package/src/sqlite/store.test.ts +106 -1
  68. package/src/sqlite/store.ts +168 -30
  69. package/src/store.test.ts +12 -0
  70. package/src/store.ts +30 -20
  71. package/src/sync.test.ts +570 -2
  72. package/src/sync.ts +586 -36
package/src/errors.ts ADDED
@@ -0,0 +1,185 @@
1
+ export const OH_OPERATION_SIZE_ERROR_CODE_V1 = "oh.operation-size.v1" as const;
2
+
3
+ const OH_CONFLICT_ERROR_BRAND_V1 = Symbol.for("@hraness/oh/OhConflictError/v1");
4
+ const OH_DEPENDENCY_ERROR_BRAND_V1 = Symbol.for("@hraness/oh/OhDependencyError/v1");
5
+ const OH_INTEGRITY_ERROR_BRAND_V1 = Symbol.for("@hraness/oh/OhIntegrityError/v1");
6
+ const OH_OPERATION_SIZE_ERROR_BRAND_V1 = Symbol.for("@hraness/oh/OhOperationSizeError/v1");
7
+ const OH_PROFILE_ERROR_BRAND_V1 = Symbol.for("@hraness/oh/OhProfileError/v1");
8
+
9
+ function immutableOwnValue(value: object, key: PropertyKey): unknown {
10
+ const descriptor = Object.getOwnPropertyDescriptor(value, key);
11
+ return descriptor !== undefined
12
+ && descriptor.get === undefined
13
+ && descriptor.set === undefined
14
+ && descriptor.configurable === false
15
+ && descriptor.writable === false
16
+ ? descriptor.value
17
+ : undefined;
18
+ }
19
+
20
+ function brandNativeError(value: Error, brand: symbol): void {
21
+ Object.defineProperty(value, brand, {
22
+ configurable: false,
23
+ enumerable: false,
24
+ value: true,
25
+ writable: false,
26
+ });
27
+ }
28
+
29
+ function hasNativeErrorBrand(value: unknown, brand: symbol): boolean {
30
+ try {
31
+ return Error.isError(value) && immutableOwnValue(value, brand) === true;
32
+ } catch {
33
+ return false;
34
+ }
35
+ }
36
+
37
+ function hasNativeSubclassInstance(constructor: Function, value: unknown): boolean {
38
+ return Function.prototype[Symbol.hasInstance].call(constructor, value);
39
+ }
40
+
41
+ /** Recognizes a compare-and-swap conflict across separately bundled Oh entrypoints. */
42
+ export function isOhConflictError(value: unknown): value is OhConflictError {
43
+ return hasNativeErrorBrand(value, OH_CONFLICT_ERROR_BRAND_V1);
44
+ }
45
+
46
+ export class OhConflictError extends Error {
47
+ static override [Symbol.hasInstance](value: unknown): boolean {
48
+ return this === OhConflictError
49
+ ? isOhConflictError(value)
50
+ : hasNativeSubclassInstance(this, value);
51
+ }
52
+
53
+ constructor(message: string) {
54
+ super(message);
55
+ this.name = "OhConflictError";
56
+ brandNativeError(this, OH_CONFLICT_ERROR_BRAND_V1);
57
+ }
58
+ }
59
+
60
+ /** Recognizes an authority-integrity failure across separately bundled Oh entrypoints. */
61
+ export function isOhIntegrityError(value: unknown): value is OhIntegrityError {
62
+ return hasNativeErrorBrand(value, OH_INTEGRITY_ERROR_BRAND_V1);
63
+ }
64
+
65
+ export class OhIntegrityError extends Error {
66
+ static override [Symbol.hasInstance](value: unknown): boolean {
67
+ return this === OhIntegrityError
68
+ ? isOhIntegrityError(value)
69
+ : hasNativeSubclassInstance(this, value);
70
+ }
71
+
72
+ constructor(message: string) {
73
+ super(message);
74
+ this.name = "OhIntegrityError";
75
+ brandNativeError(this, OH_INTEGRITY_ERROR_BRAND_V1);
76
+ }
77
+ }
78
+
79
+ /** Recognizes a missing-dependency failure across separately bundled Oh entrypoints. */
80
+ export function isOhDependencyError(value: unknown): value is OhDependencyError {
81
+ return hasNativeErrorBrand(value, OH_DEPENDENCY_ERROR_BRAND_V1);
82
+ }
83
+
84
+ export class OhDependencyError extends Error {
85
+ static override [Symbol.hasInstance](value: unknown): boolean {
86
+ return this === OhDependencyError
87
+ ? isOhDependencyError(value)
88
+ : hasNativeSubclassInstance(this, value);
89
+ }
90
+
91
+ constructor(message: string) {
92
+ super(message);
93
+ this.name = "OhDependencyError";
94
+ brandNativeError(this, OH_DEPENDENCY_ERROR_BRAND_V1);
95
+ }
96
+ }
97
+
98
+ /** Recognizes a store-profile refusal across separately bundled Oh entrypoints. */
99
+ export function isOhProfileError(value: unknown): value is OhProfileError {
100
+ return hasNativeErrorBrand(value, OH_PROFILE_ERROR_BRAND_V1);
101
+ }
102
+
103
+ export class OhProfileError extends Error {
104
+ static override [Symbol.hasInstance](value: unknown): boolean {
105
+ return this === OhProfileError
106
+ ? isOhProfileError(value)
107
+ : hasNativeSubclassInstance(this, value);
108
+ }
109
+
110
+ constructor(message: string) {
111
+ super(message);
112
+ this.name = "OhProfileError";
113
+ brandNativeError(this, OH_PROFILE_ERROR_BRAND_V1);
114
+ }
115
+ }
116
+
117
+ /**
118
+ * Recognizes this precommit refusal across separately bundled Oh entrypoints.
119
+ * Native Error identity plus immutable branded fields excludes copied plain
120
+ * objects while preserving one stable discriminator for package consumers.
121
+ */
122
+ export function isOhOperationSizeError(value: unknown): value is OhOperationSizeError {
123
+ try {
124
+ if (!Error.isError(value) || !(value instanceof RangeError)) return false;
125
+ const operationBytes = immutableOwnValue(value, "operationBytes");
126
+ const maximumOperationBytes = immutableOwnValue(value, "maximumOperationBytes");
127
+ return immutableOwnValue(value, OH_OPERATION_SIZE_ERROR_BRAND_V1) === true
128
+ && immutableOwnValue(value, "code") === OH_OPERATION_SIZE_ERROR_CODE_V1
129
+ && Number.isSafeInteger(operationBytes)
130
+ && (operationBytes as number) > 0
131
+ && Number.isSafeInteger(maximumOperationBytes)
132
+ && (maximumOperationBytes as number) > 0
133
+ && (operationBytes as number) > (maximumOperationBytes as number);
134
+ } catch {
135
+ return false;
136
+ }
137
+ }
138
+
139
+ export class OhOperationSizeError extends RangeError {
140
+ declare readonly code: typeof OH_OPERATION_SIZE_ERROR_CODE_V1;
141
+ declare readonly maximumOperationBytes: number;
142
+ declare readonly operationBytes: number;
143
+
144
+ static override [Symbol.hasInstance](value: unknown): boolean {
145
+ return this === OhOperationSizeError
146
+ ? isOhOperationSizeError(value)
147
+ : hasNativeSubclassInstance(this, value);
148
+ }
149
+
150
+ constructor(operationBytes: number, maximumOperationBytes: number) {
151
+ if (!Number.isSafeInteger(operationBytes) || operationBytes < 1
152
+ || !Number.isSafeInteger(maximumOperationBytes) || maximumOperationBytes < 1
153
+ || operationBytes <= maximumOperationBytes) {
154
+ throw new TypeError("Invalid Oh operation size refusal.");
155
+ }
156
+ super(`The ${operationBytes}-byte operation exceeds the host-declared ${maximumOperationBytes}-byte canonical bound.`);
157
+ this.name = "OhOperationSizeError";
158
+ Object.defineProperties(this, {
159
+ [OH_OPERATION_SIZE_ERROR_BRAND_V1]: {
160
+ configurable: false,
161
+ enumerable: false,
162
+ value: true,
163
+ writable: false,
164
+ },
165
+ code: {
166
+ configurable: false,
167
+ enumerable: true,
168
+ value: OH_OPERATION_SIZE_ERROR_CODE_V1,
169
+ writable: false,
170
+ },
171
+ maximumOperationBytes: {
172
+ configurable: false,
173
+ enumerable: true,
174
+ value: maximumOperationBytes,
175
+ writable: false,
176
+ },
177
+ operationBytes: {
178
+ configurable: false,
179
+ enumerable: true,
180
+ value: operationBytes,
181
+ writable: false,
182
+ },
183
+ });
184
+ }
185
+ }
package/src/graph.ts CHANGED
@@ -19,12 +19,12 @@ export const OH_GRAPH_LIMITS_V1 = Object.freeze({
19
19
  recordsPerSnapshot: 65_536,
20
20
  });
21
21
 
22
- export const OH_KNOWLEDGE_GRAPH_RECORD_KINDS_V1 = [
22
+ export const OH_KNOWLEDGE_GRAPH_RECORD_KINDS_V1 = Object.freeze([
23
23
  "activity", "assertion", "context", "dependency-manifest", "edition", "entity",
24
24
  "evidence", "identity-operation", "inquiry", "inquiry-event", "review-decision",
25
25
  "rights-decision", "schema", "shape", "statement", "type-membership", "view",
26
26
  "vocabulary",
27
- ] as const;
27
+ ] as const);
28
28
  export type KnowledgeGraphRecordKindV1 = (typeof OH_KNOWLEDGE_GRAPH_RECORD_KINDS_V1)[number];
29
29
 
30
30
  export type KnowledgeGraphRecordV1 = Readonly<{