schemind 0.0.2

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) kpietraszko
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,28 @@
1
+ ![NPM Version](https://img.shields.io/npm/v/schemind)
2
+ ![Code Coverage](https://raw.githubusercontent.com/kpietraszko/schemind/refs/heads/main/badge.svg)
3
+
4
+ # schemind
5
+ Read and write to messages serialized as arrays (aka indexed keys) by defining a schema.
6
+
7
+ ## What?
8
+ TODO
9
+
10
+ ## Installation
11
+
12
+ ```shell
13
+ npm install schemind
14
+ ```
15
+
16
+ ## Usage
17
+ TODO
18
+
19
+ ## FAQ
20
+ TODO
21
+
22
+ ## Related work
23
+ * https://github.com/MessagePack-CSharp/MessagePack-CSharp#use-indexed-keys-instead-of-string-keys-contractless
24
+ * https://aarnott.github.io/Nerdbank.MessagePack/docs/customizing-serialization.html?q=indexed#serialize-objects-with-indexes-for-keys
25
+
26
+
27
+ * https://github.com/Idein/msgpack-schema
28
+ * https://github.com/serde-rs/serde/issues/959
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function h(e){return t=>t?(c(t,e),t):{indexesPathReversed:[e],fieldType:void 0}}function i(e){return Object.hasOwn(e,"fieldType")}function c(e,t){if(!i(e))for(const[o,s]of Object.entries(e)){const n=s;i(n)?n.indexesPathReversed.push(t):c(n,t)}}function f(e,t){const o=t.indexesPathReversed;let s=e;for(let r=t.indexesPathReversed.length-1;r>=1;r--)s=s[o[r]];const n=o[0];return s[n]}function a(e,t,o){const s=t.indexesPathReversed;let n=e;for(let d=t.indexesPathReversed.length-1;d>=1;d--)n[s[d]]===void 0&&(n[s[d]]=[]),n=n[s[d]];const r=s[0];n[r]=o}function l(e,t){const o={};for(const[s,n]of Object.entries(t)){const r=n;let d;i(r)?d=f(e,r):d=l(e,r),o[s]=d}return o}function x(e,t){const o=[];return u(o,e,t),o}function u(e,t,o){for(const[s,n]of Object.entries(o)){const r=n,d=t[s];i(r)?a(e,r,d):u(e,d,r)}}exports.get=f;exports.set=a;exports.toIndexedKeysMessage=x;exports.toPlainObject=l;exports.withIndex=h;
@@ -0,0 +1,28 @@
1
+ import { NonNegativeInteger } from 'type-fest';
2
+
3
+ export declare function get<const TField>(message: readonly unknown[], schemaField: SchemaLeaf<TField>): TField;
4
+
5
+ declare type IndexedKeysMessageSchema<TSchema> = {
6
+ [K in keyof TSchema]: TSchema[K] extends SchemaLeaf<infer TField> ? SchemaLeaf<TField> : IndexedKeysMessageSchema<TSchema[K]>;
7
+ };
8
+
9
+ declare type PlainObjectOfSchema<TSchema> = TSchema extends IndexedKeysMessageSchema<unknown> ? {
10
+ [K in keyof TSchema]: TSchema[K] extends SchemaLeaf<infer TField> ? TField : PlainObjectOfSchema<TSchema[K]>;
11
+ } : never;
12
+
13
+ declare type ReturnedSchemaNode<TField, TNestedSchema> = TNestedSchema extends undefined ? SchemaLeaf<TField> : TNestedSchema;
14
+
15
+ declare type SchemaLeaf<TField> = {
16
+ indexesPathReversed: number[];
17
+ fieldType: TField;
18
+ };
19
+
20
+ export declare function set<const TField>(targetMessage: unknown[], schemaField: SchemaLeaf<TField>, value: TField): void;
21
+
22
+ export declare function toIndexedKeysMessage<TSchema extends IndexedKeysMessageSchema<TSchemaInner>, TSchemaInner>(plainObject: PlainObjectOfSchema<TSchema>, schema: TSchema): unknown[];
23
+
24
+ export declare function toPlainObject<TSchema extends IndexedKeysMessageSchema<TSchemaInner>, TSchemaInner>(message: readonly unknown[], schema: TSchema): PlainObjectOfSchema<TSchema>;
25
+
26
+ export declare function withIndex<const TIndex extends number>(index: NonNegativeInteger<TIndex>): <const TField = undefined, TNestedSchema extends IndexedKeysMessageSchema<TNestedSchema> | undefined = undefined>(nestedSchema?: TNestedSchema) => ReturnedSchemaNode<TField, TNestedSchema>;
27
+
28
+ export { }
@@ -0,0 +1 @@
1
+ var Schemind=function(i){"use strict";function v(e){return t=>t?(f(t,e),t):{indexesPathReversed:[e],fieldType:void 0}}function c(e){return Object.hasOwn(e,"fieldType")}function f(e,t){if(!c(e))for(const[d,s]of Object.entries(e)){const n=s;c(n)?n.indexesPathReversed.push(t):f(n,t)}}function a(e,t){const d=t.indexesPathReversed;let s=e;for(let o=t.indexesPathReversed.length-1;o>=1;o--)s=s[d[o]];const n=d[0];return s[n]}function u(e,t,d){const s=t.indexesPathReversed;let n=e;for(let r=t.indexesPathReversed.length-1;r>=1;r--)n[s[r]]===void 0&&(n[s[r]]=[]),n=n[s[r]];const o=s[0];n[o]=d}function l(e,t){const d={};for(const[s,n]of Object.entries(t)){const o=n;let r;c(o)?r=a(e,o):r=l(e,o),d[s]=r}return d}function I(e,t){const d=[];return h(d,e,t),d}function h(e,t,d){for(const[s,n]of Object.entries(d)){const o=n,r=t[s];c(o)?u(e,o,r):h(e,r,o)}}return i.get=a,i.set=u,i.toIndexedKeysMessage=I,i.toPlainObject=l,i.withIndex=v,Object.defineProperty(i,Symbol.toStringTag,{value:"Module"}),i}({});
@@ -0,0 +1,58 @@
1
+ function h(e) {
2
+ return (t) => t ? (c(t, e), t) : {
3
+ indexesPathReversed: [e],
4
+ fieldType: void 0
5
+ };
6
+ }
7
+ function i(e) {
8
+ return Object.hasOwn(e, "fieldType");
9
+ }
10
+ function c(e, t) {
11
+ if (!i(e))
12
+ for (const [o, s] of Object.entries(e)) {
13
+ const n = s;
14
+ i(n) ? n.indexesPathReversed.push(t) : c(n, t);
15
+ }
16
+ }
17
+ function a(e, t) {
18
+ const o = t.indexesPathReversed;
19
+ let s = e;
20
+ for (let r = t.indexesPathReversed.length - 1; r >= 1; r--)
21
+ s = s[o[r]];
22
+ const n = o[0];
23
+ return s[n];
24
+ }
25
+ function l(e, t, o) {
26
+ const s = t.indexesPathReversed;
27
+ let n = e;
28
+ for (let d = t.indexesPathReversed.length - 1; d >= 1; d--)
29
+ n[s[d]] === void 0 && (n[s[d]] = []), n = n[s[d]];
30
+ const r = s[0];
31
+ n[r] = o;
32
+ }
33
+ function u(e, t) {
34
+ const o = {};
35
+ for (const [s, n] of Object.entries(t)) {
36
+ const r = n;
37
+ let d;
38
+ i(r) ? d = a(e, r) : d = u(e, r), o[s] = d;
39
+ }
40
+ return o;
41
+ }
42
+ function x(e, t) {
43
+ const o = [];
44
+ return f(o, e, t), o;
45
+ }
46
+ function f(e, t, o) {
47
+ for (const [s, n] of Object.entries(o)) {
48
+ const r = n, d = t[s];
49
+ i(r) ? l(e, r, d) : f(e, d, r);
50
+ }
51
+ }
52
+ export {
53
+ a as get,
54
+ l as set,
55
+ x as toIndexedKeysMessage,
56
+ u as toPlainObject,
57
+ h as withIndex
58
+ };
@@ -0,0 +1 @@
1
+ (function(f,r){typeof exports=="object"&&typeof module<"u"?r(exports):typeof define=="function"&&define.amd?define(["exports"],r):(f=typeof globalThis<"u"?globalThis:f||self,r(f.Schemind={}))})(this,function(f){"use strict";function r(e){return t=>t?(u(t,e),t):{indexesPathReversed:[e],fieldType:void 0}}function c(e){return Object.hasOwn(e,"fieldType")}function u(e,t){if(!c(e))for(const[o,s]of Object.entries(e)){const n=s;c(n)?n.indexesPathReversed.push(t):u(n,t)}}function a(e,t){const o=t.indexesPathReversed;let s=e;for(let d=t.indexesPathReversed.length-1;d>=1;d--)s=s[o[d]];const n=o[0];return s[n]}function l(e,t,o){const s=t.indexesPathReversed;let n=e;for(let i=t.indexesPathReversed.length-1;i>=1;i--)n[s[i]]===void 0&&(n[s[i]]=[]),n=n[s[i]];const d=s[0];n[d]=o}function h(e,t){const o={};for(const[s,n]of Object.entries(t)){const d=n;let i;c(d)?i=a(e,d):i=h(e,d),o[s]=i}return o}function x(e,t){const o=[];return v(o,e,t),o}function v(e,t,o){for(const[s,n]of Object.entries(o)){const d=n,i=t[s];c(d)?l(e,d,i):v(e,i,d)}}f.get=a,f.set=l,f.toIndexedKeysMessage=x,f.toPlainObject=h,f.withIndex=r,Object.defineProperty(f,Symbol.toStringTag,{value:"Module"})});
package/package.json ADDED
@@ -0,0 +1,59 @@
1
+ {
2
+ "name": "schemind",
3
+ "version": "0.0.2",
4
+ "description": "Read and write to messages serialized as arrays (indexed keys) by defining a schema; \nenabling smaller message size when using protocols such as msgpack or JSON.",
5
+ "keywords": [
6
+ "serialization",
7
+ "schema",
8
+ "index",
9
+ "indexed keys",
10
+ "array",
11
+ "msgpack",
12
+ "pack",
13
+ "packed"
14
+ ],
15
+ "license": "MIT",
16
+ "author": "kpietraszko",
17
+ "homepage": "https://github.com/kpietraszko/schemind",
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "git:kpietraszko/schemind"
21
+ },
22
+ "type": "module",
23
+ "exports": {
24
+ ".": {
25
+ "import": "./dist/schemind.js",
26
+ "require": "./dist/schemind.cjs"
27
+ }
28
+ },
29
+ "main": "./dist/schemind.cjs",
30
+ "module": "./dist/schemind.js",
31
+ "types": "./dist/schemind.d.ts",
32
+ "files": [
33
+ "dist"
34
+ ],
35
+ "dependencies": {
36
+ "type-fest": "^4.30.0"
37
+ },
38
+ "devDependencies": {
39
+ "@commitlint/cli": "^19.6.0",
40
+ "@commitlint/config-conventional": "^19.6.0",
41
+ "@types/node": "^22.10.1",
42
+ "camelcase": "^8.0.0",
43
+ "changelogen": "^0.5.7",
44
+ "husky": "^9.1.7",
45
+ "typescript": "~5.7.2",
46
+ "vite": "^6.0.3",
47
+ "vite-plugin-dts": "^4.3.0",
48
+ "vitest": "2.1.8",
49
+ "@vitest/coverage-v8": "2.1.8"
50
+ },
51
+ "scripts": {
52
+ "dev": "vite",
53
+ "build": "tsc && vite build",
54
+ "release": "pnpm test && pnpm build && changelogen --release --push && pnpm publish",
55
+ "test": "vitest --run --typecheck",
56
+ "test:watch": "vitest",
57
+ "test:coverage": "vitest --run --typecheck --coverage"
58
+ }
59
+ }