@bitspark/ontos-deixis-projection 0.14.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/LICENSE +202 -0
- package/NOTICE +4 -0
- package/dist/src/index.d.ts +102 -0
- package/dist/src/index.js +229 -0
- package/dist/src/index.js.map +1 -0
- package/package.json +38 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/NOTICE
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { Node, type Option } from "@bitspark/deixis-core";
|
|
2
|
+
import { type Value } from "@bitspark/ontos-core";
|
|
3
|
+
/** The name of the profile this package implements. */
|
|
4
|
+
export declare const PROFILE = "ontos-over-deixis-v1";
|
|
5
|
+
/**
|
|
6
|
+
* The position spelling the profile is defined over. It is the value the vector file
|
|
7
|
+
* carries, and a conforming face is conforming to exactly this spelling — the tests pin
|
|
8
|
+
* it against @bitspark/deixis-pos's own `PROFILE`.
|
|
9
|
+
*/
|
|
10
|
+
export declare const POSITION_SPELLING = "deixis-pos-v1";
|
|
11
|
+
/**
|
|
12
|
+
* The bridge's slot: an optional byte string. `Some(b)` reads as an atom's bytes, `None`
|
|
13
|
+
* (spelled `undefined` by deixis) as "no atom here, a tuple's positions instead".
|
|
14
|
+
*
|
|
15
|
+
* Deixis requires a value at every node and says nothing about what it means. This choice
|
|
16
|
+
* is the profile's, made here and nowhere else.
|
|
17
|
+
*/
|
|
18
|
+
export type Payload = Option<Uint8Array>;
|
|
19
|
+
/** The projection's codomain, `Node[Option[Bytes]]`. */
|
|
20
|
+
export type BytesNode = Node<Payload>;
|
|
21
|
+
/**
|
|
22
|
+
* Equality of the WHOLE payload: `None` differs from every `Some`, and two `Some`s
|
|
23
|
+
* compare by exact bytes, length included.
|
|
24
|
+
*/
|
|
25
|
+
export declare function payloadEq(a: Payload, b: Payload): boolean;
|
|
26
|
+
/**
|
|
27
|
+
* The deixis identity `=D` at this bridge's slot: deixis's lifted relation over
|
|
28
|
+
* `payloadEq`.
|
|
29
|
+
*
|
|
30
|
+
* Deixis deliberately provides no native equality for a node — it lifts one from the slot
|
|
31
|
+
* and declines to choose the slot's relation on a caller's behalf — so the relation is
|
|
32
|
+
* supplied here, explicitly.
|
|
33
|
+
*/
|
|
34
|
+
export declare function nodeEq(a: BytesNode, b: BytesNode): boolean;
|
|
35
|
+
/**
|
|
36
|
+
* `P : Ontos → Node[Option[Bytes]]` — TOTAL. Every ontos value has a projection, so this
|
|
37
|
+
* function cannot fail on an L0 value:
|
|
38
|
+
*
|
|
39
|
+
* P(Atom(b)) = Node(Some(b), {})
|
|
40
|
+
* P(Tuple(v₀ … vₙ₋₁)) = Node(None, { κ(i) ↦ P(vᵢ) | 0 ≤ i < n })
|
|
41
|
+
*/
|
|
42
|
+
export declare function project(value: Value): BytesNode;
|
|
43
|
+
/** The refusal classes. Normative: two conforming faces agree on which one applies. */
|
|
44
|
+
export type UnrecognizedKind = "key_mismatch" | "value_with_children";
|
|
45
|
+
/**
|
|
46
|
+
* Why a node is not an ontos value.
|
|
47
|
+
*
|
|
48
|
+
* `Node[Option[Bytes]]` admits shapes the projection never produces, and they do not all
|
|
49
|
+
* fail for the same reason — so they do not all get the same explanation. A malformed key
|
|
50
|
+
* domain is a statement about WHICH positions a tuple carries; a payload beside children
|
|
51
|
+
* is a statement about WHAT KIND of node it is at all. Collapsing the second into the
|
|
52
|
+
* first would name a key as the culprit when no key is wrong.
|
|
53
|
+
*
|
|
54
|
+
* Do not branch on `message`. It is informative, not normative (PROJECTION.md §Vectors):
|
|
55
|
+
* conformance is the refusal and its `kind`, and two conforming faces are free to word
|
|
56
|
+
* the prose differently. Branch on `kind`, or on `instanceof` of a subclass.
|
|
57
|
+
*/
|
|
58
|
+
export declare abstract class Unrecognized extends Error {
|
|
59
|
+
readonly name: string;
|
|
60
|
+
/** Which refusal this is. Normative. */
|
|
61
|
+
abstract readonly kind: UnrecognizedKind;
|
|
62
|
+
/** Tuple indices from the root to the node that refused. */
|
|
63
|
+
readonly path: readonly number[];
|
|
64
|
+
protected constructor(path: readonly number[], message: string);
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* The first entry, in canonical order, whose key is not the spelling of its position. A
|
|
68
|
+
* shifted or sparse domain, a named key, a non-canonical spelling and a stray entry after
|
|
69
|
+
* a dense prefix all surface here, located by `entry`.
|
|
70
|
+
*/
|
|
71
|
+
export declare class KeyMismatch extends Unrecognized {
|
|
72
|
+
readonly name = "KeyMismatch";
|
|
73
|
+
readonly kind: "key_mismatch";
|
|
74
|
+
/** The entry position (in canonical order) whose key mismatched. */
|
|
75
|
+
readonly entry: number;
|
|
76
|
+
/** `κ(entry)` — the key that position must carry. */
|
|
77
|
+
readonly expected: Uint8Array;
|
|
78
|
+
/** The key bytes actually present. */
|
|
79
|
+
readonly found: Uint8Array;
|
|
80
|
+
constructor(path: readonly number[], entry: number, expected: Uint8Array, found: Uint8Array);
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* The node carries an own value AND children. `P` emits a payload only at a childless
|
|
84
|
+
* node, so this is outside its image however well-formed the keys are — and the keys are
|
|
85
|
+
* not consulted, because the shape is already wrong.
|
|
86
|
+
*/
|
|
87
|
+
export declare class ValueWithChildren extends Unrecognized {
|
|
88
|
+
readonly name = "ValueWithChildren";
|
|
89
|
+
readonly kind: "value_with_children";
|
|
90
|
+
/** How many children the node carries. Any number but zero refuses. */
|
|
91
|
+
readonly children: number;
|
|
92
|
+
constructor(path: readonly number[], children: number);
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* `R : Node[Option[Bytes]] ⇀ Ontos` — PARTIAL. Succeeds exactly on the image of `project`
|
|
96
|
+
* (law 2), and throws an `Unrecognized` subclass on everything else:
|
|
97
|
+
*
|
|
98
|
+
* R(Node(Some(b), {})) = Atom(b)
|
|
99
|
+
* R(Node(None, m)) = Tuple(R(m(κ(0))), …, R(m(κ(n−1))))
|
|
100
|
+
* defined only when dom m = { κ(0), …, κ(n−1) } and every child recognizes.
|
|
101
|
+
*/
|
|
102
|
+
export declare function recognize(node: BytesNode): Value;
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* ontos-over-deixis-v1 — the projection between ontos values and Node[Option[Bytes]],
|
|
3
|
+
* on the deixis-pos-v1 position spelling. See ../../PROJECTION.md (normative).
|
|
4
|
+
*
|
|
5
|
+
* P(Atom(b)) = Node(Some(b), {}) total
|
|
6
|
+
* P(Tuple(v₀ … vₙ₋₁)) = Node(None, { κ(i) ↦ P(vᵢ) }) total
|
|
7
|
+
* R(Node(Some(b), {})) = Atom(b) partial:
|
|
8
|
+
* R(Node(None, m)) = Tuple over κ(0) … κ(n−1), exactly exact or refusal
|
|
9
|
+
*
|
|
10
|
+
* Deixis v0.2.0 gives every node an own value independently of its children
|
|
11
|
+
* (Node[T] = T × FinMap[Bytes, Node[T]]), so there is no leaf/struct sum to switch on.
|
|
12
|
+
* `Option` is THIS BRIDGE'S chosen payload domain, not a feature of the deixis core — the
|
|
13
|
+
* core carries T opaquely and never interprets it. The two ontos constructors therefore
|
|
14
|
+
* land on two disjoint node shapes, a present value with no children and an absent value
|
|
15
|
+
* with the dense positional children, and the shapes that are NEITHER are exactly what R
|
|
16
|
+
* refuses.
|
|
17
|
+
*
|
|
18
|
+
* The recognizer never parses a key: κ is order-preserving, so deixis's canonical entry
|
|
19
|
+
* order is tuple order, and recognition is one pairwise walk comparing each entry key
|
|
20
|
+
* octet-for-octet against the generated κ(i). It never sorts entries into new positions,
|
|
21
|
+
* fills gaps, drops keys, or normalizes an alternate spelling to its index — recognition
|
|
22
|
+
* is exact or it throws, because a repair pass would silently coarsen identity, which no
|
|
23
|
+
* layer may do.
|
|
24
|
+
*
|
|
25
|
+
* This package is additive and defines no equality of its own at L0 — ontos identity
|
|
26
|
+
* stays where it is (`equals` from @bitspark/ontos-core). What it DOES supply is the slot
|
|
27
|
+
* relation deixis requires of a caller: see `nodeEq`. Nothing in ontos/core or
|
|
28
|
+
* ontos-codec-v1 changes because this package exists, and the dependency direction is
|
|
29
|
+
* ontos → deixis, never the reverse.
|
|
30
|
+
*
|
|
31
|
+
* BROWSER-COMPATIBLE BY CONSTRUCTION. This file imports only @bitspark/ontos-core,
|
|
32
|
+
* @bitspark/deixis-core and @bitspark/deixis-pos — all three pure ESM over Uint8Array —
|
|
33
|
+
* and nothing from `node:`; there is no Buffer, no process, no filesystem. The
|
|
34
|
+
* test/browser.test.ts guard pins that for this file AND for the runtime closure.
|
|
35
|
+
*
|
|
36
|
+
* Peer of projection/deixis/rs (Rust) and projection/deixis/go (Go). Written with both
|
|
37
|
+
* in view, so it is NOT an independent reading of PROJECTION.md — see the note at the
|
|
38
|
+
* bottom of this file.
|
|
39
|
+
*/
|
|
40
|
+
import { Node, some } from "@bitspark/deixis-core";
|
|
41
|
+
import { key } from "@bitspark/deixis-pos";
|
|
42
|
+
import { atom, tuple, bytesEqual, toHex } from "@bitspark/ontos-core";
|
|
43
|
+
/** The name of the profile this package implements. */
|
|
44
|
+
export const PROFILE = "ontos-over-deixis-v1";
|
|
45
|
+
/**
|
|
46
|
+
* The position spelling the profile is defined over. It is the value the vector file
|
|
47
|
+
* carries, and a conforming face is conforming to exactly this spelling — the tests pin
|
|
48
|
+
* it against @bitspark/deixis-pos's own `PROFILE`.
|
|
49
|
+
*/
|
|
50
|
+
export const POSITION_SPELLING = "deixis-pos-v1";
|
|
51
|
+
/**
|
|
52
|
+
* Equality of the WHOLE payload: `None` differs from every `Some`, and two `Some`s
|
|
53
|
+
* compare by exact bytes, length included.
|
|
54
|
+
*/
|
|
55
|
+
export function payloadEq(a, b) {
|
|
56
|
+
if (a === undefined || b === undefined)
|
|
57
|
+
return a === b;
|
|
58
|
+
return bytesEqual(a.value, b.value);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* The deixis identity `=D` at this bridge's slot: deixis's lifted relation over
|
|
62
|
+
* `payloadEq`.
|
|
63
|
+
*
|
|
64
|
+
* Deixis deliberately provides no native equality for a node — it lifts one from the slot
|
|
65
|
+
* and declines to choose the slot's relation on a caller's behalf — so the relation is
|
|
66
|
+
* supplied here, explicitly.
|
|
67
|
+
*/
|
|
68
|
+
export function nodeEq(a, b) {
|
|
69
|
+
return a.equalBy(b, payloadEq);
|
|
70
|
+
}
|
|
71
|
+
/** A node with a payload and no children; composing zero children cannot collide. */
|
|
72
|
+
function childless(own) {
|
|
73
|
+
return Node.compose(own, []);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* `P : Ontos → Node[Option[Bytes]]` — TOTAL. Every ontos value has a projection, so this
|
|
77
|
+
* function cannot fail on an L0 value:
|
|
78
|
+
*
|
|
79
|
+
* P(Atom(b)) = Node(Some(b), {})
|
|
80
|
+
* P(Tuple(v₀ … vₙ₋₁)) = Node(None, { κ(i) ↦ P(vᵢ) | 0 ≤ i < n })
|
|
81
|
+
*/
|
|
82
|
+
export function project(value) {
|
|
83
|
+
switch (value.kind) {
|
|
84
|
+
case "atom":
|
|
85
|
+
// Some(b) AND childless. The childlessness is half the projection: it is what
|
|
86
|
+
// lets R tell an atom from a tuple without a tag.
|
|
87
|
+
return childless(some(value.bytes()));
|
|
88
|
+
case "tuple": {
|
|
89
|
+
// Law 6: the empty TUPLE is Node(None, {}) and the empty ATOM is Node(Some(""), {}).
|
|
90
|
+
// Both are childless, so the whole distinction rests on the payload — which is
|
|
91
|
+
// exactly what a lax bridge would merge.
|
|
92
|
+
const entries = [];
|
|
93
|
+
const items = value.items();
|
|
94
|
+
for (let i = 0; i < items.length; i += 1) {
|
|
95
|
+
entries.push([key(BigInt(i)), project(items[i])]);
|
|
96
|
+
}
|
|
97
|
+
// κ is injective (deixis-pos-v1), so 0…n−1 yield n distinct keys and deixis's
|
|
98
|
+
// DuplicateKeyError is unreachable here — P stays total in its signature.
|
|
99
|
+
return Node.compose(undefined, entries);
|
|
100
|
+
}
|
|
101
|
+
default: {
|
|
102
|
+
// L0 is closed: Value = Atom | Tuple. A third case would be a new floor, not a
|
|
103
|
+
// new projection; the `never` makes the compiler say so.
|
|
104
|
+
const impossible = value;
|
|
105
|
+
throw new TypeError(`${PROFILE}: not an L0 value: ${String(impossible)}`);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Why a node is not an ontos value.
|
|
111
|
+
*
|
|
112
|
+
* `Node[Option[Bytes]]` admits shapes the projection never produces, and they do not all
|
|
113
|
+
* fail for the same reason — so they do not all get the same explanation. A malformed key
|
|
114
|
+
* domain is a statement about WHICH positions a tuple carries; a payload beside children
|
|
115
|
+
* is a statement about WHAT KIND of node it is at all. Collapsing the second into the
|
|
116
|
+
* first would name a key as the culprit when no key is wrong.
|
|
117
|
+
*
|
|
118
|
+
* Do not branch on `message`. It is informative, not normative (PROJECTION.md §Vectors):
|
|
119
|
+
* conformance is the refusal and its `kind`, and two conforming faces are free to word
|
|
120
|
+
* the prose differently. Branch on `kind`, or on `instanceof` of a subclass.
|
|
121
|
+
*/
|
|
122
|
+
export class Unrecognized extends Error {
|
|
123
|
+
name = "Unrecognized";
|
|
124
|
+
/** Tuple indices from the root to the node that refused. */
|
|
125
|
+
path;
|
|
126
|
+
constructor(path, message) {
|
|
127
|
+
super(message);
|
|
128
|
+
this.path = Object.freeze([...path]);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* The first entry, in canonical order, whose key is not the spelling of its position. A
|
|
133
|
+
* shifted or sparse domain, a named key, a non-canonical spelling and a stray entry after
|
|
134
|
+
* a dense prefix all surface here, located by `entry`.
|
|
135
|
+
*/
|
|
136
|
+
export class KeyMismatch extends Unrecognized {
|
|
137
|
+
name = "KeyMismatch";
|
|
138
|
+
kind = "key_mismatch";
|
|
139
|
+
/** The entry position (in canonical order) whose key mismatched. */
|
|
140
|
+
entry;
|
|
141
|
+
/** `κ(entry)` — the key that position must carry. */
|
|
142
|
+
expected;
|
|
143
|
+
/** The key bytes actually present. */
|
|
144
|
+
found;
|
|
145
|
+
constructor(path, entry, expected, found) {
|
|
146
|
+
const where = path.length === 0 ? "$" : `$.${path.join(".")}`;
|
|
147
|
+
super(path, `${where}: entry ${entry} carries key ${toHex(found)}, not κ(${entry}) = ${toHex(expected)} — ` +
|
|
148
|
+
`recognition under ${PROFILE} is exact, and dom m must be exactly {κ(0) … κ(n−1)}`);
|
|
149
|
+
this.entry = entry;
|
|
150
|
+
this.expected = expected;
|
|
151
|
+
this.found = found;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* The node carries an own value AND children. `P` emits a payload only at a childless
|
|
156
|
+
* node, so this is outside its image however well-formed the keys are — and the keys are
|
|
157
|
+
* not consulted, because the shape is already wrong.
|
|
158
|
+
*/
|
|
159
|
+
export class ValueWithChildren extends Unrecognized {
|
|
160
|
+
name = "ValueWithChildren";
|
|
161
|
+
kind = "value_with_children";
|
|
162
|
+
/** How many children the node carries. Any number but zero refuses. */
|
|
163
|
+
children;
|
|
164
|
+
constructor(path, children) {
|
|
165
|
+
const where = path.length === 0 ? "$" : `$.${path.join(".")}`;
|
|
166
|
+
super(path, `${where}: the node carries an own value and ${children} child(ren); under ${PROFILE} ` +
|
|
167
|
+
`a payload belongs only to a CHILDLESS node, so no key is at fault here`);
|
|
168
|
+
this.children = children;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* `R : Node[Option[Bytes]] ⇀ Ontos` — PARTIAL. Succeeds exactly on the image of `project`
|
|
173
|
+
* (law 2), and throws an `Unrecognized` subclass on everything else:
|
|
174
|
+
*
|
|
175
|
+
* R(Node(Some(b), {})) = Atom(b)
|
|
176
|
+
* R(Node(None, m)) = Tuple(R(m(κ(0))), …, R(m(κ(n−1))))
|
|
177
|
+
* defined only when dom m = { κ(0), …, κ(n−1) } and every child recognizes.
|
|
178
|
+
*/
|
|
179
|
+
export function recognize(node) {
|
|
180
|
+
return recognizeAt(node, []);
|
|
181
|
+
}
|
|
182
|
+
function recognizeAt(node, path) {
|
|
183
|
+
const own = node.own();
|
|
184
|
+
const entries = node.entries();
|
|
185
|
+
if (own !== undefined) {
|
|
186
|
+
// A present payload is an atom — but ONLY if the node is childless. A node carrying
|
|
187
|
+
// both is well-formed deixis and outside the image of P. That is a question about
|
|
188
|
+
// the node's SHAPE, so it is answered before any key is read: the keys may be
|
|
189
|
+
// flawless κ and the node is still not an ontos value.
|
|
190
|
+
if (entries.length > 0) {
|
|
191
|
+
throw new ValueWithChildren(path, entries.length);
|
|
192
|
+
}
|
|
193
|
+
return atom(own.value);
|
|
194
|
+
}
|
|
195
|
+
// An absent payload is a tuple. Because κ is order-preserving, deixis's canonical entry
|
|
196
|
+
// order IS tuple order. So the recognizer walks the entries ONCE, comparing each key
|
|
197
|
+
// against the GENERATED κ(i) — it never parses a key and needs no κ decoder. That is
|
|
198
|
+
// also what makes the refusals exact: a gap (dom = {κ(0), κ(2)}) shows up as entry 1
|
|
199
|
+
// carrying κ(2); a named key, an empty key, a straggler after a dense prefix, and a key
|
|
200
|
+
// that would DECODE to i but is not octet-equal to κ(i) are all caught by the same
|
|
201
|
+
// comparison. n = 0 is the empty tuple and is in the image.
|
|
202
|
+
const items = [];
|
|
203
|
+
for (let i = 0; i < entries.length; i += 1) {
|
|
204
|
+
const [found, child] = entries[i];
|
|
205
|
+
const expected = key(BigInt(i));
|
|
206
|
+
if (!bytesEqual(found, expected)) {
|
|
207
|
+
throw new KeyMismatch(path, i, expected, found);
|
|
208
|
+
}
|
|
209
|
+
path.push(i);
|
|
210
|
+
items.push(recognizeAt(child, path));
|
|
211
|
+
path.pop();
|
|
212
|
+
}
|
|
213
|
+
return tuple(items);
|
|
214
|
+
}
|
|
215
|
+
/*
|
|
216
|
+
* INDEPENDENCE NOTE, recorded because the profile's maturity claim depends on it.
|
|
217
|
+
*
|
|
218
|
+
* This face was written by ontos, with projection/deixis/rs and projection/deixis/go
|
|
219
|
+
* open beside PROJECTION.md. It is therefore independent of neither face's code nor of
|
|
220
|
+
* the organisation that wrote them, and per ontos-internal#255 it changes NOTHING about the
|
|
221
|
+
* profile's maturity: `ontos-over-deixis-v1` stays UNWITNESSED, permanently. A third
|
|
222
|
+
* ontos-authored face is a third consumer of the same reading, not a witness to it.
|
|
223
|
+
*
|
|
224
|
+
* The v0.2.0 migration does not change that in either direction: all three faces were
|
|
225
|
+
* carried to the mandatory-value model together, by one author with all three open, so
|
|
226
|
+
* it is not a fresh independent reading — and it does not retract the Go face's original
|
|
227
|
+
* one either, which remains a fact about how that face was FIRST written.
|
|
228
|
+
*/
|
|
229
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AAEH,OAAO,EAAE,IAAI,EAAE,IAAI,EAAe,MAAM,uBAAuB,CAAC;AAChE,OAAO,EAAE,GAAG,EAAE,MAAM,sBAAsB,CAAC;AAC3C,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,UAAU,EAAE,KAAK,EAAc,MAAM,sBAAsB,CAAC;AAElF,uDAAuD;AACvD,MAAM,CAAC,MAAM,OAAO,GAAG,sBAAsB,CAAC;AAE9C;;;;GAIG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,eAAe,CAAC;AAcjD;;;GAGG;AACH,MAAM,UAAU,SAAS,CAAC,CAAU,EAAE,CAAU;IAC9C,IAAI,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;IAC1B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;QAC3C,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,GAAG,OAAO,CAAC,CAAC,CAAE,CAAC;QACnC,MAAM,QAAQ,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;QAChC,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,QAAQ,CAAC,EAAE,CAAC;YACjC,MAAM,IAAI,WAAW,CAAC,IAAI,EAAE,CAAC,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC;QAClD,CAAC;QACD,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACb,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC;QACrC,IAAI,CAAC,GAAG,EAAE,CAAC;IACb,CAAC;IACD,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC;AACtB,CAAC;AAED;;;;;;;;;;;;;GAaG"}
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@bitspark/ontos-deixis-projection",
|
|
3
|
+
"version": "0.14.0",
|
|
4
|
+
"license": "Apache-2.0",
|
|
5
|
+
"description": "ontos-over-deixis-v1: the total projection P and exact partial recognizer R between ontos values and Node[Option[Bytes]], on the deixis-pos-v1 position spelling. Additive; the one TypeScript package in ontos that knows deixis exists. Browser-compatible (no Node-only imports). Depends on @bitspark/ontos-core, @bitspark/deixis-core and @bitspark/deixis-pos.",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/Bitspark/ontos.git"
|
|
10
|
+
},
|
|
11
|
+
"publishConfig": {
|
|
12
|
+
"access": "public",
|
|
13
|
+
"registry": "https://registry.npmjs.org/",
|
|
14
|
+
"provenance": true
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist/src",
|
|
18
|
+
"LICENSE",
|
|
19
|
+
"NOTICE"
|
|
20
|
+
],
|
|
21
|
+
"exports": {
|
|
22
|
+
".": "./dist/src/index.js",
|
|
23
|
+
"./package.json": "./package.json"
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@bitspark/deixis-core": "0.6.0",
|
|
27
|
+
"@bitspark/deixis-pos": "0.6.0",
|
|
28
|
+
"@bitspark/ontos-core": "^0.14.0"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@bitspark/ontos-codec": "^0.14.0"
|
|
32
|
+
},
|
|
33
|
+
"scripts": {
|
|
34
|
+
"build": "tsc -p tsconfig.json",
|
|
35
|
+
"test": "node --test test/*.test.ts"
|
|
36
|
+
},
|
|
37
|
+
"gitHead": "a44df597c4e7561ce2573b30e4c058c164853490"
|
|
38
|
+
}
|