@c9up/chronos 0.1.3

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 C9up
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
+ # @c9up/chronos
2
+
3
+ > Advanced date/time and recurrence engine for the Ream ecosystem (TypeScript + Rust N-API).
4
+
5
+ Part of **[Ream](https://github.com/C9up/ream)** — a Rust-powered, AdonisJS-compatible Node.js framework. Independent, publishable package.
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ pnpm add @c9up/chronos
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ```ts
16
+ import { at } from '@c9up/chronos'
17
+
18
+ const d = at('2026-06-05') // parse / construct a Chronos instant
19
+ ```
20
+
21
+ ## Entry points
22
+
23
+ - `@c9up/chronos` — main API
24
+ - `@c9up/chronos/atlas` — Atlas integration adapter
25
+
26
+ ## License
27
+
28
+ MIT
Binary file
Binary file
Binary file
Binary file
Binary file
package/package.json ADDED
@@ -0,0 +1,57 @@
1
+ {
2
+ "name": "@c9up/chronos",
3
+ "version": "0.1.3",
4
+ "description": "Chronos — advanced date/time and recurrence engine (TypeScript + Rust N-API)",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "main": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js"
13
+ },
14
+ "./atlas": {
15
+ "types": "./dist/atlas.d.ts",
16
+ "import": "./dist/atlas.js"
17
+ }
18
+ },
19
+ "files": [
20
+ "LICENSE",
21
+ "README.md",
22
+ "dist",
23
+ "index.*.node",
24
+ "index.d.ts",
25
+ "index.js",
26
+ "scripts",
27
+ "src",
28
+ "wasm"
29
+ ],
30
+ "devDependencies": {
31
+ "@types/node": "^22.19.15",
32
+ "typescript": "^6.0.2",
33
+ "vitest": "^4.1.2"
34
+ },
35
+ "engines": {
36
+ "node": ">=22.0.0"
37
+ },
38
+ "publishConfig": {
39
+ "access": "public"
40
+ },
41
+ "repository": {
42
+ "type": "git",
43
+ "url": "git+https://github.com/C9up/chronos.git"
44
+ },
45
+ "scripts": {
46
+ "build": "tsc -p tsconfig.build.json",
47
+ "build:rust": "cargo build --release",
48
+ "build:napi": "cargo build --release && node scripts/copy-napi.mjs",
49
+ "test": "vitest run",
50
+ "test:rust": "cargo test",
51
+ "test:napi": "node scripts/verify-napi.mjs",
52
+ "build:wasm": "wasm-pack build --target web crates/chronos-engine-wasm --out-dir ../../wasm",
53
+ "lint": "biome check src/",
54
+ "test:coverage": "vitest run --coverage",
55
+ "typecheck": "tsc --noEmit"
56
+ }
57
+ }
@@ -0,0 +1,48 @@
1
+ import { copyFileSync, existsSync } from 'node:fs'
2
+ import { dirname, join } from 'node:path'
3
+ import { arch, env, platform } from 'node:process'
4
+ import { fileURLToPath } from 'node:url'
5
+
6
+ const here = dirname(fileURLToPath(import.meta.url))
7
+ const root = join(here, '..')
8
+ const CRATE = 'chronos_engine_napi'
9
+ const TAG = '[chronos:napi]'
10
+
11
+ const tripleMap = {
12
+ 'x86_64-unknown-linux-gnu': { suffix: 'linux-x64-gnu', os: 'linux' },
13
+ 'aarch64-unknown-linux-gnu': { suffix: 'linux-arm64-gnu', os: 'linux' },
14
+ 'x86_64-apple-darwin': { suffix: 'darwin-x64', os: 'darwin' },
15
+ 'aarch64-apple-darwin': { suffix: 'darwin-arm64', os: 'darwin' },
16
+ 'x86_64-pc-windows-msvc': { suffix: 'win32-x64-msvc', os: 'win32' },
17
+ }
18
+ const hostSuffixMap = {
19
+ 'linux-x64': 'linux-x64-gnu', 'linux-arm64': 'linux-arm64-gnu',
20
+ 'darwin-x64': 'darwin-x64', 'darwin-arm64': 'darwin-arm64', 'win32-x64': 'win32-x64-msvc',
21
+ }
22
+
23
+ const triple = env.CARGO_BUILD_TARGET ?? ''
24
+ let suffix, os, releaseDir
25
+ if (triple) {
26
+ const entry = tripleMap[triple]
27
+ if (!entry) throw new Error(`${TAG} unsupported CARGO_BUILD_TARGET: ${triple}`)
28
+ suffix = entry.suffix; os = entry.os
29
+ releaseDir = join(root, 'target', triple, 'release')
30
+ } else {
31
+ suffix = hostSuffixMap[`${platform}-${arch}`]; os = platform
32
+ releaseDir = join(root, 'target', 'release')
33
+ if (!suffix) throw new Error(`${TAG} unsupported platform/arch: ${platform}-${arch}`)
34
+ }
35
+
36
+ const candidates =
37
+ os === 'win32'
38
+ ? [join(releaseDir, `${CRATE}.dll`), join(releaseDir, `lib${CRATE}.dll`)]
39
+ : os === 'darwin'
40
+ ? [join(releaseDir, `lib${CRATE}.dylib`)]
41
+ : [join(releaseDir, `lib${CRATE}.so`)]
42
+
43
+ const source = candidates.find((candidate) => existsSync(candidate))
44
+ if (!source) throw new Error(`${TAG} native library not found. Looked for:\n${candidates.map((p) => `- ${p}`).join('\n')}`)
45
+
46
+ const target = join(root, `index.${suffix}.node`)
47
+ copyFileSync(source, target)
48
+ console.log(`${TAG} copied ${source} -> ${target}`)
@@ -0,0 +1,46 @@
1
+ import { existsSync } from 'node:fs'
2
+ import { createRequire } from 'node:module'
3
+ import { dirname, join } from 'node:path'
4
+ import { arch, platform } from 'node:process'
5
+ import { fileURLToPath } from 'node:url'
6
+
7
+ const here = dirname(fileURLToPath(import.meta.url))
8
+ const root = join(here, '..')
9
+
10
+ const suffixMap = {
11
+ 'linux-x64': 'linux-x64-gnu',
12
+ 'linux-arm64': 'linux-arm64-gnu',
13
+ 'darwin-x64': 'darwin-x64',
14
+ 'darwin-arm64': 'darwin-arm64',
15
+ 'win32-x64': 'win32-x64-msvc',
16
+ }
17
+
18
+ const suffix = suffixMap[`${platform}-${arch}`]
19
+ if (!suffix) {
20
+ throw new Error(`[chronos:napi] unsupported platform/arch: ${platform}-${arch}`)
21
+ }
22
+
23
+ const binary = join(root, `index.${suffix}.node`)
24
+ if (!existsSync(binary)) {
25
+ throw new Error(`[chronos:napi] binary missing: ${binary}`)
26
+ }
27
+
28
+ const require2 = createRequire(import.meta.url)
29
+ const binding = require2(binary)
30
+
31
+ for (const fn of ['add', 'diff', 'startOf', 'endOf', 'format', 'rruleExpand']) {
32
+ if (typeof binding[fn] !== 'function') {
33
+ throw new Error(`[chronos:napi] invalid exports: missing ${fn}()`)
34
+ }
35
+ }
36
+
37
+ if (binding.add('2026-01-15T10:00:00Z', 1, 'month') !== '2026-02-15T10:00:00Z') {
38
+ throw new Error('[chronos:napi] add smoke test failed')
39
+ }
40
+
41
+ const recurring = binding.rruleExpand('2026-01-15T15:00:00Z', 'FREQ=MONTHLY;BYMONTHDAY=15;COUNT=3', 10)
42
+ if (!Array.isArray(recurring) || recurring.length !== 3) {
43
+ throw new Error('[chronos:napi] rrule smoke test failed')
44
+ }
45
+
46
+ console.log('[chronos:napi] smoke test passed')