@plurnk/plurnk-mimetypes-application-json 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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 PossumTech Laboratories
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 ADDED
@@ -0,0 +1,29 @@
1
+ # @plurnk/plurnk-mimetypes-application-json
2
+
3
+ `application/json` mimetype handler for the [plurnk](https://github.com/plurnk) ecosystem.
4
+
5
+ ## install
6
+
7
+ ```
8
+ npm install @plurnk/plurnk-mimetypes-application-json
9
+ ```
10
+
11
+ plurnk-service discovers this handler automatically via its `plurnk.kind: "mimetype"` declaration.
12
+
13
+ ## what it does
14
+
15
+ - `validate(content)` throws on malformed JSON (via `JSON.parse`). Per framework error policy, this error propagates to the caller as a contract violation.
16
+ - `extract(content)` returns the document's top-level keys as `field` symbols. Nested keys are out of scope; a JSON document's "API surface" is its top level. Line numbers come from a single-pass scan of the raw source.
17
+ - Array and scalar JSON roots have no named top-level keys → empty `Symbol[]`.
18
+
19
+ ## development
20
+
21
+ ```
22
+ npm install
23
+ npm run build
24
+ npm test
25
+ ```
26
+
27
+ ## license
28
+
29
+ MIT.
@@ -0,0 +1,7 @@
1
+ import { BaseHandler } from "@plurnk/plurnk-mimetypes";
2
+ import type { MimeSymbol } from "@plurnk/plurnk-mimetypes";
3
+ export default class ApplicationJson extends BaseHandler {
4
+ validate(content: string): void;
5
+ extract(content: string): MimeSymbol[];
6
+ }
7
+ //# sourceMappingURL=ApplicationJson.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ApplicationJson.d.ts","sourceRoot":"","sources":["../src/ApplicationJson.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAmB3D,MAAM,CAAC,OAAO,OAAO,eAAgB,SAAQ,WAAW;IACpD,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAI/B,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,UAAU,EAAE;CAoBzC"}
@@ -0,0 +1,64 @@
1
+ import { BaseHandler } from "@plurnk/plurnk-mimetypes";
2
+ // application/json handler. Two responsibilities beyond BaseHandler defaults:
3
+ //
4
+ // 1. validate(content) throws on malformed JSON. Per framework error policy
5
+ // (SPEC §7), validate errors propagate through Mimetypes.process to the
6
+ // caller — this is the contract for "the consumer asserted this is JSON,
7
+ // but it isn't."
8
+ //
9
+ // 2. extract(content) returns the document's top-level keys as `field`
10
+ // symbols. Matches the legacy ANTLR-backed policy: a JSON document's
11
+ // "API surface" is its top-level keys; nested structure is recursive
12
+ // and out of scope for the structural outline. Array and scalar roots
13
+ // have no named top-level keys → empty Symbol[].
14
+ //
15
+ // Line numbers are derived from a single-pass scan of the raw source — JSON.parse
16
+ // itself doesn't preserve positions. The scan is approximate (a `"key":` pattern
17
+ // inside a string value could in principle be mis-matched as a key) but accurate
18
+ // for well-formed documents in practical use.
19
+ export default class ApplicationJson extends BaseHandler {
20
+ validate(content) {
21
+ JSON.parse(content);
22
+ }
23
+ extract(content) {
24
+ let parsed;
25
+ try {
26
+ parsed = JSON.parse(content);
27
+ }
28
+ catch {
29
+ return [];
30
+ }
31
+ if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
32
+ return [];
33
+ }
34
+ const keys = Object.keys(parsed);
35
+ const lineMap = mapKeysToLines(content, keys);
36
+ return keys.map((name) => {
37
+ const line = lineMap.get(name) ?? 1;
38
+ return { name, kind: "field", line, endLine: line };
39
+ });
40
+ }
41
+ }
42
+ // Scan content for the first occurrence of each `"key":` pattern (key followed
43
+ // by optional whitespace and a colon, signaling a key position rather than a
44
+ // value). Returns key → 1-indexed line number.
45
+ function mapKeysToLines(content, keys) {
46
+ const result = new Map();
47
+ const remaining = new Set(keys);
48
+ if (remaining.size === 0)
49
+ return result;
50
+ const lines = content.split("\n");
51
+ for (let i = 0; i < lines.length && remaining.size > 0; i += 1) {
52
+ const line = lines[i];
53
+ for (const key of remaining) {
54
+ const escaped = key.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
55
+ const pattern = new RegExp(`"${escaped}"\\s*:`);
56
+ if (pattern.test(line)) {
57
+ result.set(key, i + 1);
58
+ remaining.delete(key);
59
+ }
60
+ }
61
+ }
62
+ return result;
63
+ }
64
+ //# sourceMappingURL=ApplicationJson.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ApplicationJson.js","sourceRoot":"","sources":["../src/ApplicationJson.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAGvD,8EAA8E;AAC9E,EAAE;AACF,8EAA8E;AAC9E,6EAA6E;AAC7E,8EAA8E;AAC9E,sBAAsB;AACtB,EAAE;AACF,yEAAyE;AACzE,0E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I,KAAK,CAAC;QAAE,OAAO,MAAM,CAAC;IAExC,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAClC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,IAAI,SAAS,CAAC,IAAI,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;QAC7D,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;QACtB,KAAK,MAAM,GAAG,IAAI,SAAS,EAAE,CAAC;YAC1B,MAAM,OAAO,GAAG,GAAG,CAAC,OAAO,CAAC,qBAAqB,EAAE,MAAM,CAAC,CAAC;YAC3D,MAAM,OAAO,GAAG,IAAI,MAAM,CAAC,IAAI,OAAO,QAAQ,CAAC,CAAC;YAChD,IAAI,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;gBACrB,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;gBACvB,SAAS,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YAC1B,CAAC;QACL,CAAC;IACL,CAAC;IACD,OAAO,MAAM,CAAC;AAClB,CAAC"}
@@ -0,0 +1,3 @@
1
+ export { default as ApplicationJson } from "./ApplicationJson.ts";
2
+ export { default } from "./ApplicationJson.ts";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAClE,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export { default as ApplicationJson } from "./ApplicationJson.js";
2
+ export { default } from "./ApplicationJson.js";
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAClE,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC"}
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "@plurnk/plurnk-mimetypes-application-json",
3
+ "version": "0.1.0",
4
+ "description": "application/json mimetype handler for plurnk-service.",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "publishConfig": {
8
+ "access": "public"
9
+ },
10
+ "engines": {
11
+ "node": ">=25"
12
+ },
13
+ "plurnk": {
14
+ "kind": "mimetype",
15
+ "name": "application/json",
16
+ "glyph": "📋",
17
+ "extensions": [".json"]
18
+ },
19
+ "exports": {
20
+ ".": {
21
+ "types": "./dist/index.d.ts",
22
+ "default": "./dist/index.js"
23
+ },
24
+ "./package.json": "./package.json"
25
+ },
26
+ "files": [
27
+ "dist/**/*",
28
+ "README.md"
29
+ ],
30
+ "scripts": {
31
+ "test:lint": "tsc --noEmit",
32
+ "test:unit": "node --test src/**/*.test.ts",
33
+ "test": "npm run test:lint && npm run test:unit",
34
+ "build:dist": "tsc -p tsconfig.build.json",
35
+ "build": "npm run build:dist",
36
+ "prepare": "npm run build"
37
+ },
38
+ "dependencies": {
39
+ "@plurnk/plurnk-mimetypes": "^0.1.1"
40
+ },
41
+ "devDependencies": {
42
+ "@types/node": "^25.8.0",
43
+ "typescript": "^6.0.3"
44
+ }
45
+ }