@vazen-ai/toml 0.0.0-development.0 → 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/LICENSING.md CHANGED
@@ -20,4 +20,7 @@ version of the format, or your own product, as Vazen TOML, and do not suggest
20
20
  that Vazen endorses you.
21
21
 
22
22
  ProSpace, Blue Yonder, .psa and other third-party names are trademarks of their
23
- respective owners. Vazen is not affiliated with or endorsed by Blue Yonder.
23
+ respective owners. Vazen is not affiliated with or endorsed by Blue Yonder. PSA
24
+ support was built from PSA files that customers supplied or that were published
25
+ online; column and value names follow ProSpace's field definitions. No Blue
26
+ Yonder software was used.
package/README.md CHANGED
@@ -1,17 +1,127 @@
1
1
  # @vazen-ai/toml
2
2
 
3
- Vazen TOML planogram tooling. This development release writes PSA files.
3
+ `@vazen-ai/toml` 0.1.0 reads and writes [Vazen TOML](https://toml.vazen.com/)
4
+ 0.3.0 files, `vazen/spec` and `vazen/layout`, as TOML or as JSON. It reads
5
+ ProSpace PSA files of any version, and writes the versions `PsaVersion` lists,
6
+ 2017.1.0 to 2024.4.0. Each file reads as the tables of a 0.3.0 file. A writer
7
+ writes 0.3.0, or PSA 2024.4.0, unless another version is asked for.
8
+ [Reading and writing](#reading-and-writing) says what each function reads and
9
+ writes, and what reading does not check.
4
10
 
5
11
  ```js
6
- import { psaStringify } from '@vazen-ai/toml';
12
+ import {
13
+ decodeVazenProjectFromTomlFile,
14
+ encodeJsonFileFromVazenProject,
15
+ } from '@vazen-ai/toml';
7
16
 
8
- console.log(psaStringify([['Fictional item A', 'Shelf, left']]));
9
- // Fictional item A,Shelf\, left
17
+ const { project, source } =
18
+ decodeVazenProjectFromTomlFile(`schema = "vazen/spec"
19
+ schema_version = "0.3.0"
20
+
21
+ [[products]]
22
+ name = "Vazen Planflakes breakfast cereal 400 g"
23
+ gtin = "884400062451"
24
+ brand = "Vazen"
25
+
26
+ [[fixtures]]
27
+
28
+ [[fixtures.equipment]]
29
+ type = "shelf"
30
+
31
+ [[fixtures.equipment.sites]]
32
+ product = { gtin = "884400062451" }
33
+ facings = { wide = 3, deep = 4 }
34
+ `);
35
+ console.log(project.fixtures[0].equipment[0].sites[0].facings.wide);
36
+ // 3
37
+ console.log(source);
38
+ // { declaredVersion: '0.3.0', format: 'vazen-toml' }
39
+ console.log(encodeJsonFileFromVazenProject({ project }).includes('"wide": 3'));
40
+ // true
41
+ ```
42
+
43
+ ## What a project holds
44
+
45
+ A project is the tables of a 0.3.0 file, `VazenTomlProjectV0_3_0`: `products`
46
+ and `fixtures`, each fixture's `equipment`, and each piece of equipment's
47
+ `sites`. When the file gives no value for a key, the key is absent. Keys the
48
+ specification does not define sit beside the standard keys, as in the file. A
49
+ reader returns the file's format and declared version as `source`, beside the
50
+ project. The source is not part of the project, because a writer writes the
51
+ project alone. Reading checks the shape of the file. It does not check the
52
+ specification's rules of a whole file, nor its spatial rules.
53
+
54
+ ## JSON
55
+
56
+ The tables also read and write as JSON, in a `.vazen.json` file. The JSON has
57
+ the same keys and the same values. JSON has no date, so the JSON writer writes a
58
+ date as text, such as `"2026-09-27T09:30:00.000Z"`, `"2026-09-27"` or
59
+ `"09:30:00.000"`. The JSON reader reads text in exactly that form as a date, but
60
+ only in an attribute or a product selector. JSON cannot hold `nan` or `inf`, so
61
+ the JSON writer refuses them. The JSON reader refuses an integer beyond
62
+ JavaScript's safe range, as the TOML reader does.
63
+
64
+ ## PSA files
65
+
66
+ A PSA file reads as the tables of a 0.3.0 layout. Each planogram is a fixture,
67
+ each fixture row is its equipment, and each position is a site. Every length is
68
+ in millimetres. A value with a standard key takes that key. Every other value
69
+ the file gives becomes a `_psa__` key on its object, unless the column's default
70
+ already implies it. So the project writes back as the same PSA records, also
71
+ after a trip through TOML or JSON.
72
+
73
+ ```js
74
+ import { readFileSync, writeFileSync } from 'node:fs';
75
+ import {
76
+ decodeVazenProjectFromPsaFile,
77
+ encodeTomlFileFromVazenProject,
78
+ } from '@vazen-ai/toml';
79
+
80
+ const { project } = decodeVazenProjectFromPsaFile(
81
+ readFileSync('end-of-aisle.psa'),
82
+ );
83
+ writeFileSync(
84
+ 'end-of-aisle.vazen.toml',
85
+ encodeTomlFileFromVazenProject({ project }),
86
+ );
10
87
  ```
11
88
 
12
- ESM only, for Node.js 24 or later, with Effect as a peer dependency.
89
+ ## Reading and writing
90
+
91
+ Each format has a pair of file functions. `decodeVazenProjectFromTomlFile` and
92
+ `encodeTomlFileFromVazenProject` read and write TOML text.
93
+ `decodeVazenProjectFromJsonFile` and `encodeJsonFileFromVazenProject` read and
94
+ write JSON text. `decodeVazenProjectFromPsaFile` and
95
+ `encodePsaFileFromVazenProject` read and write PSA bytes. The TOML and JSON
96
+ readers take the versions `VazenVersion` lists. The PSA reader takes a file of
97
+ any version. A project read from a PSA file drops what the records reader lists
98
+ in `compromises`, such as a cell its column could not read.
99
+ `decodePsaDataFromPsaFile` shows them. The TOML and JSON writers write 0.3.0.
100
+ The PSA writer writes 2024.4.0. The `version` option names another version that
101
+ `VazenVersion` or `PsaVersion` lists:
102
+ `encodePsaFileFromVazenProject({ project, version: '2017.2.0' })`. A writer
103
+ refuses a project that a reader would refuse as a file. The PSA writer also
104
+ refuses a value that a column of the named version cannot hold. Each function
105
+ throws a `ParseError` saying what it could not read or write.
106
+
107
+ The Effect schemas behind the file functions are exported for a caller who wants
108
+ an `Either` or an `Effect`: `VazenProjectFromTomlText`,
109
+ `VazenProjectFromJsonText`, `VazenProjectFromPsaBytes`,
110
+ `VazenProjectFromPsaText` and `VazenProjectFromPsaData`. Each schema reads a
111
+ file into `VazenProject`. In a `VazenProject`, an optional value is an Effect
112
+ `Option`, the keys the specification does not define live in each object's
113
+ `attributes`, and `source` is part of the project. So the PSA schemas write the
114
+ version of the PSA file the project came from, when that version can hold the
115
+ project.
13
116
 
14
- From this directory, run `npm ci`, then `npm run verify` to check, test, build
15
- and lint the package.
117
+ The functions above read a file as a project. To edit the columns of a PSA file,
118
+ read its records instead. `decodePsaDataFromPsaFile` returns `PsaData`, the rows
119
+ of the file as records. `encodePsaFileFromPsaData` writes the records back to a
120
+ file.
121
+ [The PSA README](https://github.com/vazen-ai/toml/blob/main/typescript/src/psa/README.md)
122
+ says which values the reader loses and which values the writer keeps.
16
123
 
17
- See [licensing](https://github.com/vazen-ai/toml/blob/main/LICENSING.md).
124
+ The package is ESM only, for Node.js 24 or later. It needs Effect 3.14.8 or a
125
+ later 3.x release as a peer dependency. To work on the package, run `npm ci`
126
+ then `npm run verify` here. Licensing is in
127
+ [LICENSING.md](https://github.com/vazen-ai/toml/blob/main/LICENSING.md).