Skip to content

jolo18/rpay-ai-coding

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Document Service

A simple document service implementation in TypeScript, built as a coding interview exercise with Gyanendra Singh.

Overview

The service manages documents with:

  • Permission-based access control — documents are private by default; only owners can grant/revoke read or edit access to other users
  • Owner-only deletion — only the document creator can delete it
  • Dual storage — HOT (in-memory) and COLD (file system)
  • Storage migration — documents can be moved between HOT and COLD storage

Entities

Entity Description
DocumentMeta Document metadata: id, body, storageType, path, ownerId
DocumentStoreObject Physical storage record: docId, storageType, data/path
DocumentStore Storage layer handling read/write to memory or file system
DocumentService Main service with permission maps and CRUD + grant/revoke + move

API

const service = new DocumentService();

// Create
service.createDocument(body, id, ownerId, storageType, path?);

// Read / Edit / Delete
service.readDocument(docId, userId);
service.editDocument(docId, userId, newBody);
service.deleteDocument(docId, userId);       // owner only

// Permissions (owner only)
service.grantAccess(docId, ownerId, targetUserId, permission);
service.revokeAccess(docId, ownerId, targetUserId, permission);

// Move between storage types
service.moveDocument(docId, userId, newStorageType, newPath?);

Running Tests

npm install
npm test

Project Structure

src/
  types.ts                 # Enums (StorageType, Permission) and interfaces
  DocumentStore.ts         # Physical storage layer (HOT = Map, COLD = fs)
  DocumentStore.test.ts    # Store-level tests
  DocumentService.ts       # Main service with permissions + CRUD
  DocumentService.test.ts  # Service-level tests

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors