npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

androidjs-file-repovych

v1.1.0

Published

File repo implements repovych interface for androidjs frontend

Downloads

237

Readme

Androidjs-file-repovych

Realization of repovych repository interface for androidjs file storage on frontend.

Usage

  1. Copy file ./backend/main.js to your androidjs backend script
  2. on frontend make repo and use it by instruction

Example of usage

  1. Copy file ./backend/main.js to your androidjs backend script
  2. On frontend:
import { make, property, valid } from "class-model";
import { AndroidjsFileRepovych, backendLogOutput, makeFilePath } from ".";
import { IRepovich } from "repovych";
import { ConsoleLoggych, HtmlElemLoggych } from "loggych";

//class of data to store with class-model validation
class MyClass
{
    @property(null,
        valid.number(),
        make.int()
    )
    id: number;

    @property(null,
        valid.string(),
        make.string()
    )
    val: string;
}

//description of query
interface MyQuery {
    ids: number[];
}

async function run() {
    try {
        //see html at ./test-repo-app/views/index.html
        const input = document.getElementById("my-input") as HTMLInputElement;
        const submitBtn = document.getElementById("my-btn") as HTMLButtonElement;
        const outConsole = document.getElementById("my-console");
        const errConsole = document.getElementById("my-err");

        // making logger
        const log = HtmlElemLoggych.createDefault(errConsole);
        backendLogOutput(eval("front"), log.addContext("backend"));
        
        //making repo
        const repo: IRepovich<MyClass, Partial<MyQuery>, {id: number}> = new AndroidjsFileRepovych(
            makeFilePath("my-file.json"), //always use makeFilePath function
            eval("front"),
            () => new MyClass(),
            (data, q: MyQuery) => {
                //data filtering
                if(q.ids) {
                    data = data.filter(v => q.ids.includes(v.id));
                }
                return data;
            },
            ["id"], //id fields
            log.addContext("frontend") //logger
        );
        
        submitBtn.onclick = () => {
            const val = input.value;
            repo.save([{id: Math.ceil(Math.random() * 999999), val: val}])
                .catch(e => {log.log({err: e});})
                .then(() =>  repo.query({}))
                .catch(e => {
                    log.log({err: e});
                    return e;
                })
                .then(data => {
                    outConsole.innerHTML = JSON.stringify(data);
                })
                .catch(e => {
                    log.log({err: e});
                });
        }
        return Promise.resolve();
    } catch(e) {
        return Promise.reject(e);
    }
}

run();

//build this file with browserify and connect to androidjs project
//see result mobile app on ./test-repo-app/dist/test-repo-app.apk

Api

//after requiring "androidjs" to your page
//use eval("front") to access it
export interface Front {
    on: (msg: string, f: (...data: any[]) => void) => void;
    send: (msg: string, ...data: any[]) => void;
}

//hepler function to making full android filepath to internal storage file
export declare function makeFilePath(filename: string): string;
export type QueryAllReq = {
    id: string;
    type: "get-all";
    filepath: string;
    req: any;
};

//You should run app after initialization all repositories
export declare function run(front: Front): void;

//Androifjs file repo for frontend
export declare class AndroidjsFileRepovych<T extends Id, Q extends {}, Id extends {}> implements IRepovich<T, Q, Id> {
    constructor(
        filepath: string, //use makeFilePath function to make correct filepath
        front: Front, //use eval("front") to access front
        newModel: () => T, //making instance of class-model class
        filterFn: (data: T[], q: Q) => T[], //data-filtering function
        idFields: (keyof Id)[],  //id fields
        log: ILoggych
    );
    
    //Special androidjs-file-repovych commands and queries
    queryAll(q?: any): Promise<T[]>;
    saveAll(data: T[]): Promise<T[]>;
    
    //Standart repovych commands and queries
    query(q: Q): Promise<T[]>;
    save(d: T[]): Promise<void>;
    delete(ids: Id[]): Promise<void>;
    queryDelete(q: Q): Promise<void>;
}

export declare class AndroidjsFileRepovych2<T extends Id, Q extends {}, Id extends {}> implements IRepovich2<T, Q, Id> {
    constructor(
        filepath: string, //use makeFilePath function to make correct filepath
        front: Front, //use eval("front") to access front
        newModel: () => T, //making instance of class-model class
        filterFn: (data: T[], q: Q) => T[], //data-filtering function
        idFields: (keyof Id)[],  //id fields
        log: ILoggych
    );
    
    //Special androidjs-file-repovych commands and queries
    queryAll(q?: any): Promise<T[]>;
    saveAll(data: T[]): Promise<T[]>;
    
    //Standart repovych commands and queries
    query(q: Q): Promise<T[]>;
    save(d: T[]): Promise<void>;
    delete(ids: Id[]): Promise<void>;
    queryDelete(q: Q): Promise<void>;
    queryIds(q: Q): Promise<Id[]>;
    reset(d: T[]): Promise<void>;
    count(q: Q): Promise<number>;
}

//connect any loggych to this command to log backend events
export declare function backendLogOutput(front: Front, log: ILoggych): void;

Possible problems

  1. On typescript use eval("front") for access to front global variable.
  2. Check, that androidjs.js file have been linked before your script using this repovisch.
  3. On bundling and es5 compiling possible names conflinct with "front variable". For resolve this replace all front variable names on _front, expect "front" (in quotes).
  4. Dont forget start running with run(front) command after repos initiated.

Author

Anatoly Starodubtsev [email protected]

License

MIT