@nxara/olio-core 0.0.0-stage → 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 +21 -0
- package/README.md +7 -2
- package/dist/files.d.ts +5 -0
- package/dist/files.d.ts.map +1 -0
- package/dist/files.js +43 -0
- package/dist/files.js.map +1 -0
- package/dist/index.d.ts +40 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/package.json +45 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Nxara contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @nxara/olio-core
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The contracts the Nxara packages share, so none of them has to depend on `@nxara/olio`. Apps don't import it: `@nxara/olio` re-exports the types, and `@nxara/olio-tools` the loaders.
|
|
4
|
+
|
|
5
|
+
- **`Olio`**: the registration interface. Apps still augment it through olio (`declare module "@nxara/olio" { interface Olio { ... } }`), which reaches it here; `@nxara/olio-http` reads the registered `ctx` as `Context`.
|
|
6
|
+
- **Module shapes**: `OlioModule`, `OlioFeature`, `ResolverMap`, `StoredMiddleware` (olio's `MiddlewareMap` is the typed view), and the `LoadedResolvers` / `LoadedEnums` brands that `@nxara/olio-tools` returns.
|
|
7
|
+
- **`TypeSource`, `Pattern`**.
|
|
8
|
+
- **`@nxara/olio-core/files`** (Node only, so `node:fs` stays out of olio's imports): `matchFiles(patterns)` (sorted; a pattern matching nothing throws) and `loadGraphQLFile(file)` (`.graphql` / `.gql`, or a `.ts` / `.js` default export of GraphQL source or a `DocumentNode`; errors carry `file:line:col`). `@nxara/olio-tools` and `@nxara/olio-codegen` load SDL and operations through it, so they read the same files the same way.
|
package/dist/files.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type DocumentNode } from "graphql";
|
|
2
|
+
import type { Pattern } from "./index.js";
|
|
3
|
+
export declare function matchFiles(patterns: readonly Pattern[]): Promise<string[]>;
|
|
4
|
+
export declare function loadGraphQLFile(file: string): Promise<DocumentNode | undefined>;
|
|
5
|
+
//# sourceMappingURL=files.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"files.d.ts","sourceRoot":"","sources":["../src/files.ts"],"names":[],"mappings":"AAIA,OAAO,EAAiB,KAAK,YAAY,EAAE,MAAM,SAAS,CAAC;AAE3D,OAAO,KAAK,EAAE,OAAO,EAAc,MAAM,YAAY,CAAC;AAOtD,wBAAsB,UAAU,CAC9B,QAAQ,EAAE,SAAS,OAAO,EAAE,GAC3B,OAAO,CAAC,MAAM,EAAE,CAAC,CASnB;AAwBD,wBAAsB,eAAe,CACnC,IAAI,EAAE,MAAM,GACX,OAAO,CAAC,YAAY,GAAG,SAAS,CAAC,CAkBnC"}
|
package/dist/files.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { globSync, readFileSync } from "node:fs";
|
|
2
|
+
import { extname } from "node:path";
|
|
3
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
4
|
+
import { parse, Source } from "graphql";
|
|
5
|
+
const COMMENT = /#[^\n]*/g;
|
|
6
|
+
export async function matchFiles(patterns) {
|
|
7
|
+
const paths = patterns.map((p) => typeof p === "string" ? p : fileURLToPath(p));
|
|
8
|
+
const matches = paths.map((path) => globSync(path));
|
|
9
|
+
for (const [i, found] of matches.entries()) {
|
|
10
|
+
if (found.length === 0)
|
|
11
|
+
throw new Error(`No files match "${paths[i]}"`);
|
|
12
|
+
}
|
|
13
|
+
return [...new Set(matches.flat())].sort();
|
|
14
|
+
}
|
|
15
|
+
function parseFile(source, file) {
|
|
16
|
+
try {
|
|
17
|
+
return parse(new Source(source, file));
|
|
18
|
+
}
|
|
19
|
+
catch (error) {
|
|
20
|
+
const { message, locations } = error;
|
|
21
|
+
const loc = locations?.[0];
|
|
22
|
+
throw new Error(`${loc ? `${file}:${loc.line}:${loc.column}` : file}: ${message}`);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export async function loadGraphQLFile(file) {
|
|
26
|
+
const ext = extname(file);
|
|
27
|
+
if (ext === ".graphql" || ext === ".gql") {
|
|
28
|
+
const source = readFileSync(file, "utf8");
|
|
29
|
+
return source.replace(COMMENT, "").trim() === ""
|
|
30
|
+
? undefined
|
|
31
|
+
: parseFile(source, file);
|
|
32
|
+
}
|
|
33
|
+
if (ext === ".ts" || ext === ".js") {
|
|
34
|
+
const mod = (await import(pathToFileURL(file).href));
|
|
35
|
+
if (!mod.default)
|
|
36
|
+
return undefined;
|
|
37
|
+
return typeof mod.default === "string"
|
|
38
|
+
? parseFile(mod.default, file)
|
|
39
|
+
: mod.default;
|
|
40
|
+
}
|
|
41
|
+
throw new Error(`Cannot load GraphQL from "${file}" (unknown extension)`);
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=files.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"files.js","sourceRoot":"","sources":["../src/files.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACjD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAExD,OAAO,EAAE,KAAK,EAAE,MAAM,EAAqB,MAAM,SAAS,CAAC;AAI3D,MAAM,OAAO,GAAG,UAAU,CAAC;AAK3B,MAAM,CAAC,KAAK,UAAU,UAAU,CAC9B,QAA4B;IAE5B,MAAM,KAAK,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAC/B,OAAO,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,CAC7C,CAAC;IACF,MAAM,OAAO,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC;IACpD,KAAK,MAAM,CAAC,CAAC,EAAE,KAAK,CAAC,IAAI,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC;QAC3C,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;YAAE,MAAM,IAAI,KAAK,CAAC,mBAAmB,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;IAC1E,CAAC;IACD,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC,C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,QAAQ;YACpC,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,OAAO,EAAE,IAAI,CAAC;YAC9B,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC;IAClB,CAAC;IACD,MAAM,IAAI,KAAK,CAAC,6BAA6B,IAAI,uBAAuB,CAAC,CAAC;AAC5E,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { DocumentNode } from "graphql";
|
|
2
|
+
export interface Olio {
|
|
3
|
+
}
|
|
4
|
+
export type Context = Olio extends {
|
|
5
|
+
ctx: infer C;
|
|
6
|
+
} ? C : unknown;
|
|
7
|
+
export type TypeSource = string | DocumentNode;
|
|
8
|
+
export type Pattern = string | URL;
|
|
9
|
+
export type ResolverMap = Record<string, object>;
|
|
10
|
+
export type StoredMiddleware = Partial<Record<string, Partial<Record<string, readonly unknown[]>>>>;
|
|
11
|
+
declare const loaded: unique symbol;
|
|
12
|
+
export type LoadedResolvers = {
|
|
13
|
+
readonly [type: string]: never;
|
|
14
|
+
} & {
|
|
15
|
+
readonly [loaded]: true;
|
|
16
|
+
};
|
|
17
|
+
declare const loadedEnums: unique symbol;
|
|
18
|
+
export type LoadedEnums = {
|
|
19
|
+
readonly [type: string]: never;
|
|
20
|
+
} & {
|
|
21
|
+
readonly [loadedEnums]: true;
|
|
22
|
+
};
|
|
23
|
+
export interface OlioModule {
|
|
24
|
+
readonly id: string;
|
|
25
|
+
readonly typeDefs: readonly DocumentNode[];
|
|
26
|
+
readonly resolvers: readonly ResolverMap[];
|
|
27
|
+
readonly enums: ResolverMap;
|
|
28
|
+
readonly middleware: StoredMiddleware;
|
|
29
|
+
readonly features: readonly OlioFeature[];
|
|
30
|
+
}
|
|
31
|
+
export interface OlioFeature {
|
|
32
|
+
readonly module: string;
|
|
33
|
+
readonly id: string;
|
|
34
|
+
readonly typeDefs: readonly DocumentNode[];
|
|
35
|
+
readonly resolvers: readonly ResolverMap[];
|
|
36
|
+
readonly enums: ResolverMap;
|
|
37
|
+
readonly middleware: StoredMiddleware;
|
|
38
|
+
}
|
|
39
|
+
export {};
|
|
40
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAkB5C,MAAM,WAAW,IAAI;CAAG;AAGxB,MAAM,MAAM,OAAO,GAAG,IAAI,SAAS;IAAE,GAAG,EAAE,MAAM,CAAC,CAAA;CAAE,GAAG,CAAC,GAAG,OAAO,CAAC;AAElE,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,YAAY,CAAC;AAG/C,MAAM,MAAM,OAAO,GAAG,MAAM,GAAG,GAAG,CAAC;AAEnC,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAGjD,MAAM,MAAM,gBAAgB,GAAG,OAAO,CACpC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,OAAO,EAAE,CAAC,CAAC,CAAC,CAC5D,CAAC;AAEF,OAAO,CAAC,MAAM,MAAM,EAAE,OAAO,MAAM,CAAC;AASpC,MAAM,MAAM,eAAe,GAAG;IAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,GAAG,KAAK,CAAA;CAAE,GAAG;IACjE,QAAQ,CAAC,CAAC,MAAM,CAAC,EAAE,IAAI,CAAC;CACzB,CAAC;AAEF,OAAO,CAAC,MAAM,WAAW,EAAE,OAAO,MAAM,CAAC;AAMzC,MAAM,MAAM,WAAW,GAAG;IAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,GAAG,KAAK,CAAA;CAAE,GAAG;IAC7D,QAAQ,CAAC,CAAC,WAAW,CAAC,EAAE,IAAI,CAAC;CAC9B,CAAC;AAGF,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,QAAQ,EAAE,SAAS,YAAY,EAAE,CAAC;IAC3C,QAAQ,CAAC,SAAS,EAAE,SAAS,WAAW,EAAE,CAAC;IAC3C,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC;IAC5B,QAAQ,CAAC,UAAU,EAAE,gBAAgB,CAAC;IACtC,QAAQ,CAAC,QAAQ,EAAE,SAAS,WAAW,EAAE,CAAC;CAC3C;AAGD,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,QAAQ,EAAE,SAAS,YAAY,EAAE,CAAC;IAC3C,QAAQ,CAAC,SAAS,EAAE,SAAS,WAAW,EAAE,CAAC;IAC3C,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC;IAC5B,QAAQ,CAAC,UAAU,EAAE,gBAAgB,CAAC;CACvC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,6 +1,47 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nxara/olio-core",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Contracts shared by the Nxara packages. Apps import from @nxara/olio and @nxara/olio-tools instead.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"graphql",
|
|
7
|
+
"nxara"
|
|
8
|
+
],
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git+https://github.com/nxara-hub/olio.git",
|
|
13
|
+
"directory": "packages/core"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"type": "module",
|
|
19
|
+
"sideEffects": false,
|
|
20
|
+
"exports": {
|
|
21
|
+
".": {
|
|
22
|
+
"types": "./dist/index.d.ts",
|
|
23
|
+
"default": "./dist/index.js"
|
|
24
|
+
},
|
|
25
|
+
"./files": {
|
|
26
|
+
"types": "./dist/files.d.ts",
|
|
27
|
+
"default": "./dist/files.js"
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"publishConfig": {
|
|
31
|
+
"access": "public"
|
|
32
|
+
},
|
|
33
|
+
"scripts": {
|
|
34
|
+
"build": "tsc",
|
|
35
|
+
"test": "bun test",
|
|
36
|
+
"check-types": "tsc -p tsconfig.test.json"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"graphql": "^16.14.2"
|
|
40
|
+
},
|
|
41
|
+
"peerDependencies": {
|
|
42
|
+
"graphql": "^16.13.0"
|
|
43
|
+
},
|
|
44
|
+
"engines": {
|
|
45
|
+
"node": ">=22"
|
|
46
|
+
}
|
|
47
|
+
}
|