@gtfs-jp/types 4.0.0-beta.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 +21 -0
- package/README.md +109 -0
- package/dist/helpers.d.ts +10 -0
- package/dist/helpers.d.ts.map +1 -0
- package/dist/helpers.js +30 -0
- package/dist/helpers.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/schema.d.ts +1253 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +514 -0
- package/dist/schema.js.map +1 -0
- package/dist/types.d.ts +43 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +42 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Kai-Z-JP
|
|
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,109 @@
|
|
|
1
|
+
# @gtfs-jp/types
|
|
2
|
+
|
|
3
|
+
GTFS-JP v4 全33テーブルのスキーマ定義と、スキーマから導出される TypeScript 型を提供します。
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @gtfs-jp/types
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
### テーブル名の一覧と判定
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import {
|
|
17
|
+
GTFS_JP_V4_TABLE_NAMES,
|
|
18
|
+
isGtfsJpV4TableName,
|
|
19
|
+
} from "@gtfs-jp/types";
|
|
20
|
+
|
|
21
|
+
console.log(GTFS_JP_V4_TABLE_NAMES);
|
|
22
|
+
// ["feed_info", "agency", "stops", "routes", "trips", ...]
|
|
23
|
+
|
|
24
|
+
isGtfsJpV4TableName("routes"); // true
|
|
25
|
+
isGtfsJpV4TableName("unknown"); // false
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### スキーマの取得
|
|
29
|
+
|
|
30
|
+
```ts
|
|
31
|
+
import { getGtfsJpV4TableSchema } from "@gtfs-jp/types";
|
|
32
|
+
|
|
33
|
+
const schema = getGtfsJpV4TableSchema("routes");
|
|
34
|
+
// schema.fileName → "routes.txt"
|
|
35
|
+
// schema.requirement → "required"
|
|
36
|
+
// schema.columns → { route_id: { kind: "string", required: true }, ... }
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### 型付き行データ
|
|
40
|
+
|
|
41
|
+
```ts
|
|
42
|
+
import type { GtfsJpV4TableRow } from "@gtfs-jp/types";
|
|
43
|
+
|
|
44
|
+
// routes テーブルの行型が自動導出される
|
|
45
|
+
type RouteRow = GtfsJpV4TableRow<"routes">;
|
|
46
|
+
// { route_id: string; agency_id: string | undefined; route_type: number; ... }
|
|
47
|
+
|
|
48
|
+
const row: RouteRow = {
|
|
49
|
+
route_id: "R1",
|
|
50
|
+
agency_id: "A1",
|
|
51
|
+
route_type: 3,
|
|
52
|
+
};
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### ファイル名とテーブル名の相互変換
|
|
56
|
+
|
|
57
|
+
```ts
|
|
58
|
+
import {
|
|
59
|
+
resolveGtfsJpV4TableNameFromFileName,
|
|
60
|
+
resolveGtfsJpV4FileNameFromTableName,
|
|
61
|
+
isGtfsJpV4FileName,
|
|
62
|
+
} from "@gtfs-jp/types";
|
|
63
|
+
|
|
64
|
+
resolveGtfsJpV4TableNameFromFileName("routes.txt"); // "routes"
|
|
65
|
+
resolveGtfsJpV4FileNameFromTableName("routes"); // "routes.txt"
|
|
66
|
+
isGtfsJpV4FileName("routes.txt"); // true
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## API
|
|
70
|
+
|
|
71
|
+
### 定数
|
|
72
|
+
|
|
73
|
+
| 名前 | 説明 |
|
|
74
|
+
|--------------------------|----------------------|
|
|
75
|
+
| `GTFS_JP_V4_SCHEMA` | 全33テーブルのスキーマ定義配列 |
|
|
76
|
+
| `GTFS_JP_V4_TABLE_NAMES` | テーブル名の `readonly` 配列 |
|
|
77
|
+
| `GTFS_JP_V4_FILE_NAMES` | ファイル名の `readonly` 配列 |
|
|
78
|
+
|
|
79
|
+
### 関数
|
|
80
|
+
|
|
81
|
+
| 名前 | 説明 |
|
|
82
|
+
|---------------------------------------------------|------------------------|
|
|
83
|
+
| `getGtfsJpV4TableSchema(tableName)` | テーブル名からスキーマを取得 |
|
|
84
|
+
| `getGtfsJpV4TableSchemaByFileName(fileName)` | ファイル名からスキーマを取得 |
|
|
85
|
+
| `isGtfsJpV4TableName(value)` | GTFS-JP v4 テーブル名かどうか判定 |
|
|
86
|
+
| `isGtfsJpV4FileName(value)` | GTFS-JP v4 ファイル名かどうか判定 |
|
|
87
|
+
| `resolveGtfsJpV4TableNameFromFileName(fileName)` | ファイル名 → テーブル名 |
|
|
88
|
+
| `resolveGtfsJpV4FileNameFromTableName(tableName)` | テーブル名 → ファイル名 |
|
|
89
|
+
|
|
90
|
+
### 型
|
|
91
|
+
|
|
92
|
+
| 名前 | 説明 |
|
|
93
|
+
|---------------------------|-----------------|
|
|
94
|
+
| `GtfsJpV4TableName` | 全テーブル名のユニオン型 |
|
|
95
|
+
| `GtfsJpV4FileName` | 全ファイル名のユニオン型 |
|
|
96
|
+
| `GtfsJpV4TableRow<TName>` | テーブル名から導出される行の型 |
|
|
97
|
+
| `GtfsJpV4TableSchema` | テーブルスキーマの型 |
|
|
98
|
+
| `GtfsJpV4ColumnSchema` | カラムスキーマの型 |
|
|
99
|
+
|
|
100
|
+
### スカラー型
|
|
101
|
+
|
|
102
|
+
CSV の値に意味的な型を付与するブランド型です。実体はすべて `string` または `number` です。
|
|
103
|
+
|
|
104
|
+
`GtfsId` `GtfsText` `GtfsDate` `GtfsTime` `GtfsUrl` `GtfsEmail` `GtfsColor` `GtfsPhoneNumber` `GtfsTimezone`
|
|
105
|
+
`GtfsLanguageCode` `GtfsCurrencyCode` `BinaryFlag`
|
|
106
|
+
|
|
107
|
+
## License
|
|
108
|
+
|
|
109
|
+
[MIT](../../LICENSE)
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { GtfsJpV4FileName, GtfsJpV4SchemaEntry, GtfsJpV4SchemaEntryByName, GtfsJpV4TableName } from "./types.js";
|
|
2
|
+
export declare const GTFS_JP_V4_TABLE_NAMES: readonly GtfsJpV4TableName[];
|
|
3
|
+
export declare const GTFS_JP_V4_FILE_NAMES: readonly GtfsJpV4FileName[];
|
|
4
|
+
export declare const isGtfsJpV4TableName: (value: string) => value is GtfsJpV4TableName;
|
|
5
|
+
export declare const isGtfsJpV4FileName: (value: string) => value is GtfsJpV4FileName;
|
|
6
|
+
export declare const getGtfsJpV4TableSchema: <TName extends GtfsJpV4TableName>(tableName: TName) => GtfsJpV4SchemaEntryByName<TName>;
|
|
7
|
+
export declare const getGtfsJpV4TableSchemaByFileName: (fileName: GtfsJpV4FileName) => GtfsJpV4SchemaEntry;
|
|
8
|
+
export declare const resolveGtfsJpV4TableNameFromFileName: (fileName: string) => GtfsJpV4TableName | undefined;
|
|
9
|
+
export declare const resolveGtfsJpV4FileNameFromTableName: (tableName: GtfsJpV4TableName) => GtfsJpV4FileName;
|
|
10
|
+
//# sourceMappingURL=helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,gBAAgB,EAChB,mBAAmB,EACnB,yBAAyB,EACzB,iBAAiB,EAClB,MAAM,YAAY,CAAC;AAEpB,eAAO,MAAM,sBAAsB,EAE9B,SAAS,iBAAiB,EAAE,CAAC;AAElC,eAAO,MAAM,qBAAqB,EAE7B,SAAS,gBAAgB,EAAE,CAAC;AAUjC,eAAO,MAAM,mBAAmB,GAAI,OAAO,MAAM,KAAG,KAAK,IAAI,iBACV,CAAC;AAEpD,eAAO,MAAM,kBAAkB,GAAI,OAAO,MAAM,KAAG,KAAK,IAAI,gBACX,CAAC;AAElD,eAAO,MAAM,sBAAsB,GAAI,KAAK,SAAS,iBAAiB,EACpE,WAAW,KAAK,KACf,yBAAyB,CAAC,KAAK,CAOjC,CAAC;AAEF,eAAO,MAAM,gCAAgC,GAC3C,UAAU,gBAAgB,KACzB,mBAOF,CAAC;AAEF,eAAO,MAAM,oCAAoC,GAC/C,UAAU,MAAM,KACf,iBAAiB,GAAG,SAItB,CAAC;AAEF,eAAO,MAAM,oCAAoC,GAC/C,WAAW,iBAAiB,KAC3B,gBAEF,CAAC"}
|
package/dist/helpers.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { GTFS_JP_V4_SCHEMA } from "./schema.js";
|
|
2
|
+
export const GTFS_JP_V4_TABLE_NAMES = GTFS_JP_V4_SCHEMA.map((schema) => schema.tableName);
|
|
3
|
+
export const GTFS_JP_V4_FILE_NAMES = GTFS_JP_V4_SCHEMA.map((schema) => schema.fileName);
|
|
4
|
+
const schemaByTableName = new Map(GTFS_JP_V4_SCHEMA.map((schema) => [schema.tableName, schema]));
|
|
5
|
+
const schemaByFileName = new Map(GTFS_JP_V4_SCHEMA.map((schema) => [schema.fileName, schema]));
|
|
6
|
+
export const isGtfsJpV4TableName = (value) => schemaByTableName.has(value);
|
|
7
|
+
export const isGtfsJpV4FileName = (value) => schemaByFileName.has(value);
|
|
8
|
+
export const getGtfsJpV4TableSchema = (tableName) => {
|
|
9
|
+
const schema = schemaByTableName.get(tableName);
|
|
10
|
+
if (!schema) {
|
|
11
|
+
throw new Error(`Unknown GTFS-JP v4 table: ${tableName}`);
|
|
12
|
+
}
|
|
13
|
+
return schema;
|
|
14
|
+
};
|
|
15
|
+
export const getGtfsJpV4TableSchemaByFileName = (fileName) => {
|
|
16
|
+
const schema = schemaByFileName.get(fileName);
|
|
17
|
+
if (!schema) {
|
|
18
|
+
throw new Error(`Unknown GTFS-JP v4 file: ${fileName}`);
|
|
19
|
+
}
|
|
20
|
+
return schema;
|
|
21
|
+
};
|
|
22
|
+
export const resolveGtfsJpV4TableNameFromFileName = (fileName) => {
|
|
23
|
+
const normalized = fileName.toLowerCase();
|
|
24
|
+
const schema = schemaByFileName.get(normalized);
|
|
25
|
+
return schema?.tableName;
|
|
26
|
+
};
|
|
27
|
+
export const resolveGtfsJpV4FileNameFromTableName = (tableName) => {
|
|
28
|
+
return getGtfsJpV4TableSchema(tableName).fileName;
|
|
29
|
+
};
|
|
30
|
+
//# sourceMappingURL=helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.js","sourceRoot":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AA0B,EACL,EAAE;IACvB,MAAM,MAAM,GAAG,gBAAgB,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAC9C,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,IAAI,KAAK,CAAC,4BAA4B,QAAQ,EAAE,CAAC,CAAC;IAC1D,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,oCAAoC,GAAG,CAClD,QAAgB,EACe,EAAE;IACjC,MAAM,UAAU,GAAG,QAAQ,CAAC,WAAW,EAAsB,CAAC;IAC9D,MAAM,MAAM,GAAG,gBAAgB,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IAChD,OAAO,MAAM,EAAE,SAAS,CAAC;AAC3B,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,oCAAoC,GAAG,CAClD,SAA4B,EACV,EAAE;IACpB,OAAO,sBAAsB,CAAC,SAAS,CAAC,CAAC,QAAQ,CAAC;AACpD,CAAC,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { GTFS_JP_V4_SCHEMA, type GtfsJpV4ColumnRequirement, type GtfsJpV4ColumnSchema, type GtfsJpV4Requirement, type GtfsJpV4TableSchema, } from "./schema.js";
|
|
2
|
+
export { GTFS_JP_V4_FILE_NAMES, GTFS_JP_V4_TABLE_NAMES, getGtfsJpV4TableSchema, getGtfsJpV4TableSchemaByFileName, isGtfsJpV4FileName, isGtfsJpV4TableName, resolveGtfsJpV4FileNameFromTableName, resolveGtfsJpV4TableNameFromFileName, } from "./helpers.js";
|
|
3
|
+
export type { BinaryFlag, GtfsColor, GtfsCurrencyCode, GtfsDate, GtfsEmail, GtfsId, GtfsLanguageCode, GtfsPhoneNumber, GtfsRow, GtfsScalar, GtfsText, GtfsTime, GtfsTimezone, GtfsUrl, GtfsJpV4ColumnsByTableName, GtfsJpV4FileName, GtfsJpV4Format, GtfsJpV4SchemaEntry, GtfsJpV4SchemaEntryByName, GtfsJpV4TableName, GtfsJpV4TableRequirement, GtfsJpV4TableRow, GtfsJpV4TypedRows, RowFromColumns, } from "./types.js";
|
|
4
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,KAAK,yBAAyB,EAC9B,KAAK,oBAAoB,EACzB,KAAK,mBAAmB,EACxB,KAAK,mBAAmB,GACzB,MAAM,aAAa,CAAC;AAErB,OAAO,EACL,qBAAqB,EACrB,sBAAsB,EACtB,sBAAsB,EACtB,gCAAgC,EAChC,kBAAkB,EAClB,mBAAmB,EACnB,oCAAoC,EACpC,oCAAoC,GACrC,MAAM,cAAc,CAAC;AAEtB,YAAY,EACV,UAAU,EACV,SAAS,EACT,gBAAgB,EAChB,QAAQ,EACR,SAAS,EACT,MAAM,EACN,gBAAgB,EAChB,eAAe,EACf,OAAO,EACP,UAAU,EACV,QAAQ,EACR,QAAQ,EACR,YAAY,EACZ,OAAO,EACP,0BAA0B,EAC1B,gBAAgB,EAChB,cAAc,EACd,mBAAmB,EACnB,yBAAyB,EACzB,iBAAiB,EACjB,wBAAwB,EACxB,gBAAgB,EAChB,iBAAiB,EACjB,cAAc,GACf,MAAM,YAAY,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { GTFS_JP_V4_SCHEMA, } from "./schema.js";
|
|
2
|
+
export { GTFS_JP_V4_FILE_NAMES, GTFS_JP_V4_TABLE_NAMES, getGtfsJpV4TableSchema, getGtfsJpV4TableSchemaByFileName, isGtfsJpV4FileName, isGtfsJpV4TableName, resolveGtfsJpV4FileNameFromTableName, resolveGtfsJpV4TableNameFromFileName, } from "./helpers.js";
|
|
3
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,GAKlB,MAAM,aAAa,CAAC;AAErB,OAAO,EACL,qBAAqB,EACrB,sBAAsB,EACtB,sBAAsB,EACtB,gCAAgC,EAChC,kBAAkB,EAClB,mBAAmB,EACnB,oCAAoC,EACpC,oCAAoC,GACrC,MAAM,cAAc,CAAC"}
|