@rayfold/conformance 0.1.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 +10 -0
- package/README.md +29 -0
- package/fixture.d.ts +107 -0
- package/fixture.js +161 -0
- package/fixture.js.map +1 -0
- package/fixtures/core/01-default-view.json +1245 -0
- package/fixtures/core/02-shapes.json +1278 -0
- package/fixtures/core/03-pipelining.json +1369 -0
- package/fixtures/core/04-commands.json +1456 -0
- package/fixtures/core/05-errors.json +1510 -0
- package/fixtures/core/06-auth.json +1441 -0
- package/fixtures/core/07-defer.json +1277 -0
- package/fixtures/core/08-streams.json +1199 -0
- package/fixtures/core/09-limits.json +1249 -0
- package/fixtures/core/10-trusted-shapes.json +1231 -0
- package/fixtures/core/11-unions.json +389 -0
- package/fixtures/core/12-compact.json +1252 -0
- package/fixtures/core/12-interfaces.json +605 -0
- package/fixtures/core/13-writes.json +1391 -0
- package/fixtures/core/14-shared-loads.json +440 -0
- package/package.json +44 -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,10 @@
|
|
|
1
|
+
Rayfold
|
|
2
|
+
Copyright 2026 The Rayfold Authors
|
|
3
|
+
|
|
4
|
+
This product is licensed under the Apache License, Version 2.0 (see LICENSE).
|
|
5
|
+
|
|
6
|
+
The data in data/gutenberg.json.gz is derived from the Project Gutenberg catalogue
|
|
7
|
+
(https://www.gutenberg.org/ebooks/offline_catalogs.html) and is not covered by this
|
|
8
|
+
project's copyright. See data/README.md for its source. Project Gutenberg is a
|
|
9
|
+
registered trademark of the Project Gutenberg Literary Archive Foundation; Rayfold is
|
|
10
|
+
not affiliated with or endorsed by Project Gutenberg.
|
package/README.md
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# @rayfold/conformance
|
|
2
|
+
|
|
3
|
+
The shared test cases that every Rayfold implementation must pass. The TypeScript and Kotlin runtimes both run them.
|
|
4
|
+
If you write a Rayfold server in another language, run these and you can show it behaves like the reference.
|
|
5
|
+
|
|
6
|
+
What the package contains:
|
|
7
|
+
|
|
8
|
+
- `fixtures/core/*.json`: one file per topic (default views, shapes, pipelining, commands, errors, auth, defer,
|
|
9
|
+
streams, limits, trusted shapes, ...). Each file holds a `.rayfold` schema, its parsed IR, seed data, and cases:
|
|
10
|
+
a request, the viewer, and the exact frames expected back.
|
|
11
|
+
- The harness the reference runtime uses (`seedStore`, `fixtureResolvers`, `groupFrames`): it turns a fixture's
|
|
12
|
+
data and declarative resolver specs into resolvers for `@rayfold/server`, so you can see how each case is meant
|
|
13
|
+
to be served.
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { readFileSync, readdirSync } from "node:fs";
|
|
17
|
+
import { createRequire } from "node:module";
|
|
18
|
+
import { dirname, join } from "node:path";
|
|
19
|
+
|
|
20
|
+
const dir = join(dirname(createRequire(import.meta.url).resolve("@rayfold/conformance/package.json")), "fixtures/core");
|
|
21
|
+
for (const file of readdirSync(dir)) {
|
|
22
|
+
const fixture = JSON.parse(readFileSync(join(dir, file), "utf8"));
|
|
23
|
+
console.log(file, fixture.cases.length, "cases");
|
|
24
|
+
}
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
The fixture format is documented in `conformance/README.md` and `conformance/src/fixture.ts` in the Rayfold repository.
|
|
28
|
+
|
|
29
|
+
Apache-2.0.
|
package/fixture.d.ts
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Conformance fixture format and the declarative resolver interpreter.
|
|
3
|
+
* Both runtimes (TS, Kotlin) implement this interpreter so fixtures need no code.
|
|
4
|
+
*/
|
|
5
|
+
import { type Frame, type PatchOp, type RequestEnvelope, type Resolvers } from "@rayfold/server";
|
|
6
|
+
export interface Fixture {
|
|
7
|
+
name: string;
|
|
8
|
+
/** `.rayfold` schema text */
|
|
9
|
+
schema: string;
|
|
10
|
+
/** rows per type name; re-seeded before every case */
|
|
11
|
+
data: Record<string, Array<Record<string, unknown>>>;
|
|
12
|
+
resolvers: {
|
|
13
|
+
Query?: Record<string, QuerySpec>;
|
|
14
|
+
Command?: Record<string, CommandSpec>;
|
|
15
|
+
Stream?: Record<string, StreamSpec>;
|
|
16
|
+
fields?: Record<string, Record<string, FieldSpec>>;
|
|
17
|
+
};
|
|
18
|
+
options?: {
|
|
19
|
+
budget?: number;
|
|
20
|
+
maxDepth?: number;
|
|
21
|
+
trustedShapes?: boolean;
|
|
22
|
+
registerShapes?: string[];
|
|
23
|
+
};
|
|
24
|
+
cases: Case[];
|
|
25
|
+
}
|
|
26
|
+
export interface Case {
|
|
27
|
+
name: string;
|
|
28
|
+
viewer?: unknown;
|
|
29
|
+
request: RequestEnvelope;
|
|
30
|
+
/** Expected frames. Frames of different ops may interleave; per-op order must match. */
|
|
31
|
+
frames: Frame[];
|
|
32
|
+
/** Expected loader call counts, e.g. { "Book.author": 1 } */
|
|
33
|
+
calls?: Record<string, number>;
|
|
34
|
+
/** Run this many times in sequence against the same store (idempotency cases). */
|
|
35
|
+
repeat?: number;
|
|
36
|
+
}
|
|
37
|
+
/** Value templates: "$args.x.y", "$viewer.id", "$parent.field", "$row.field", literals. */
|
|
38
|
+
type Tmpl = unknown;
|
|
39
|
+
export interface QuerySpec {
|
|
40
|
+
from: string;
|
|
41
|
+
where?: Record<string, Tmpl>;
|
|
42
|
+
/** "one" returns the first match or null; "page" returns a Page from $args.page; "list" returns all matches */
|
|
43
|
+
mode: "one" | "page" | "list";
|
|
44
|
+
pageArg?: string;
|
|
45
|
+
}
|
|
46
|
+
export interface FieldSpec {
|
|
47
|
+
from: string;
|
|
48
|
+
/** parent field to match against row field: parent[key] == row[match] */
|
|
49
|
+
key: string;
|
|
50
|
+
match: string;
|
|
51
|
+
mode: "one" | "page" | "list";
|
|
52
|
+
pageArg?: string;
|
|
53
|
+
}
|
|
54
|
+
export interface CommandSpec {
|
|
55
|
+
/** conditions evaluated in order; the first one that matches throws */
|
|
56
|
+
fail?: Array<{
|
|
57
|
+
when: {
|
|
58
|
+
field: string;
|
|
59
|
+
op: "lt" | "eq" | "missing";
|
|
60
|
+
value?: Tmpl;
|
|
61
|
+
from?: string;
|
|
62
|
+
where?: Record<string, Tmpl>;
|
|
63
|
+
};
|
|
64
|
+
type?: string;
|
|
65
|
+
code?: string;
|
|
66
|
+
data?: Record<string, Tmpl>;
|
|
67
|
+
message?: string;
|
|
68
|
+
}>;
|
|
69
|
+
insert?: {
|
|
70
|
+
into: string;
|
|
71
|
+
row: Record<string, Tmpl>;
|
|
72
|
+
idPrefix?: string;
|
|
73
|
+
};
|
|
74
|
+
/** `merge` copies the keys present in a template object (partial updates); `version` names a @version field to check and bump */
|
|
75
|
+
update?: {
|
|
76
|
+
table: string;
|
|
77
|
+
where: Record<string, Tmpl>;
|
|
78
|
+
set?: Record<string, Tmpl | {
|
|
79
|
+
$add: Tmpl;
|
|
80
|
+
} | {
|
|
81
|
+
$sub: Tmpl;
|
|
82
|
+
}>;
|
|
83
|
+
merge?: Tmpl;
|
|
84
|
+
version?: string;
|
|
85
|
+
};
|
|
86
|
+
/** which row to return: "inserted" | "updated" */
|
|
87
|
+
returns: "inserted" | "updated";
|
|
88
|
+
patch?: PatchOp[];
|
|
89
|
+
emit?: Array<{
|
|
90
|
+
event: string;
|
|
91
|
+
payload: Record<string, Tmpl>;
|
|
92
|
+
}>;
|
|
93
|
+
}
|
|
94
|
+
export interface StreamSpec {
|
|
95
|
+
/** yields these items in order, then ends */
|
|
96
|
+
items: Array<Record<string, unknown>>;
|
|
97
|
+
}
|
|
98
|
+
export interface FixtureStore {
|
|
99
|
+
tables: Record<string, Array<Record<string, unknown>>>;
|
|
100
|
+
calls: Record<string, number>;
|
|
101
|
+
nextId: number;
|
|
102
|
+
}
|
|
103
|
+
export declare function seedStore(f: Fixture): FixtureStore;
|
|
104
|
+
export declare function fixtureResolvers(f: Fixture, store: FixtureStore): Resolvers;
|
|
105
|
+
/** Group frames by op id (batch-level frames under key "batch"), preserving per-op order. */
|
|
106
|
+
export declare function groupFrames(frames: Frame[]): Record<string, Frame[]>;
|
|
107
|
+
export {};
|
package/fixture.js
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Conformance fixture format and the declarative resolver interpreter.
|
|
3
|
+
* Both runtimes (TS, Kotlin) implement this interpreter so fixtures need no code.
|
|
4
|
+
*/
|
|
5
|
+
import { RayfoldError, ok } from "@rayfold/server";
|
|
6
|
+
export function seedStore(f) {
|
|
7
|
+
return { tables: structuredClone(f.data), calls: {}, nextId: 1 };
|
|
8
|
+
}
|
|
9
|
+
function tmpl(v, env) {
|
|
10
|
+
if (typeof v === "string" && v.startsWith("$")) {
|
|
11
|
+
const [root, ...path] = v.slice(1).split(".");
|
|
12
|
+
let cur = env[root];
|
|
13
|
+
for (const p of path)
|
|
14
|
+
cur = cur && typeof cur === "object" ? cur[p] : undefined;
|
|
15
|
+
return cur === undefined ? null : cur;
|
|
16
|
+
}
|
|
17
|
+
if (Array.isArray(v))
|
|
18
|
+
return v.map((x) => tmpl(x, env));
|
|
19
|
+
if (v && typeof v === "object") {
|
|
20
|
+
const o = {};
|
|
21
|
+
for (const [k, x] of Object.entries(v))
|
|
22
|
+
o[k] = tmpl(x, env);
|
|
23
|
+
return o;
|
|
24
|
+
}
|
|
25
|
+
return v;
|
|
26
|
+
}
|
|
27
|
+
function matches(row, where, env) {
|
|
28
|
+
if (!where)
|
|
29
|
+
return true;
|
|
30
|
+
return Object.entries(where).every(([k, v]) => {
|
|
31
|
+
const want = tmpl(v, env);
|
|
32
|
+
return want === null ? true : String(row[k]) === String(want);
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
function page(rows, p) {
|
|
36
|
+
const first = p?.first ?? 20;
|
|
37
|
+
let start = 0;
|
|
38
|
+
if (p?.after) {
|
|
39
|
+
const i = rows.findIndex((r) => String(r["id"]) === p.after);
|
|
40
|
+
start = i < 0 ? rows.length : i + 1;
|
|
41
|
+
}
|
|
42
|
+
const items = rows.slice(start, start + first);
|
|
43
|
+
return { items, cursor: items.length ? String(items[items.length - 1]["id"]) : null, hasMore: start + first < rows.length, total: rows.length };
|
|
44
|
+
}
|
|
45
|
+
function count(store, k) {
|
|
46
|
+
store.calls[k] = (store.calls[k] ?? 0) + 1;
|
|
47
|
+
}
|
|
48
|
+
export function fixtureResolvers(f, store) {
|
|
49
|
+
const r = { Query: {}, Command: {}, Stream: {} };
|
|
50
|
+
const table = (name) => store.tables[name] ?? (store.tables[name] = []);
|
|
51
|
+
for (const [name, spec] of Object.entries(f.resolvers.Query ?? {})) {
|
|
52
|
+
r.Query[name] = (args, ctx) => {
|
|
53
|
+
count(store, `Query.${name}`);
|
|
54
|
+
const env = { args, viewer: ctx.viewer };
|
|
55
|
+
const rows = table(spec.from).filter((row) => matches(row, spec.where, env));
|
|
56
|
+
if (spec.mode === "one")
|
|
57
|
+
return rows[0] ?? null;
|
|
58
|
+
if (spec.mode === "list")
|
|
59
|
+
return rows;
|
|
60
|
+
return page(rows, args[spec.pageArg ?? "page"]);
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
for (const [type, fields] of Object.entries(f.resolvers.fields ?? {})) {
|
|
64
|
+
r[type] = {};
|
|
65
|
+
for (const [field, spec] of Object.entries(fields)) {
|
|
66
|
+
r[type][field] = ((parents, args) => {
|
|
67
|
+
count(store, `${type}.${field}`);
|
|
68
|
+
const rows = table(spec.from);
|
|
69
|
+
return parents.map((p) => {
|
|
70
|
+
const hits = rows.filter((row) => String(row[spec.match]) === String(p[spec.key]));
|
|
71
|
+
if (spec.mode === "one")
|
|
72
|
+
return hits[0] ?? null;
|
|
73
|
+
if (spec.mode === "list")
|
|
74
|
+
return hits;
|
|
75
|
+
return page(hits, args[spec.pageArg ?? "page"]);
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
for (const [name, spec] of Object.entries(f.resolvers.Command ?? {})) {
|
|
81
|
+
r.Command[name] = (args, ctx) => {
|
|
82
|
+
count(store, `Command.${name}`);
|
|
83
|
+
const env = { args, viewer: ctx.viewer };
|
|
84
|
+
for (const fail of spec.fail ?? []) {
|
|
85
|
+
const w = fail.when;
|
|
86
|
+
let subject;
|
|
87
|
+
if (w.from)
|
|
88
|
+
subject = table(w.from).find((row) => matches(row, w.where, env));
|
|
89
|
+
const actual = subject ? subject[w.field] : tmpl(`$args.${w.field}`, env);
|
|
90
|
+
const want = tmpl(w.value, { ...env, row: subject });
|
|
91
|
+
const hit = w.op === "missing" ? subject === undefined : w.op === "eq" ? String(actual) === String(want) : Number(actual) < Number(want);
|
|
92
|
+
if (hit) {
|
|
93
|
+
const data = tmpl(fail.data ?? {}, { ...env, row: subject });
|
|
94
|
+
if (fail.type)
|
|
95
|
+
throw RayfoldError.domain(fail.type, data, fail.message ?? fail.type);
|
|
96
|
+
throw new RayfoldError((fail.code ?? "failed_precondition"), fail.message ?? fail.code ?? "failed");
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
let inserted;
|
|
100
|
+
let updated;
|
|
101
|
+
if (spec.update) {
|
|
102
|
+
updated = table(spec.update.table).find((row) => matches(row, spec.update.where, env));
|
|
103
|
+
if (!updated)
|
|
104
|
+
throw new RayfoldError("not_found", "row not found");
|
|
105
|
+
const vf = spec.update.version;
|
|
106
|
+
if (vf)
|
|
107
|
+
ctx.checkVersion(`${spec.update.table}:${String(updated["id"])}`, updated[vf], { ...updated });
|
|
108
|
+
const target = ctx.simulate ? { ...updated } : updated;
|
|
109
|
+
if (spec.update.merge !== undefined) {
|
|
110
|
+
const src = tmpl(spec.update.merge, env);
|
|
111
|
+
if (src && typeof src === "object" && !Array.isArray(src))
|
|
112
|
+
Object.assign(target, src);
|
|
113
|
+
}
|
|
114
|
+
if (vf)
|
|
115
|
+
target[vf] = Number(target[vf]) + 1;
|
|
116
|
+
for (const [k, v] of Object.entries(spec.update.set ?? {})) {
|
|
117
|
+
if (v && typeof v === "object" && "$add" in v)
|
|
118
|
+
target[k] = Number(target[k]) + Number(tmpl(v.$add, env));
|
|
119
|
+
else if (v && typeof v === "object" && "$sub" in v)
|
|
120
|
+
target[k] = Number(target[k]) - Number(tmpl(v.$sub, env));
|
|
121
|
+
else
|
|
122
|
+
target[k] = tmpl(v, env);
|
|
123
|
+
}
|
|
124
|
+
updated = target;
|
|
125
|
+
}
|
|
126
|
+
if (spec.insert) {
|
|
127
|
+
inserted = { id: `${spec.insert.idPrefix ?? "n"}${store.nextId++}`, ...tmpl(spec.insert.row, env) };
|
|
128
|
+
if (!ctx.simulate)
|
|
129
|
+
table(spec.insert.into).push(inserted);
|
|
130
|
+
}
|
|
131
|
+
const result = spec.returns === "inserted" ? inserted : updated;
|
|
132
|
+
const rowEnv = { ...env, row: result };
|
|
133
|
+
const extra = {};
|
|
134
|
+
if (spec.patch)
|
|
135
|
+
extra.patch = tmpl(spec.patch, rowEnv);
|
|
136
|
+
if (spec.emit)
|
|
137
|
+
extra.emit = spec.emit.map((e) => ({ event: e.event, payload: tmpl(e.payload, rowEnv) }));
|
|
138
|
+
return ok(result, extra);
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
for (const [name, spec] of Object.entries(f.resolvers.Stream ?? {})) {
|
|
142
|
+
r.Stream[name] = () => {
|
|
143
|
+
count(store, `Stream.${name}`);
|
|
144
|
+
return (async function* () {
|
|
145
|
+
for (const it of spec.items)
|
|
146
|
+
yield it;
|
|
147
|
+
})();
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
return r;
|
|
151
|
+
}
|
|
152
|
+
/** Group frames by op id (batch-level frames under key "batch"), preserving per-op order. */
|
|
153
|
+
export function groupFrames(frames) {
|
|
154
|
+
const out = {};
|
|
155
|
+
for (const f of frames) {
|
|
156
|
+
const k = "id" in f ? String(f.id) : "batch";
|
|
157
|
+
(out[k] ??= []).push(f);
|
|
158
|
+
}
|
|
159
|
+
return out;
|
|
160
|
+
}
|
|
161
|
+
//# sourceMappingURL=fixture.js.map
|
package/fixture.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fixture.js","sourceRoot":"","sources":["../src/fixture.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,YAAY,EAAE,EAAE,EAAuF,MAAM,iBAAiB,CAAC;AAyExI,MAAM,UAAU,SAAS,CAAC,CAAU;IAClC,OAAO,EAAE,MAAM,EAAE,eAAe,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC;AACnE,CAAC;AAED,SAAS,IAAI,CAAC,CAAO,EAAE,GAA0E;IAC/F,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;QAC/C,MAAM,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAC9C,IAAI,GAAG,GAAa,GAA+B,CAAC,IAAK,CAAC,CAAC;QAC3D,KAAK,MAAM,CAAC,IAAI,IAAI;YAAE,GAAG,GAAG,GAAG,IAAI,OAAO,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAE,GAA+B,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;QAC7G,OAAO,GAAG,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG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AC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;QAC7C,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAC1B,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["/**\n * Conformance fixture format and the declarative resolver interpreter.\n * Both runtimes (TS, Kotlin) implement this interpreter so fixtures need no code.\n */\nimport { RayfoldError, ok, type Frame, type PatchOp, type RayfoldContext, type RequestEnvelope, type Resolvers } from \"@rayfold/server\";\n\nexport interface Fixture {\n name: string;\n /** `.rayfold` schema text */\n schema: string;\n /** rows per type name; re-seeded before every case */\n data: Record<string, Array<Record<string, unknown>>>;\n resolvers: {\n Query?: Record<string, QuerySpec>;\n Command?: Record<string, CommandSpec>;\n Stream?: Record<string, StreamSpec>;\n fields?: Record<string, Record<string, FieldSpec>>; // \"Type\": { \"field\": spec }\n };\n options?: { budget?: number; maxDepth?: number; trustedShapes?: boolean; registerShapes?: string[] };\n cases: Case[];\n}\n\nexport interface Case {\n name: string;\n viewer?: unknown;\n request: RequestEnvelope;\n /** Expected frames. Frames of different ops may interleave; per-op order must match. */\n frames: Frame[];\n /** Expected loader call counts, e.g. { \"Book.author\": 1 } */\n calls?: Record<string, number>;\n /** Run this many times in sequence against the same store (idempotency cases). */\n repeat?: number;\n}\n\n/** Value templates: \"$args.x.y\", \"$viewer.id\", \"$parent.field\", \"$row.field\", literals. */\ntype Tmpl = unknown;\n\nexport interface QuerySpec {\n from: string;\n where?: Record<string, Tmpl>;\n /** \"one\" returns the first match or null; \"page\" returns a Page from $args.page; \"list\" returns all matches */\n mode: \"one\" | \"page\" | \"list\";\n pageArg?: string; // default \"page\"\n}\n\nexport interface FieldSpec {\n from: string;\n /** parent field to match against row field: parent[key] == row[match] */\n key: string;\n match: string;\n mode: \"one\" | \"page\" | \"list\";\n pageArg?: string;\n}\n\nexport interface CommandSpec {\n /** conditions evaluated in order; the first one that matches throws */\n fail?: Array<{ when: { field: string; op: \"lt\" | \"eq\" | \"missing\"; value?: Tmpl; from?: string; where?: Record<string, Tmpl> }; type?: string; code?: string; data?: Record<string, Tmpl>; message?: string }>;\n insert?: { into: string; row: Record<string, Tmpl>; idPrefix?: string };\n /** `merge` copies the keys present in a template object (partial updates); `version` names a @version field to check and bump */\n update?: { table: string; where: Record<string, Tmpl>; set?: Record<string, Tmpl | { $add: Tmpl } | { $sub: Tmpl }>; merge?: Tmpl; version?: string };\n /** which row to return: \"inserted\" | \"updated\" */\n returns: \"inserted\" | \"updated\";\n patch?: PatchOp[];\n emit?: Array<{ event: string; payload: Record<string, Tmpl> }>;\n}\n\nexport interface StreamSpec {\n /** yields these items in order, then ends */\n items: Array<Record<string, unknown>>;\n}\n\nexport interface FixtureStore {\n tables: Record<string, Array<Record<string, unknown>>>;\n calls: Record<string, number>;\n nextId: number;\n}\n\nexport function seedStore(f: Fixture): FixtureStore {\n return { tables: structuredClone(f.data), calls: {}, nextId: 1 };\n}\n\nfunction tmpl(v: Tmpl, env: { args?: unknown; viewer?: unknown; parent?: unknown; row?: unknown }): unknown {\n if (typeof v === \"string\" && v.startsWith(\"$\")) {\n const [root, ...path] = v.slice(1).split(\".\");\n let cur: unknown = (env as Record<string, unknown>)[root!];\n for (const p of path) cur = cur && typeof cur === \"object\" ? (cur as Record<string, unknown>)[p] : undefined;\n return cur === undefined ? null : cur;\n }\n if (Array.isArray(v)) return v.map((x) => tmpl(x, env));\n if (v && typeof v === \"object\") {\n const o: Record<string, unknown> = {};\n for (const [k, x] of Object.entries(v)) o[k] = tmpl(x, env);\n return o;\n }\n return v;\n}\n\nfunction matches(row: Record<string, unknown>, where: Record<string, Tmpl> | undefined, env: Parameters<typeof tmpl>[1]): boolean {\n if (!where) return true;\n return Object.entries(where).every(([k, v]) => {\n const want = tmpl(v, env);\n return want === null ? true : String(row[k]) === String(want);\n });\n}\n\nfunction page(rows: Array<Record<string, unknown>>, p: { first: number; after: string | null } | undefined) {\n const first = p?.first ?? 20;\n let start = 0;\n if (p?.after) {\n const i = rows.findIndex((r) => String(r[\"id\"]) === p.after);\n start = i < 0 ? rows.length : i + 1;\n }\n const items = rows.slice(start, start + first);\n return { items, cursor: items.length ? String(items[items.length - 1]![\"id\"]) : null, hasMore: start + first < rows.length, total: rows.length };\n}\n\nfunction count(store: FixtureStore, k: string): void {\n store.calls[k] = (store.calls[k] ?? 0) + 1;\n}\n\nexport function fixtureResolvers(f: Fixture, store: FixtureStore): Resolvers {\n const r: Resolvers = { Query: {}, Command: {}, Stream: {} };\n const table = (name: string) => store.tables[name] ?? (store.tables[name] = []);\n\n for (const [name, spec] of Object.entries(f.resolvers.Query ?? {})) {\n r.Query![name] = (args: Record<string, unknown>, ctx: RayfoldContext<never>) => {\n count(store, `Query.${name}`);\n const env = { args, viewer: ctx.viewer };\n const rows = table(spec.from).filter((row) => matches(row, spec.where, env));\n if (spec.mode === \"one\") return rows[0] ?? null;\n if (spec.mode === \"list\") return rows;\n return page(rows, args[spec.pageArg ?? \"page\"] as never);\n };\n }\n for (const [type, fields] of Object.entries(f.resolvers.fields ?? {})) {\n r[type] = {};\n for (const [field, spec] of Object.entries(fields)) {\n r[type]![field] = ((parents: Array<Record<string, unknown>>, args: Record<string, unknown>) => {\n count(store, `${type}.${field}`);\n const rows = table(spec.from);\n return parents.map((p) => {\n const hits = rows.filter((row) => String(row[spec.match]) === String(p[spec.key]));\n if (spec.mode === \"one\") return hits[0] ?? null;\n if (spec.mode === \"list\") return hits;\n return page(hits, args[spec.pageArg ?? \"page\"] as never);\n });\n }) as never;\n }\n }\n for (const [name, spec] of Object.entries(f.resolvers.Command ?? {})) {\n r.Command![name] = (args: Record<string, unknown>, ctx: RayfoldContext<never>) => {\n count(store, `Command.${name}`);\n const env = { args, viewer: ctx.viewer };\n for (const fail of spec.fail ?? []) {\n const w = fail.when;\n let subject: Record<string, unknown> | undefined;\n if (w.from) subject = table(w.from).find((row) => matches(row, w.where, env));\n const actual = subject ? subject[w.field] : tmpl(`$args.${w.field}`, env);\n const want = tmpl(w.value, { ...env, row: subject });\n const hit = w.op === \"missing\" ? subject === undefined : w.op === \"eq\" ? String(actual) === String(want) : Number(actual) < Number(want);\n if (hit) {\n const data = tmpl(fail.data ?? {}, { ...env, row: subject }) as Record<string, unknown>;\n if (fail.type) throw RayfoldError.domain(fail.type, data, fail.message ?? fail.type);\n throw new RayfoldError((fail.code ?? \"failed_precondition\") as never, fail.message ?? fail.code ?? \"failed\");\n }\n }\n let inserted: Record<string, unknown> | undefined;\n let updated: Record<string, unknown> | undefined;\n if (spec.update) {\n updated = table(spec.update.table).find((row) => matches(row, spec.update!.where, env));\n if (!updated) throw new RayfoldError(\"not_found\", \"row not found\");\n const vf = spec.update.version;\n if (vf) ctx.checkVersion(`${spec.update.table}:${String(updated[\"id\"])}`, updated[vf], { ...updated });\n const target = ctx.simulate ? { ...updated } : updated;\n if (spec.update.merge !== undefined) {\n const src = tmpl(spec.update.merge, env);\n if (src && typeof src === \"object\" && !Array.isArray(src)) Object.assign(target, src);\n }\n if (vf) target[vf] = Number(target[vf]) + 1;\n for (const [k, v] of Object.entries(spec.update.set ?? {})) {\n if (v && typeof v === \"object\" && \"$add\" in (v as object)) target[k] = Number(target[k]) + Number(tmpl((v as { $add: Tmpl }).$add, env));\n else if (v && typeof v === \"object\" && \"$sub\" in (v as object)) target[k] = Number(target[k]) - Number(tmpl((v as { $sub: Tmpl }).$sub, env));\n else target[k] = tmpl(v, env);\n }\n updated = target;\n }\n if (spec.insert) {\n inserted = { id: `${spec.insert.idPrefix ?? \"n\"}${store.nextId++}`, ...(tmpl(spec.insert.row, env) as Record<string, unknown>) };\n if (!ctx.simulate) table(spec.insert.into).push(inserted);\n }\n const result = spec.returns === \"inserted\" ? inserted : updated;\n const rowEnv = { ...env, row: result };\n const extra: { patch?: PatchOp[]; emit?: Array<{ event: string; payload: Record<string, unknown> }> } = {};\n if (spec.patch) extra.patch = tmpl(spec.patch, rowEnv) as PatchOp[];\n if (spec.emit) extra.emit = spec.emit.map((e) => ({ event: e.event, payload: tmpl(e.payload, rowEnv) as Record<string, unknown> }));\n return ok(result, extra);\n };\n }\n for (const [name, spec] of Object.entries(f.resolvers.Stream ?? {})) {\n r.Stream![name] = () => {\n count(store, `Stream.${name}`);\n return (async function* () {\n for (const it of spec.items) yield it;\n })();\n };\n }\n return r;\n}\n\n/** Group frames by op id (batch-level frames under key \"batch\"), preserving per-op order. */\nexport function groupFrames(frames: Frame[]): Record<string, Frame[]> {\n const out: Record<string, Frame[]> = {};\n for (const f of frames) {\n const k = \"id\" in f ? String(f.id) : \"batch\";\n (out[k] ??= []).push(f);\n }\n return out;\n}\n"]}
|