@samoa-house-lib/shl-types 1.0.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/package.json ADDED
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "@samoa-house-lib/shl-types",
3
+ "version": "1.0.0",
4
+ "description": "Types and constants shared between the SHL project's repo's",
5
+ "main": "src/index.ts",
6
+ "scripts": {
7
+ "build": "tsc",
8
+ "test": "npm run test"
9
+ },
10
+ "author": "Ford Jones",
11
+ "license": "MIT",
12
+ "devDependencies": {
13
+ "@tsconfig/node18": "18.2.4",
14
+ "@tsconfig/node20": "20.1.4",
15
+ "@types/node": "20.12.7",
16
+ "@types/pg": "^8.11.6",
17
+ "typescript": "~5.4.5",
18
+ "ts-node": "^10.9.2"
19
+ },
20
+ "dependencies": {
21
+ "pg": "^8.11.5",
22
+ "zod": "3.23.8"
23
+ }
24
+ }
@@ -0,0 +1,102 @@
1
+ export enum SectionVariant {
2
+ MOANA = 'Moana',
3
+ MAORI = 'Toi Maori',
4
+ AOTEAROA = 'Aotearoa Art',
5
+ INTERNATIONAL = 'International Art',
6
+ THEORY = 'Theory',
7
+ HISTORY = 'Art History',
8
+ LITERATURE = 'Literature',
9
+ REFERENCE = 'Reference',
10
+ }
11
+
12
+ export enum ConditionVariant {
13
+ EXQUISITE = 'Mint',
14
+ GOOD = 'Good',
15
+ OK = 'Okay',
16
+ BAD = 'Bad',
17
+ RUIN = 'Poor',
18
+ BINDING = 'Binding Undone',
19
+ TORN = 'Pages Torn',
20
+ SUN = 'Sun Damage',
21
+ WET = 'Moisture Damage',
22
+ COVER_MISS = 'Cover Missing',
23
+ PAGE_MISS = 'Pages Missing',
24
+ NOTES = 'Hand-written Notation',
25
+ }
26
+
27
+ export enum TextVariant {
28
+ DEFAULT = 'Book',
29
+ HARDCOVER = 'Hardcover',
30
+ PAPERBACK = 'Paperback',
31
+ CHAPBOOK = 'Chapbook',
32
+ JOURNAL = 'Journal',
33
+ MAGAZINE = 'Magazine',
34
+ ZINE = 'Zine',
35
+ RECORD = 'Record',
36
+ CATALOGUE = 'Catalogue',
37
+ REPORT = 'Report',
38
+ LARGE = 'Large',
39
+ SMALL = 'Small',
40
+ ARCHIVE = 'Archive Box',
41
+ EPHEMERA = 'Ephemera',
42
+ AUC_CATA = 'Auction Catalogue',
43
+ EX_CATA = 'Exhibition Catalogue',
44
+ EX_TEXT = 'Exhibition Text',
45
+ EX_PROG = 'Exhibition Programme',
46
+ GAL_PUB = 'Gallery Publication',
47
+ ARTIST_BOOK = 'Artist Book',
48
+ ARTIST_PUB = 'Artist Publication',
49
+ ARTWORK = 'Artwork',
50
+ NEWSPAPER = 'Newspaper',
51
+ NEWSLETTER = 'Newsletter',
52
+ POSTCARD = 'Postcard',
53
+ CARD = 'Card',
54
+ POSTER = 'Poster',
55
+ OHP = 'Overhead Projector Laminate',
56
+ TAPE = 'Cassette Tape',
57
+ DVD = 'DVD',
58
+ VHS = 'VHS',
59
+ CD = 'CD',
60
+ ESSAY = 'Essay',
61
+ RINGBOUND = 'Ringbound',
62
+ ENVELOPE = 'Envelope',
63
+ CALENDAR = 'Calendar',
64
+ MEMOIR = 'Memoir',
65
+ SPECIAL = 'Special',
66
+ NOTEBOOK = 'Notebook',
67
+ MULTI_VOL = 'Multiple Volumes',
68
+ PAPER = 'Paper',
69
+ CRAFT = 'Hand Crafted',
70
+ THESIS = 'Thesis',
71
+ MONOGRAPH = 'Monograph',
72
+ BOOKLET = 'Booklet',
73
+ SLIP = 'Slipcase',
74
+ CONF_TEXT = 'Conference Text',
75
+ }
76
+
77
+ export enum ColumnNames {
78
+ ID = 'id',
79
+ RUNNING_NUMBER = 'running_number',
80
+ DONOR_FIRST_NAME = 'donor_first_name',
81
+ DONOR_LAST_NAME = 'donor_last_name',
82
+ SHL_ID = 'shl_id',
83
+ TERMS = 'terms',
84
+ TITLE = 'title',
85
+ AUTHOR_FIRST_NAME = 'author_first_name',
86
+ AUTHOR_LAST_NAME = 'author_last_name',
87
+ ISBN_ISSN = 'isbn_issn',
88
+ RECIEPEIENT = 'recipient',
89
+ DATE_PROCESSED = 'date_processed',
90
+ SECTION = 'section',
91
+ BOOK_TYPE = 'book_type',
92
+ PUBLISHER = 'publisher',
93
+ DATE_PUBLISHED = 'date_published',
94
+ NOTES = 'notes',
95
+ SPECIAL_CONDITION = 'special_conditions',
96
+ CONDITION = 'condition',
97
+ }
98
+
99
+ export enum Responses {
100
+ SUCCESS = 'Request Success',
101
+ FAILURE = 'Request Failure'
102
+ }
package/src/index.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from './constants'
2
+ export * from './types'
package/src/types.ts ADDED
@@ -0,0 +1,89 @@
1
+ import * as z from 'zod'
2
+ import { SectionVariant, TextVariant, ConditionVariant, ColumnNames } from "./constants"
3
+ import { QueryResult } from 'pg'
4
+
5
+ const unionFromEnum = (enumerable: object): z.ZodUnion<NonEmptyStringArray> => {
6
+ return z.union(
7
+ Object.values(enumerable)
8
+ .map(
9
+ (val) => z.literal(val as z.Primitive)
10
+ ) as NonEmptyStringArray
11
+ )
12
+ }
13
+
14
+
15
+ export interface ServiceResponse {
16
+ readBatch: () => Promise<QueryResult | void>,
17
+ readBy: (column_name: ColumnName, column_value: string) => Promise<QueryResult | void>,
18
+ readLatest: () => Promise<QueryResult | void>,
19
+ writeItem: (data: CreateBookRequest) => Promise<QueryResult | void>,
20
+ updateItem: (colName: ColumnName, colValue: string, id: ShlID) => Promise<QueryResult | void>,
21
+ createTable : () => Promise<QueryResult | void>
22
+ }
23
+
24
+ export type Book = z.infer<typeof dbEntrySchema>
25
+ export type BookBatch = z.infer<typeof bookBatchSchema>
26
+
27
+ export type BookWithID = z.infer<typeof newDbEntrySchema>
28
+
29
+ export type CreateBookRequest = z.infer<typeof addBookRequest>
30
+
31
+ export type ColumnName = z.infer<typeof dbColumnNameSchema>
32
+
33
+ export type ShlID = z.infer<typeof shlIdSchema>
34
+ export type Name = z.infer<typeof nameSchema>
35
+ export type Terms = z.infer<typeof termsSchema>
36
+ export type Section = z.infer<typeof sectionSchema>
37
+ export type TextType = z.infer<typeof textTypeSchema>
38
+ export type Condition = z.infer<typeof conditionSchema>
39
+
40
+ type NonEmptyStringArray = [z.ZodLiteral<string>, z.ZodLiteral<string>, ...z.ZodLiteral<string>[]]
41
+
42
+ export const shlIdSchema = z.string().min(3).brand("SamoaHouseLibraryID")
43
+
44
+ export const nameSchema = z.string().transform((val) => {
45
+ const initial = val.charAt(0).toUpperCase()
46
+ return initial.concat(val.slice(1, val.length))
47
+ })
48
+
49
+ export const termsSchema = z.union([z.literal("D"), z.literal("R")]).optional()
50
+
51
+ export const dbColumnNameSchema = unionFromEnum(ColumnNames)
52
+ export const sectionSchema = unionFromEnum(SectionVariant)
53
+ export const textTypeSchema = unionFromEnum(TextVariant)
54
+ export const conditionSchema = unionFromEnum(ConditionVariant)
55
+
56
+ export const addBookRequest = z.object({
57
+ donor_first_name: nameSchema.optional(),
58
+ donor_last_name: nameSchema.optional().nullable(),
59
+ terms: termsSchema.optional(),
60
+ title: z.string().max(150),
61
+ author_first_name: nameSchema.optional(),
62
+ author_last_name: nameSchema.optional().nullable(),
63
+ isbn_issn: z.string().max(13).optional().nullable(),
64
+ recipient: z.string().max(2),
65
+ date_processed: z.string().max(27),
66
+ section: sectionSchema.optional().nullable(),
67
+ book_type: textTypeSchema.optional(),
68
+ publisher: z.string().optional().nullable(),
69
+ date_published: z.string().max(27).optional().nullable(),
70
+ notes: z.string().max(100).optional().nullable(),
71
+ special_conditions: z.string().optional().nullable(),
72
+ condition: conditionSchema.optional()
73
+ })
74
+
75
+ export const newDbEntrySchema = addBookRequest.extend({
76
+ shl_id: shlIdSchema
77
+ })
78
+
79
+ export const dbEntrySchema = newDbEntrySchema.extend({
80
+ id: z.number(),
81
+ running_number: z.number()
82
+ })
83
+
84
+ export const bookBatchSchema = z.array(dbEntrySchema)
85
+
86
+ export const responseSchema = z.object({
87
+ message: z.string(),
88
+ data: bookBatchSchema.nullable()
89
+ })
package/tsconfig.json ADDED
@@ -0,0 +1,10 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "es2016",
4
+ "module": "commonjs",
5
+ "esModuleInterop": true,
6
+ "forceConsistentCasingInFileNames": true,
7
+ "strict": true,
8
+ "skipLibCheck": true
9
+ }
10
+ }